Class AbstractDecimal<T extends AbstractDecimal>

java.lang.Object
java.lang.Number
org.kuali.coeus.sys.api.model.AbstractDecimal<T>
All Implemented Interfaces:
Serializable, Comparable<T>
Direct Known Subclasses:
ScaleThreeDecimal, ScaleTwoDecimal

public abstract class AbstractDecimal<T extends AbstractDecimal> extends Number implements Comparable<T>
This class is a wrapper around BigDecimal. It exposes the only the needed functionality of BigDecimal and uses a standard RoundingMode of RoundingMode.HALF_UP. Children this class should be, like BigDecimal, immutable; even methods which might be expected to change the value actually just return a new instance with the new value.
See Also:
  • Field Details

  • Constructor Details

    • 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 Details

    • 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.
    • compareTo

      public int compareTo(T k)
      Returns the result of comparing the values of this AbstractDecimal and the given AbstractDecimal.
      Specified by:
      compareTo in interface Comparable<T extends AbstractDecimal>
      See Also:
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString 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()