Class AbstractDecimal<T extends AbstractDecimal>

    • Constructor Detail

      • AbstractDecimal

        protected AbstractDecimal()
        This constructor should never be called except during JAXB unmarshalling.
      • AbstractDecimal

        protected AbstractDecimal​(String value,
                                  int scale)
        This is the base constructor, used by constructors that take other types
        Parameters:
        value - String containing numeric value - defaults to zero
      • AbstractDecimal

        protected AbstractDecimal​(int value,
                                  int scale)
      • AbstractDecimal

        protected AbstractDecimal​(double value,
                                  int scale)
      • AbstractDecimal

        protected AbstractDecimal​(BigDecimal value,
                                  int scale)
    • Method Detail

      • isLessThan

        public boolean isLessThan​(T operand)
        Parameters:
        operand - the operand to compare against. cannot be null
        Returns:
        true if this AbstractDecimal is less than the given AbstractDecimal
        Throws:
        IllegalArgumentException - if operand is null
      • isGreaterThan

        public boolean isGreaterThan​(T operand)
        Parameters:
        operand - the operand to compare against. cannot be null
        Returns:
        true if this AbstractDecimal is greater than the given AbstractDecimal
        Throws:
        IllegalArgumentException - if operand is null
      • isLessEqual

        public boolean isLessEqual​(T operand)
        Parameters:
        operand - the operand to compare against. cannot be null
        Returns:
        true if this AbstractDecimal is less than or equal to the given AbstractDecimal
        Throws:
        IllegalArgumentException - if operand is null
      • isGreaterEqual

        public boolean isGreaterEqual​(T operand)
        Parameters:
        operand - the operand to compare against. cannot be null
        Returns:
        true if this AbstractDecimal is greater than or equal to the given AbstractDecimal
        Throws:
        IllegalArgumentException - if operand is null
      • isNumeric

        public static boolean isNumeric​(String s)
        Returns:
        true if the given String can be used to construct a valid AbstractDecimal
        Throws:
        IllegalArgumentException - if operand is null
      • doubleValue

        public double doubleValue()
        Specified by:
        doubleValue in class Number
      • floatValue

        public float floatValue()
        Specified by:
        floatValue in class Number
      • intValue

        public int intValue()
        Specified by:
        intValue in class Number
      • longValue

        public long longValue()
        Specified by:
        longValue in class Number
      • bigDecimalValue

        public BigDecimal bigDecimalValue()
        Returns:
        the value of this instance as a BigDecimal.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • isNegative

        public boolean isNegative()
        Returns:
        true if this T is less than zero
      • isPositive

        public boolean isPositive()
        Returns:
        true if this T is greater than zero
      • isZero

        public boolean isZero()
        Returns:
        true if this T is equal to zero
      • abs

        public T abs()
        Returns:
        a T with the same scale and the absolute value
      • isNonZero

        public boolean isNonZero()
        Returns:
        true if this T is not equal to zero
      • add

        public T add​(T addend)
        Wraps BigDecimal's add method to accept and return T instances instead of BigDecimals, so that users of the class don't have to typecast the return value.
        Parameters:
        addend - the value to add
        Returns:
        result of adding the given addend to this value
        Throws:
        IllegalArgumentException - if the given addend is null
      • subtract

        public T subtract​(T subtrahend)
        Wraps BigDecimal's subtract method to accept and return T instances instead of BigDecimals, so that users of the class don't have to typecast the return value.
        Parameters:
        subtrahend - the value to subtract
        Returns:
        result of the subtracting the given subtrahend from this value
        Throws:
        IllegalArgumentException - if the given subtrahend is null
      • multiply

        public T multiply​(T multiplier)
        Wraps BigDecimal's multiply method to accept and return T instances instead of BigDecimals, so that users of the class don't have to typecast the return value.
        Parameters:
        multiplier - the value to multiply
        Returns:
        result of multiplying this value by the given multiplier
        Throws:
        IllegalArgumentException - if the given multiplier is null
      • mod

        public T mod​(T modulus)
        This method calculates the mod between to T values by first casting to doubles and then by performing the % operation on the two primitives.
        Parameters:
        modulus - The other value to apply the mod to.
        Returns:
        result of performing the mod calculation
        Throws:
        IllegalArgumentException - if the given modulus is null
      • divide

        public T divide​(T divisor)
        Wraps BigDecimal's divide method to enforce the default rounding behavior
        Parameters:
        divisor - the value to divide by
        Returns:
        result of dividing this value by the given divisor
        Throws:
        IllegalArgumentException - if the given divisor is null
      • negated

        public T negated()
        Returns:
        a T with the same scale and a negated value (iff the value is non-zero)
      • percentage

        public T percentage​(T rate)
      • newInstance

        protected abstract T newInstance​(int value)
      • newInstance

        protected abstract T newInstance​(BigDecimal value,
                                         int scale)
      • zero

        protected abstract T zero()
      • oneHundred

        protected abstract T oneHundred()