Module life.expert

Class ForwardingQuantity

  • All Implemented Interfaces:
    java.lang.Comparable<Quantity>, Quantity

    public abstract class ForwardingQuantity
    extends com.google.common.collect.ForwardingObject
    implements Quantity
    The type Forwarding numeric.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected ForwardingQuantity()
      Constructor for use by subclasses.
    • Method Summary

      Modifier and Type Method Description
      Quantity abs()
      Returns a Quantity whose value is the absolute value of this Quantity, and whose scale is this.scale().
      Quantity add​(Quantity amount)
      Returns a Quantity whose value is
      int compareTo​(@NotNull Quantity o)  
      protected abstract Quantity delegate()  
      Quantity divide​(double divisor)
      Returns a Quantity whose value is
      Quantity divide​(long divisor)
      Returns a Quantity whose value is
      Quantity divide​(java.lang.Number divisor)
      Returns a Quantity whose value is
      Quantity[] divideAndRemainder​(double divisor)
      Returns a two-element Quantity array containing the result of divideToIntegralValue followed by the result of remainder on the two operands.
      Quantity[] divideAndRemainder​(long divisor)
      Returns a two-element Quantity array containing the result of divideToIntegralValue followed by the result of remainder on the two operands.
      Quantity[] divideAndRemainder​(java.lang.Number divisor)
      Returns a two-element Quantity array containing the result of divideToIntegralValue followed by the result of remainder on the two operands.
      Quantity divideToIntegralValue​(double divisor)
      Returns a Quantity whose value is the integer part of the quotient
      Quantity divideToIntegralValue​(long divisor)
      Returns a Quantity whose value is the integer part of the quotient
      Quantity divideToIntegralValue​(java.lang.Number divisor)
      Returns a Quantity whose value is the integer part of the quotient
      Context getContext()
      Returns the Context of this Quantity.
      NumberValue getNumber()
      Gets the corresponding NumberValue.
      Unit getUnit()
      Gets the corresponding Unit.
      boolean isEqualTo​(Quantity amount)
      Compares two instances of Quantity, hereby ignoring non significant trailing zeroes and different numeric capabilities.
      boolean isGreaterThan​(Quantity amount)
      Compares two instances of Quantity, hereby ignoring non significant trailing zeroes and different numeric capabilities.
      boolean isGreaterThanOrEqualTo​(Quantity amount)
      Compares two instances of Quantity, hereby ignoring non significant trailing zeroes and different numeric capabilities.
      boolean isLessThan​(Quantity amount)
      Compares two instances of Quantity, hereby ignoring non significant trailing zeroes and different numeric capabilities.
      boolean isLessThanOrEqualTo​(Quantity amt)
      Compares two instances of Quantity, hereby ignoring non significant trailing zeroes and different numeric capabilities.
      Quantity multiply​(double multiplicand)
      Returns a Quantity whose value is (this × multiplicand), and whose scale is
      Quantity multiply​(long multiplicand)
      Returns a Quantity whose value is (this × multiplicand), and whose scale is
      Quantity multiply​(java.lang.Number multiplicand)
      Returns a Quantity whose value is (this × multiplicand) , and whose scale is
      Quantity negate()
      Returns a Quantity whose value is
      Quantity plus()
      Returns a Quantity whose value is
      Quantity remainder​(double divisor)
      Returns a Quantity whose value is
      Quantity remainder​(long divisor)
      Returns a Quantity whose value is
      Quantity remainder​(java.lang.Number divisor)
      Returns a Quantity whose value is
      Quantity scaleByPowerOfTen​(int power)
      Returns a Quantity whose numerical value is equal to ( this * 10n).
      int signum()
      Returns the signum function of this Quantity.
      Quantity stripTrailingZeros()
      Returns a Quantity which is numerically equal to this one but with any trailing zeros removed from the representation.
      Quantity subtract​(Quantity amount)
      Returns a Quantity whose value is
      • Methods inherited from class com.google.common.collect.ForwardingObject

        toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ForwardingQuantity

        protected ForwardingQuantity()
        Constructor for use by subclasses.
    • Method Detail

      • delegate

        protected abstract Quantity delegate()
        Specified by:
        delegate in class com.google.common.collect.ForwardingObject
      • getContext

        public Context getContext()
        Description copied from interface: Quantity
        Returns the Context of this Quantity. The Context provides additional information about the numeric representation and the numeric capabilities. This information can be used by code to determine situations where Qunatity instances must be converted to avoid implicit truncation, which can lead to invalid results.
        Specified by:
        getContext in interface Quantity
        Returns:
        the Context of this Quantity, never null .
      • isGreaterThan

        public boolean isGreaterThan​(Quantity amount)
        Description copied from interface: Quantity
        Compares two instances of Quantity, hereby ignoring non significant trailing zeroes and different numeric capabilities.
        Specified by:
        isGreaterThan in interface Quantity
        Parameters:
        amount - the Quantity to be compared with this instance.
        Returns:
        true if amount > this.
      • isGreaterThanOrEqualTo

        public boolean isGreaterThanOrEqualTo​(Quantity amount)
        Description copied from interface: Quantity
        Compares two instances of Quantity, hereby ignoring non significant trailing zeroes and different numeric capabilities.
        Specified by:
        isGreaterThanOrEqualTo in interface Quantity
        Parameters:
        amount - the Quantity to be compared with this instance.
        Returns:
        true if amount >= this.
      • isLessThan

        public boolean isLessThan​(Quantity amount)
        Description copied from interface: Quantity
        Compares two instances of Quantity, hereby ignoring non significant trailing zeroes and different numeric capabilities.
        Specified by:
        isLessThan in interface Quantity
        Parameters:
        amount - the Quantity to be compared with this instance.
        Returns:
        true if amount < this.
      • isLessThanOrEqualTo

        public boolean isLessThanOrEqualTo​(Quantity amt)
        Description copied from interface: Quantity
        Compares two instances of Quantity, hereby ignoring non significant trailing zeroes and different numeric capabilities.
        Specified by:
        isLessThanOrEqualTo in interface Quantity
        Parameters:
        amt - the amount
        Returns:
        true if amount <= this.
      • isEqualTo

        public boolean isEqualTo​(Quantity amount)
        Description copied from interface: Quantity
        Compares two instances of Quantity, hereby ignoring non significant trailing zeroes and different numeric capabilities.
        Specified by:
        isEqualTo in interface Quantity
        Parameters:
        amount - the Quantity to be compared with this instance.
        Returns:
        true if amount == this.
      • signum

        public int signum()
        Description copied from interface: Quantity
        Returns the signum function of this Quantity.
        Specified by:
        signum in interface Quantity
        Returns:
        -1, 0, or 1 as the value of this Quantity is negative, zero, or positive.
      • add

        public Quantity add​(Quantity amount)
        Description copied from interface: Quantity
        Returns a Quantity whose value is
        this + amount
        , and whose scale is
        max(this.scale(),
         amount.scale()
        .
        Specified by:
        add in interface Quantity
        Parameters:
        amount - value to be added to this Quantity.
        Returns:
        this + amount
      • subtract

        public Quantity subtract​(Quantity amount)
        Description copied from interface: Quantity
        Returns a Quantity whose value is
        this -
         amount
        , and whose scale is
        max(this.scale(),
         subtrahend.scale()
        .
        Specified by:
        subtract in interface Quantity
        Parameters:
        amount - value to be subtracted from this Quantity.
        Returns:
        this - amount
      • multiply

        public Quantity multiply​(long multiplicand)
        Description copied from interface: Quantity
        Returns a Quantity whose value is (this × multiplicand), and whose scale is
        this.scale() +
         multiplicand.scale()
        .
        Specified by:
        multiply in interface Quantity
        Parameters:
        multiplicand - value to be multiplied by this Quantity.
        Returns:
        this * multiplicand
      • multiply

        public Quantity multiply​(double multiplicand)
        Description copied from interface: Quantity
        Returns a Quantity whose value is (this × multiplicand), and whose scale is
        this.scale() +
         multiplicand.scale()
        . By default the input value's scale will be rounded to accommodate the format capabilities, and no ArithmeticException is thrown if the input number's scale exceeds the capabilities.
        Specified by:
        multiply in interface Quantity
        Parameters:
        multiplicand - value to be multiplied by this Quantity. If the multiplicand's scale exceeds the capabilities of the implementation, it may be rounded implicitly.
        Returns:
        this * multiplicand
      • multiply

        public Quantity multiply​(java.lang.Number multiplicand)
        Description copied from interface: Quantity
        Returns a Quantity whose value is (this × multiplicand) , and whose scale is
        this.scale() +
         multiplicand.scale()
        .
        Specified by:
        multiply in interface Quantity
        Parameters:
        multiplicand - value to be multiplied by this Quantity. If the multiplicand's scale exceeds the capabilities of the implementation, it may be rounded implicitly.
        Returns:
        this * multiplicand
      • divide

        public Quantity divide​(long divisor)
        Description copied from interface: Quantity
        Returns a Quantity whose value is
        this /
         divisor
        , and whose preferred scale is
        this.scale() -
         divisor.scale()
        ; if the exact quotient cannot be represented an ArithmeticException is thrown.
        Specified by:
        divide in interface Quantity
        Parameters:
        divisor - value by which this Quantity is to be divided.
        Returns:
        this / divisor
      • divide

        public Quantity divide​(double divisor)
        Description copied from interface: Quantity
        Returns a Quantity whose value is
        this /
         divisor
        , and whose preferred scale is
        this.scale() -
         divisor.scale()
        ; if the exact quotient cannot be represented an ArithmeticException is thrown.
        Specified by:
        divide in interface Quantity
        Parameters:
        divisor - value by which this Quantity is to be divided.
        Returns:
        this / divisor
      • divide

        public Quantity divide​(java.lang.Number divisor)
        Description copied from interface: Quantity
        Returns a Quantity whose value is
        this /
         divisor
        , and whose preferred scale is
        this.scale() -
         divisor.scale()
        ; if the exact quotient cannot be represented an ArithmeticException is thrown.
        Specified by:
        divide in interface Quantity
        Parameters:
        divisor - value by which this Quantity is to be divided.
        Returns:
        this / divisor
      • remainder

        public Quantity remainder​(long divisor)
        Description copied from interface: Quantity
        Returns a Quantity whose value is
        this % divisor
        . The remainder is given by
        this.subtract(this.divideToIntegralValue(divisor).multiply(divisor)
        . Note that this is not the modulo operation (the result can be negative).
        Specified by:
        remainder in interface Quantity
        Parameters:
        divisor - value by which this Quantity is to be divided.
        Returns:
        this % divisor.
      • remainder

        public Quantity remainder​(double divisor)
        Description copied from interface: Quantity
        Returns a Quantity whose value is
        this % divisor
        . The remainder is given by
        this.subtract(this.divideToIntegralValue(divisor).multiply(divisor)
        . Note that this is not the modulo operation (the result can be negative).
        Specified by:
        remainder in interface Quantity
        Parameters:
        divisor - value by which this Quantity is to be divided.
        Returns:
        this % divisor.
      • remainder

        public Quantity remainder​(java.lang.Number divisor)
        Description copied from interface: Quantity
        Returns a Quantity whose value is
        this % divisor
        . The remainder is given by
        this.subtract(this.divideToIntegralValue(divisor).multiply(divisor)
        . Note that this is not the modulo operation (the result can be negative).
        Specified by:
        remainder in interface Quantity
        Parameters:
        divisor - value by which this Quantity is to be divided.
        Returns:
        this % divisor.
      • divideToIntegralValue

        public Quantity divideToIntegralValue​(long divisor)
        Description copied from interface: Quantity
        Returns a Quantity whose value is the integer part of the quotient
        this / divisor
        rounded down. The preferred scale of the result is
        this.scale() -
         divisor.scale()
        .
        Specified by:
        divideToIntegralValue in interface Quantity
        Parameters:
        divisor - value by which this BigDecimal is 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: Quantity
        Returns a Quantity whose value is the integer part of the quotient
        this / divisor
        rounded down. The preferred scale of the result is
        this.scale() - divisor.scale()
        .
        Specified by:
        divideToIntegralValue in interface Quantity
        Parameters:
        divisor - value by which this BigDecimal is 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: Quantity
        Returns a Quantity whose value is the integer part of the quotient
        this / divisor
        rounded down. The preferred scale of the result is
        this.scale() -
         divisor.scale()
        .
        Specified by:
        divideToIntegralValue in interface Quantity
        Parameters:
        divisor - value by which this BigDecimal is 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: Quantity
        Returns a Quantity whose numerical value is equal to ( this * 10n). The scale of the result is
        this.scale() - n
        .
        Specified by:
        scaleByPowerOfTen in interface Quantity
        Parameters:
        power - the power.
        Returns:
        the calculated amount value.
      • abs

        public Quantity abs()
        Description copied from interface: Quantity
        Returns a Quantity whose value is the absolute value of this Quantity, and whose scale is this.scale().
        Specified by:
        abs in interface Quantity
        Returns:
        abs(this
      • negate

        public Quantity negate()
        Description copied from interface: Quantity
        Returns a Quantity whose value is
        -this
        , and whose scale is this.scale().
        Specified by:
        negate in interface Quantity
        Returns:
        -this.
      • plus

        public Quantity plus()
        Description copied from interface: Quantity
        Returns a Quantity whose value is
        +this
        , with rounding according to the context settings.
        Specified by:
        plus in interface Quantity
        Returns:
        this, rounded as necessary. A zero result will have a scale of 0.
        See Also:
        java.math.BigDecimal#plus()java.math.BigDecimal#plus()java.math.BigDecimal#plus()java.math.BigDecimal#plus()java.math.BigDecimal#plus()
      • stripTrailingZeros

        public Quantity stripTrailingZeros()
        Description copied from interface: Quantity
        Returns a Quantity which is numerically equal to this one but with any trailing zeros removed from the representation. For example, stripping the trailing zeros from the Quantity value UNIT 600.0, which has [BigInteger, scale] components equals to [6000, 1], yields 6E2 with [ BigInteger, scale] components equals to [6, -2]
        Specified by:
        stripTrailingZeros in interface Quantity
        Returns:
        a numerically equal Quantity with any trailing zeros removed.
      • compareTo

        public int compareTo​(@NotNull
                             @NotNull Quantity o)
        Specified by:
        compareTo in interface java.lang.Comparable<Quantity>
      • getUnit

        public Unit getUnit()
        Description copied from interface: Quantity
        Gets the corresponding Unit.
        Specified by:
        getUnit in interface Quantity
        Returns:
        the corresponding Unit, not null.