- java.lang.Object
-
- com.google.common.collect.ForwardingObject
-
- life.expert.value.numeric.amount.ForwardingQuantity
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedForwardingQuantity()Constructor for use by subclasses.
-
Method Summary
Modifier and Type Method Description Quantityabs()Returns aQuantitywhose value is the absolute value of thisQuantity, and whose scale isthis.scale().Quantityadd(Quantity amount)Returns aQuantitywhose value isintcompareTo(@NotNull Quantity o)protected abstract Quantitydelegate()Quantitydivide(double divisor)Returns aQuantitywhose value isQuantitydivide(long divisor)Returns aQuantitywhose value isQuantitydivide(java.lang.Number divisor)Returns aQuantitywhose value isQuantity[]divideAndRemainder(double divisor)Returns a two-elementQuantityarray containing the result ofdivideToIntegralValuefollowed by the result ofremainderon the two operands.Quantity[]divideAndRemainder(long divisor)Returns a two-elementQuantityarray containing the result ofdivideToIntegralValuefollowed by the result ofremainderon the two operands.Quantity[]divideAndRemainder(java.lang.Number divisor)Returns a two-elementQuantityarray containing the result ofdivideToIntegralValuefollowed by the result ofremainderon the two operands.QuantitydivideToIntegralValue(double divisor)Returns aQuantitywhose value is the integer part of the quotientQuantitydivideToIntegralValue(long divisor)Returns aQuantitywhose value is the integer part of the quotientQuantitydivideToIntegralValue(java.lang.Number divisor)Returns aQuantitywhose value is the integer part of the quotientContextgetContext()Returns theContextof thisQuantity.NumberValuegetNumber()Gets the correspondingNumberValue.UnitgetUnit()Gets the correspondingUnit.booleanisEqualTo(Quantity amount)Compares two instances ofQuantity, hereby ignoring non significant trailing zeroes and different numeric capabilities.booleanisGreaterThan(Quantity amount)Compares two instances ofQuantity, hereby ignoring non significant trailing zeroes and different numeric capabilities.booleanisGreaterThanOrEqualTo(Quantity amount)Compares two instances ofQuantity, hereby ignoring non significant trailing zeroes and different numeric capabilities.booleanisLessThan(Quantity amount)Compares two instances ofQuantity, hereby ignoring non significant trailing zeroes and different numeric capabilities.booleanisLessThanOrEqualTo(Quantity amt)Compares two instances ofQuantity, hereby ignoring non significant trailing zeroes and different numeric capabilities.Quantitymultiply(double multiplicand)Returns aQuantitywhose value is (this × multiplicand), and whose scale isQuantitymultiply(long multiplicand)Returns aQuantitywhose value is (this × multiplicand), and whose scale isQuantitymultiply(java.lang.Number multiplicand)Returns aQuantitywhose value is (this × multiplicand) , and whose scale isQuantitynegate()Returns aQuantitywhose value isQuantityplus()Returns aQuantitywhose value isQuantityremainder(double divisor)Returns aQuantitywhose value isQuantityremainder(long divisor)Returns aQuantitywhose value isQuantityremainder(java.lang.Number divisor)Returns aQuantitywhose value isQuantityscaleByPowerOfTen(int power)Returns aQuantitywhose numerical value is equal to (this* 10n).intsignum()Returns the signum function of thisQuantity.QuantitystripTrailingZeros()Returns aQuantitywhich is numerically equal to this one but with any trailing zeros removed from the representation.Quantitysubtract(Quantity amount)Returns aQuantitywhose value is-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface life.expert.value.numeric.amount.Quantity
isNegative, isNegativeOrZero, isPositive, isPositiveOrZero, isZero, with
-
-
-
-
Method Detail
-
delegate
protected abstract Quantity delegate()
- Specified by:
delegatein classcom.google.common.collect.ForwardingObject
-
getContext
public Context getContext()
Description copied from interface:QuantityReturns theContextof thisQuantity. TheContextprovides additional information about the numeric representation and the numeric capabilities. This information can be used by code to determine situations whereQunatityinstances must be converted to avoid implicit truncation, which can lead to invalid results.- Specified by:
getContextin interfaceQuantity- Returns:
- the
Contextof thisQuantity, nevernull.
-
isGreaterThan
public boolean isGreaterThan(Quantity amount)
Description copied from interface:QuantityCompares two instances ofQuantity, hereby ignoring non significant trailing zeroes and different numeric capabilities.- Specified by:
isGreaterThanin interfaceQuantity- Parameters:
amount- theQuantityto be compared with this instance.- Returns:
trueifamount > this.
-
isGreaterThanOrEqualTo
public boolean isGreaterThanOrEqualTo(Quantity amount)
Description copied from interface:QuantityCompares two instances ofQuantity, hereby ignoring non significant trailing zeroes and different numeric capabilities.- Specified by:
isGreaterThanOrEqualToin interfaceQuantity- Parameters:
amount- theQuantityto be compared with this instance.- Returns:
trueifamount >= this.
-
isLessThan
public boolean isLessThan(Quantity amount)
Description copied from interface:QuantityCompares two instances ofQuantity, hereby ignoring non significant trailing zeroes and different numeric capabilities.- Specified by:
isLessThanin interfaceQuantity- Parameters:
amount- theQuantityto be compared with this instance.- Returns:
trueifamount < this.
-
isLessThanOrEqualTo
public boolean isLessThanOrEqualTo(Quantity amt)
Description copied from interface:QuantityCompares two instances ofQuantity, hereby ignoring non significant trailing zeroes and different numeric capabilities.- Specified by:
isLessThanOrEqualToin interfaceQuantity- Parameters:
amt- the amount- Returns:
trueifamount <= this.
-
isEqualTo
public boolean isEqualTo(Quantity amount)
Description copied from interface:QuantityCompares two instances ofQuantity, hereby ignoring non significant trailing zeroes and different numeric capabilities.
-
signum
public int signum()
Description copied from interface:QuantityReturns the signum function of thisQuantity.
-
add
public Quantity add(Quantity amount)
Description copied from interface:QuantityReturns aQuantitywhose value is
, and whose scale isthis + amount
.max(this.scale(), amount.scale()
-
subtract
public Quantity subtract(Quantity amount)
Description copied from interface:QuantityReturns aQuantitywhose value is
, and whose scale isthis - amount
.max(this.scale(), subtrahend.scale()
-
multiply
public Quantity multiply(long multiplicand)
Description copied from interface:QuantityReturns aQuantitywhose value is (this × multiplicand), and whose scale is
.this.scale() + multiplicand.scale()
-
multiply
public Quantity multiply(double multiplicand)
Description copied from interface:QuantityReturns aQuantitywhose value is (this × multiplicand), and whose scale is
. By default the input value's scale will be rounded to accommodate the format capabilities, and nothis.scale() + multiplicand.scale()ArithmeticExceptionis thrown if the input number's scale exceeds the capabilities.
-
multiply
public Quantity multiply(java.lang.Number multiplicand)
Description copied from interface:QuantityReturns aQuantitywhose value is (this × multiplicand) , and whose scale is
.this.scale() + multiplicand.scale()
-
divide
public Quantity divide(long divisor)
Description copied from interface:QuantityReturns aQuantitywhose value is
, and whose preferred scale isthis / divisor
; if the exact quotient cannot be represented anthis.scale() - divisor.scale()ArithmeticExceptionis thrown.
-
divide
public Quantity divide(double divisor)
Description copied from interface:QuantityReturns aQuantitywhose value is
, and whose preferred scale isthis / divisor
; if the exact quotient cannot be represented anthis.scale() - divisor.scale()ArithmeticExceptionis thrown.
-
divide
public Quantity divide(java.lang.Number divisor)
Description copied from interface:QuantityReturns aQuantitywhose value is
, and whose preferred scale isthis / divisor
; if the exact quotient cannot be represented anthis.scale() - divisor.scale()ArithmeticExceptionis thrown.
-
remainder
public Quantity remainder(long divisor)
Description copied from interface:QuantityReturns aQuantitywhose value is
. The remainder is given bythis % divisor
. Note that this is not the modulo operation (the result can be negative).this.subtract(this.divideToIntegralValue(divisor).multiply(divisor)
-
remainder
public Quantity remainder(double divisor)
Description copied from interface:QuantityReturns aQuantitywhose value is
. The remainder is given bythis % divisor
. Note that this is not the modulo operation (the result can be negative).this.subtract(this.divideToIntegralValue(divisor).multiply(divisor)
-
remainder
public Quantity remainder(java.lang.Number divisor)
Description copied from interface:QuantityReturns aQuantitywhose value is
. The remainder is given bythis % divisor
. Note that this is not the modulo operation (the result can be negative).this.subtract(this.divideToIntegralValue(divisor).multiply(divisor)
-
divideAndRemainder
public Quantity[] divideAndRemainder(long divisor)
Description copied from interface:QuantityReturns a two-elementQuantityarray containing the result ofdivideToIntegralValuefollowed by the result ofremainderon the two operands. Note that if both the integer quotient and remainder are needed, this method is faster than using thedivideToIntegralValueandremaindermethods separately because the division need only be carried out once.- Specified by:
divideAndRemainderin interfaceQuantity- Parameters:
divisor- value by which thisQuantityis to be divided, and the remainder computed.- Returns:
- a two element
Quantityarray: the quotient (the result ofdivideToIntegralValue) is the initial element and the remainder is the final element. - See Also:
#divideToIntegralValue(long)#divideToIntegralValue(long)#divideToIntegralValue(long)#divideToIntegralValue(long)#divideToIntegralValue(long),#remainder(long)#remainder(long)#remainder(long)#remainder(long)#remainder(long)
-
divideAndRemainder
public Quantity[] divideAndRemainder(double divisor)
Description copied from interface:QuantityReturns a two-elementQuantityarray containing the result ofdivideToIntegralValuefollowed by the result ofremainderon the two operands. Note that if both the integer quotient and remainder are needed, this method is faster than using thedivideToIntegralValueandremaindermethods separately because the division need only be carried out once.- Specified by:
divideAndRemainderin interfaceQuantity- Parameters:
divisor- value by which thisQuantityis to be divided, and the remainder computed.- Returns:
- a two element
Quantityarray: the quotient (the result ofdivideToIntegralValue) is the initial element and the remainder is the final element. - See Also:
#divideToIntegralValue(double)#divideToIntegralValue(double)#divideToIntegralValue(double)#divideToIntegralValue(double)#divideToIntegralValue(double),#remainder(double)#remainder(double)#remainder(double)#remainder(double)#remainder(double)
-
divideAndRemainder
public Quantity[] divideAndRemainder(java.lang.Number divisor)
Description copied from interface:QuantityReturns a two-elementQuantityarray containing the result ofdivideToIntegralValuefollowed by the result ofremainderon the two operands. Note that if both the integer quotient and remainder are needed, this method is faster than using thedivideToIntegralValueandremaindermethods separately because the division need only be carried out once.- Specified by:
divideAndRemainderin interfaceQuantity- Parameters:
divisor- value by which thisQuantityis to be divided, and the remainder computed.- Returns:
- a two element
Quantityarray: the quotient (the result ofdivideToIntegralValue) is the initial element and the remainder is the final element. - See Also:
#divideToIntegralValue(Number)#divideToIntegralValue(Number)#divideToIntegralValue(Number)#divideToIntegralValue(Number)#divideToIntegralValue(Number),#remainder(Number)#remainder(Number)#remainder(Number)#remainder(Number)#remainder(Number)
-
divideToIntegralValue
public Quantity divideToIntegralValue(long divisor)
Description copied from interface:QuantityReturns aQuantitywhose value is the integer part of the quotient
rounded down. The preferred scale of the result isthis / divisor
.this.scale() - divisor.scale()- Specified by:
divideToIntegralValuein interfaceQuantity- Parameters:
divisor- value by which thisBigDecimalis to be divided.- Returns:
- The integer part of
this / divisor. - See Also:
java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal)java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal)java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal)java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal)java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal)
-
divideToIntegralValue
public Quantity divideToIntegralValue(double divisor)
Description copied from interface:QuantityReturns aQuantitywhose value is the integer part of the quotient
rounded down. The preferred scale of the result isthis / divisor
.this.scale() - divisor.scale()- Specified by:
divideToIntegralValuein interfaceQuantity- Parameters:
divisor- value by which thisBigDecimalis to be divided.- Returns:
- The integer part of
this / divisor. - See Also:
java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal)java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal)java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal)java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal)java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal)
-
divideToIntegralValue
public Quantity divideToIntegralValue(java.lang.Number divisor)
Description copied from interface:QuantityReturns aQuantitywhose value is the integer part of the quotient
rounded down. The preferred scale of the result isthis / divisor
.this.scale() - divisor.scale()- Specified by:
divideToIntegralValuein interfaceQuantity- Parameters:
divisor- value by which thisBigDecimalis to be divided.- Returns:
- The integer part of
this / divisor. - See Also:
java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal)java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal)java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal)java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal)java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal)
-
scaleByPowerOfTen
public Quantity scaleByPowerOfTen(int power)
Description copied from interface:QuantityReturns aQuantitywhose numerical value is equal to (this* 10n). The scale of the result is
.this.scale() - n- Specified by:
scaleByPowerOfTenin interfaceQuantity- Parameters:
power- the power.- Returns:
- the calculated amount value.
-
abs
public Quantity abs()
Description copied from interface:QuantityReturns aQuantitywhose value is the absolute value of thisQuantity, and whose scale isthis.scale().
-
negate
public Quantity negate()
Description copied from interface:QuantityReturns aQuantitywhose value is
, and whose scale is-thisthis.scale().
-
plus
public Quantity plus()
Description copied from interface:QuantityReturns aQuantitywhose value is
, with rounding according to the context settings.+this
-
stripTrailingZeros
public Quantity stripTrailingZeros()
Description copied from interface:QuantityReturns aQuantitywhich is numerically equal to this one but with any trailing zeros removed from the representation. For example, stripping the trailing zeros from theQuantityvalueUNIT 600.0, which has [BigInteger,scale] components equals to [6000, 1], yields6E2with [BigInteger,scale] components equals to [6, -2]- Specified by:
stripTrailingZerosin interfaceQuantity- Returns:
- a numerically equal
Quantitywith any trailing zeros removed.
-
compareTo
public int compareTo(@NotNull @NotNull Quantity o)- Specified by:
compareToin interfacejava.lang.Comparable<Quantity>
-
getUnit
public Unit getUnit()
Description copied from interface:QuantityGets the correspondingUnit.
-
getNumber
public NumberValue getNumber()
Description copied from interface:QuantityGets the correspondingNumberValue.- Specified by:
getNumberin interfaceQuantity- Returns:
- the corresponding
NumberValue, not null.
-
-