Module life.expert

Class DefaultNumberValue

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static NumberValue ONE
      The value 1, with a scale of 0.
      Backed by BigDecimal.ONE
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultNumberValue​(java.lang.Number number)
      Instantiates a new Default number value.
    • Method Summary

      Modifier and Type Method Description
      double doubleValue()  
      double doubleValueExact()
      Access the numeric value as double.
      float floatValue()  
      long getAmountFractionDenominator()
      This method allows to extract the denominator part of the current fraction, hereby given
      long getAmountFractionNumerator()
      This method allows to extract the numerator part of the current fraction, hereby given
      protected static java.math.BigDecimal getBigDecimal​(java.lang.Number num)
      Deprecated.
      will be removed.
      java.lang.Class<?> getNumberType()
      Get the numeric implementation type, that is the base of this number.
      int getPrecision()
      Returns the precision of this Quantity.
      int getScale()
      Returns the scale of this Quantity.
      int intValue()  
      int intValueExact()
      Access the numeric value as int.
      long longValue()  
      long longValueExact()
      Access the numeric value as long.
      <T extends java.lang.Number>
      T
      numberValue​(java.lang.Class<T> numberType)
      Access the numeric value as Number.
      <T extends java.lang.Number>
      T
      numberValueExact​(java.lang.Class<T> numberType)
      Access the numeric value as Number.
      static NumberValue of​(java.lang.Number number)
      Creates a new instance of NumberValue, using the given number.
      NumberValue round​(java.math.MathContext mathContext)
      Access the current NumberValue rounded using the given MathContext.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Number

        byteValue, shortValue
      • Methods inherited from class java.lang.Object

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

      • ONE

        public static final NumberValue ONE
        The value 1, with a scale of 0.
        Backed by BigDecimal.ONE
        Since:
        0.8
    • Constructor Detail

      • DefaultNumberValue

        public DefaultNumberValue​(java.lang.Number number)
        Instantiates a new Default number value.
        Parameters:
        number - the number
    • Method Detail

      • of

        public static NumberValue of​(java.lang.Number number)
        Creates a new instance of NumberValue, using the given number.
        Parameters:
        number - The numeric part, not null.
        Returns:
        A new instance of NumberValue.
      • getNumberType

        public java.lang.Class<?> getNumberType()
        Description copied from class: NumberValue
        Get the numeric implementation type, that is the base of this number.
        Specified by:
        getNumberType in class NumberValue
        Returns:
        the numeric implementation type, not null.
      • getPrecision

        public int getPrecision()
        Description copied from class: NumberValue
        Returns the precision of this Quantity. (The precision is the number of digits in the unscaled value.) The precision of a zero value is 1.
        Specified by:
        getPrecision in class NumberValue
        Returns:
        the precision of this Quantity.
      • getScale

        public int getScale()
        Description copied from class: NumberValue
        Returns the scale of this Quantity. If zero or positive, the scale is the number of digits to the right of the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power of the negation of the scale. For example, a scale of -3 means the unscaled value is multiplied by 1000.
        Specified by:
        getScale in class NumberValue
        Returns:
        the scale of this Quantity.
      • intValue

        public int intValue()
        Specified by:
        intValue in class java.lang.Number
      • intValueExact

        public int intValueExact()
        Description copied from class: NumberValue
        Access the numeric value as int. Hereby no truncation will be performed to fit the value into the target data type.
        Specified by:
        intValueExact in class NumberValue
        Returns:
        the (possibly) truncated value of the Quantity.
      • longValue

        public long longValue()
        Specified by:
        longValue in class java.lang.Number
      • longValueExact

        public long longValueExact()
        Description copied from class: NumberValue
        Access the numeric value as long. Hereby no truncation will be performed to fit the value into the target data type.
        Specified by:
        longValueExact in class NumberValue
        Returns:
        the (possibly) truncated value of the Quantity.
      • floatValue

        public float floatValue()
        Specified by:
        floatValue in class java.lang.Number
      • doubleValue

        public double doubleValue()
        Specified by:
        doubleValue in class java.lang.Number
      • doubleValueExact

        public double doubleValueExact()
        Description copied from class: NumberValue
        Access the numeric value as double. Hereby no truncation will be performed to fit the value into the target data type.
        Specified by:
        doubleValueExact in class NumberValue
        Returns:
        the (possibly) truncated value of the Quantity.
      • getAmountFractionNumerator

        public long getAmountFractionNumerator()
        Description copied from class: NumberValue
        This method allows to extract the numerator part of the current fraction, hereby given
         *
         w = longValue()
         n = getFractionNominator()
         d = getFractionDenominator() *
        the following must be always true:
         * !(w<0 && n>0)  and
         !(w>0 && n<0)  and
         d>0            and
         |n| < d        // || = absolute value 
        Specified by:
        getAmountFractionNumerator in class NumberValue
        Returns:
        the amount's fraction numerator..
      • getAmountFractionDenominator

        public long getAmountFractionDenominator()
        Description copied from class: NumberValue
        This method allows to extract the denominator part of the current fraction, hereby given
        
         w = longValue()
         n = getFractionNominator()
         d = getFractionDenominator()
         *
        the following must be always true:
        
         !(w<0 && n>0)  and
         !(w>0 && n<0)  and
         d>0            and
         |n| < d        // || = absolute value
         *
        .
        Specified by:
        getAmountFractionDenominator in class NumberValue
        Returns:
        the amount's fraction denominator.
      • numberValue

        public <T extends java.lang.Number> T numberValue​(java.lang.Class<T> numberType)
        Description copied from class: NumberValue
        Access the numeric value as Number. Hereby truncation may be performed as needed to fit the value into the target data type.
        Specified by:
        numberValue in class NumberValue
        Type Parameters:
        T - the type parameter
        Parameters:
        numberType - The concrete number class to be returned. Basically the following Number types, must be supported if available on the corresponding runtime platform:
        • java.lang.Long
        • java.lang.Double
        • java.lang.Number
        • java.math.BigInteger, currently not available on all platforms.
        • java.math.BigDecimal, currently not available on all platforms.
        Returns:
        the (possibly) truncated value of the Quantity.
      • round

        public NumberValue round​(java.math.MathContext mathContext)
        Description copied from class: NumberValue
        Access the current NumberValue rounded using the given MathContext.
        Specified by:
        round in class NumberValue
        Parameters:
        mathContext - the MathContext to be applied.
        Returns:
        the new NumberValue, never null.
        See Also:
        java.math.BigDecimal#round(java.math.MathContext)java.math.BigDecimal#round(java.math.MathContext)
      • numberValueExact

        public <T extends java.lang.Number> T numberValueExact​(java.lang.Class<T> numberType)
        Description copied from class: NumberValue
        Access the numeric value as Number. Hereby no truncation will be performed to fit the value into the target data type.
        Specified by:
        numberValueExact in class NumberValue
        Type Parameters:
        T - the type parameter
        Parameters:
        numberType - The concrete number class to be returned. Basically the following Number types, must be supported if available on the corresponding runtime platform:
        • java.lang.Long
        • java.lang.Double
        • java.lang.Number
        • java.math.BigInteger, currently not available on all platforms.
        • java.math.BigDecimal, currently not available on all platforms.
        Returns:
        the (possibly) truncated value of the Quantity.
      • getBigDecimal

        @Deprecated
        protected static java.math.BigDecimal getBigDecimal​(java.lang.Number num)
        Deprecated.
        will be removed.
        Creates a BigDecimal from the given Number doing the valid conversion depending the type given.
        Parameters:
        num - the number type
        Returns:
        the corresponding BigDecimal
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object