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 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 Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedThis 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
Modifier and TypeMethodDescriptionabs()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.intReturns the result of comparing the values of thisAbstractDecimaland the givenAbstractDecimal.Wraps BigDecimal's divide method to enforce the default rounding behaviordoublebooleanfloatinthashCode()intintValue()booleanisGreaterEqual(T operand) booleanisGreaterThan(T operand) booleanisLessEqual(T operand) booleanisLessThan(T operand) booleanbooleanstatic booleanbooleanbooleanisZero()longThis method calculates the mod between to T values by first casting to doubles and then by performing the % operation on the two primitives.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.negated()protected abstract TnewInstance(int value) protected abstract TnewInstance(BigDecimal value, int scale) protected abstract Tpercentage(T rate) 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.toString()protected abstract Tzero()Methods inherited from class java.lang.Number
byteValue, shortValue
-
Field Details
-
ROUND_BEHAVIOR
-
value
-
-
Constructor Details
-
AbstractDecimal
protected AbstractDecimal()This constructor should never be called except during JAXB unmarshalling. -
AbstractDecimal
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
-
-
Method Details
-
isLessThan
- 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
- 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
- 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
- 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
- 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
-
intValue
public int intValue() -
longValue
public long longValue() -
bigDecimalValue
- Returns:
- the value of this instance as a BigDecimal.
-
compareTo
Returns the result of comparing the values of thisAbstractDecimaland the givenAbstractDecimal.- Specified by:
compareToin interfaceComparable<T extends AbstractDecimal>- See Also:
-
equals
-
hashCode
public int hashCode() -
toString
-
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
- 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
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
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
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
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
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
- Returns:
- a T with the same scale and a negated value (iff the value is non-zero)
-
percentage
-
newInstance
-
newInstance
-
zero
-
oneHundred
-