Package io.fabric8.kubernetes.api.model
Class Quantity
- java.lang.Object
-
- io.fabric8.kubernetes.api.model.Quantity
-
- All Implemented Interfaces:
Serializable
,Comparable<Quantity>
public class Quantity extends Object implements Serializable, Comparable<Quantity>
Quantity is fixed point representation of a number. It provides convenient marshalling/unmarshalling in JSON or YAML, in addition to String or getAmountInBytes accessors.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Quantity.Deserializer
static class
Quantity.Serializer
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Quantity
add(Quantity y)
Add the provided quantity to the current value.int
compareTo(Quantity o)
Compares the numerical amounts of these quantities.boolean
equals(Object o)
static Quantity
fromNumericalAmount(BigDecimal amountInBytes, String desiredFormat)
Constructs a new Quantity from the provided amountInBytes.Map<String,Object>
getAdditionalProperties()
String
getAmount()
static BigDecimal
getAmountInBytes(Quantity quantity)
If the quantity is a memory Quantity, the result will represent bytes.
If the quantity is a cpu Quantity, the result will represent cores.String
getFormat()
BigDecimal
getNumericalAmount()
If this is a memory Quantity, the result will represent bytes.
If this is a cpu Quantity, the result will represent cores.int
hashCode()
Quantity
multiply(int multiplicand)
Multiplies the quantity by the specified scalar multiplicand.static Quantity
parse(String quantityAsString)
void
setAdditionalProperty(String name, Object value)
void
setAmount(String amount)
void
setFormat(String format)
Quantity
subtract(Quantity y)
Subtract the provided quantity from the current value.String
toString()
-
-
-
Constructor Detail
-
Quantity
public Quantity()
No args constructor for use in serialization
-
Quantity
public Quantity(String amount)
Single argument constructor for setting amount.- Parameters:
amount
- amount of quantity specified.
-
-
Method Detail
-
getAmount
public String getAmount()
-
setAmount
public void setAmount(String amount)
-
getFormat
public String getFormat()
-
setFormat
public void setFormat(String format)
-
getNumericalAmount
public BigDecimal getNumericalAmount() throws ArithmeticException
If this is a memory Quantity, the result will represent bytes.
If this is a cpu Quantity, the result will represent cores.- Returns:
- the formatted amount as a number
- Throws:
ArithmeticException
-
getAmountInBytes
public static BigDecimal getAmountInBytes(Quantity quantity) throws ArithmeticException
If the quantity is a memory Quantity, the result will represent bytes.
If the quantity is a cpu Quantity, the result will represent cores.- Parameters:
quantity
-- Returns:
- a BigDecimal of the bytes
- Throws:
ArithmeticException
- See Also:
getNumericalAmount()
-
fromNumericalAmount
public static Quantity fromNumericalAmount(BigDecimal amountInBytes, String desiredFormat)
Constructs a new Quantity from the provided amountInBytes. This amount is converted to a value with the unit provided in desiredFormat.- Parameters:
amountInBytes
-desiredFormat
-- Returns:
- a new Quantity with the value of amountInBytes with units desiredFormat
- See Also:
getNumericalAmount()
-
compareTo
public int compareTo(Quantity o)
Compares the numerical amounts of these quantities.- Specified by:
compareTo
in interfaceComparable<Quantity>
-
add
public Quantity add(Quantity y)
Add the provided quantity to the current value. If the current value is zero, the format of the quantity will be the format of y.- Parameters:
y
- to add- Returns:
- a new Quantity after y has been added
-
subtract
public Quantity subtract(Quantity y)
Subtract the provided quantity from the current value. If the current value is zero, the format of the quantity will be the format of y.- Parameters:
y
- to subtract- Returns:
- a new Quantity after y has been subtracted
-
multiply
public Quantity multiply(int multiplicand)
Multiplies the quantity by the specified scalar multiplicand.- Parameters:
multiplicand
- the scalar value to multiply by- Returns:
- a new Quantity resulting from the multiplication of this quantity by the scalar multiplicand
-
-