Package org.kuali.coeus.sys.api.model
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 aroundBigDecimal. It exposes the only the needed functionality ofBigDecimaland uses a standardRoundingModeofRoundingMode.HALF_UP. Children this class should be, likeBigDecimal, immutable; even methods which might be expected to change the value actually just return a new instance with the new value.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static RoundingModeROUND_BEHAVIORprotected BigDecimalvalue
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractDecimal()This constructor should never be called except during JAXB unmarshalling.protectedAbstractDecimal(double value, int scale)protectedAbstractDecimal(int value, int scale)protectedAbstractDecimal(String value, int scale)This is the base constructor, used by constructors that take other typesprotectedAbstractDecimal(BigDecimal value, int scale)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Tabs()Tadd(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.BigDecimalbigDecimalValue()intcompareTo(T k)Returns the result of comparing the values of thisAbstractDecimaland the givenAbstractDecimal.Tdivide(T divisor)Wraps BigDecimal's divide method to enforce the default rounding behaviordoubledoubleValue()booleanequals(Object obj)floatfloatValue()inthashCode()intintValue()booleanisGreaterEqual(T operand)booleanisGreaterThan(T operand)booleanisLessEqual(T operand)booleanisLessThan(T operand)booleanisNegative()booleanisNonZero()static booleanisNumeric(String s)booleanisPositive()booleanisZero()longlongValue()Tmod(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.Tmultiply(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.Tnegated()protected abstract TnewInstance(int value)protected abstract TnewInstance(BigDecimal value, int scale)protected abstract ToneHundred()Tpercentage(T rate)Tsubtract(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.StringtoString()protected abstract Tzero()-
Methods inherited from class java.lang.Number
byteValue, shortValue
-
-
-
-
Field Detail
-
ROUND_BEHAVIOR
public static final RoundingMode ROUND_BEHAVIOR
-
value
protected final BigDecimal value
-
-
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:
doubleValuein classNumber
-
floatValue
public float floatValue()
- Specified by:
floatValuein classNumber
-
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 thisAbstractDecimaland the givenAbstractDecimal.- Specified by:
compareToin interfaceComparable<T extends AbstractDecimal>- See Also:
Comparable.compareTo(java.lang.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)
-
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()
-
-