diff --git a/kubernetes-model-generator/kubernetes-model-core/src/main/java/io/fabric8/kubernetes/api/model/Quantity.java b/kubernetes-model-generator/kubernetes-model-core/src/main/java/io/fabric8/kubernetes/api/model/Quantity.java index 843887794a6..206f166b732 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/main/java/io/fabric8/kubernetes/api/model/Quantity.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/main/java/io/fabric8/kubernetes/api/model/Quantity.java @@ -408,6 +408,18 @@ public Quantity subtract(Quantity y) { return op(y, BigDecimal::subtract); } + /** + * Multiplies the quantity by the specified scalar multiplicand. + * + * @param multiplicand the scalar value to multiply by + * @return a new Quantity resulting from the multiplication of this quantity by the scalar multiplicand + */ + public Quantity multiply(int multiplicand) { + BigDecimal numericalAmount = getNumericalAmount(); + numericalAmount = numericalAmount.multiply(BigDecimal.valueOf(multiplicand)); + return fromNumericalAmount(numericalAmount, format); + } + Quantity op(Quantity y, BiFunction func) { BigDecimal numericalAmount = this.getNumericalAmount(); numericalAmount = func.apply(numericalAmount, y.getNumericalAmount()); diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/QuantityTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/QuantityTest.java index 55074138452..680a9a9b874 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/QuantityTest.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/QuantityTest.java @@ -222,4 +222,12 @@ void testSubtract() { Quantity quantity = new Quantity("0Mi"); assertThat(quantity.subtract(new Quantity("1Ki"))).isEqualTo(new Quantity("-1Ki")); } + + @Test + void testMultiply() { + Quantity quantity = new Quantity("4Gi"); + assertThat(quantity.multiply(0)).isEqualTo(new Quantity("0")); + assertThat(quantity.multiply(3)).isEqualTo(new Quantity("12Gi")); + assertThat(quantity.multiply(-3)).isEqualTo(new Quantity("-12Gi")); + } }