Package rs.baselib.type
Class MonetaryValue
java.lang.Object
rs.baselib.type.MonetaryValue
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<MonetaryValue>
public class MonetaryValue extends java.lang.Object implements java.io.Serializable, java.lang.Comparable<MonetaryValue>
A
BigDecimal configured for monetary operations.
The BigDecimal is configured with a precision scale of 2, RoundingMode.HALF_UP.
- Since:
- 1.2.9
- Author:
- ralph
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_SCALEThe default scale to be used for monetary valuesstatic java.math.MathContextMATH_CONTEXTTheMathContextto be used for monetary valuesstatic java.math.RoundingModeROUNDING_MODEBanker's roundingstatic MonetaryValueZERO0 -
Constructor Summary
Constructors Constructor Description MonetaryValue(double value)Constructor.MonetaryValue(int value)Constructor.MonetaryValue(long value)Constructor.MonetaryValue(java.lang.CharSequence value)Constructor.MonetaryValue(java.math.BigDecimal value)Constructor.MonetaryValue(java.math.BigDecimal value, java.math.RoundingMode roundingMode)Constructor.MonetaryValue(java.math.BigDecimal value, java.math.RoundingMode roundingMode, java.math.MathContext mathContext, int scale)Constructor.MonetaryValue(java.math.BigInteger value)Constructor.MonetaryValue(MonetaryValue value)Constructor. -
Method Summary
Modifier and Type Method Description MonetaryValueadd(double value)Adds another value to this objectMonetaryValueadd(int value)Adds another value to this objectMonetaryValueadd(long value)Adds another value to this objectMonetaryValueadd(java.lang.CharSequence value)Adds another value to this objectMonetaryValueadd(java.math.BigDecimal value)Adds another value to this objectMonetaryValueadd(java.math.BigInteger value)Adds another value to this objectMonetaryValueadd(MonetaryValue value)Adds another value to this objectintcompareTo(MonetaryValue o)MonetaryValuedivide(double value)Divides this object by another value.MonetaryValuedivide(int value)Divides this object by another value.MonetaryValuedivide(long value)Divides this object by another value.MonetaryValuedivide(java.lang.CharSequence value)Divides this object by another value.MonetaryValuedivide(java.math.BigDecimal value)Divides this object by another value.MonetaryValuedivide(java.math.BigInteger value)Divides this object by another value.java.math.BigDecimaldivide(MonetaryValue value)Divides this object by another value.booleanequals(java.lang.Object other)java.math.BigDecimalgetAmount()Returns the amount.java.math.BigIntegergetBigInteger()Returns this value asBigInteger.doublegetDouble()Returns this value as a double.floatgetFloat()Returns this value as a float.intgetInt()Returns this value as int.longgetLong()Returns this value as a long.java.math.MathContextgetMathContext()Returns theMathContext.java.math.RoundingModegetRoundingMode()Returns the rounding mode.intgetScale()Returns the scale.inthashCode()booleanisNegative()Is value negative?booleanisPositive()Is value positive?booleanisZero()Is value positive?MonetaryValuemultiply(double value)Multiplies another value with this object.MonetaryValuemultiply(int value)Multiplies another value with this object.MonetaryValuemultiply(long value)Multiplies another value with this object.MonetaryValuemultiply(java.lang.CharSequence value)Multiplies another value with this object.MonetaryValuemultiply(java.math.BigDecimal value)Multiplies another value with this object.MonetaryValuemultiply(java.math.BigInteger value)Multiplies another value with this object.MonetaryValuenegate()Negates this value.voidsetAmount(java.math.BigDecimal amount)Sets the amount.voidsetMathContext(java.math.MathContext mathContext)Sets theMathContext.voidsetRoundingMode(java.math.RoundingMode roundingMode)Sets the rounding mode.voidsetScale(int scale)Sets the scale.MonetaryValuesubtract(double value)Subtracts another value from this object.MonetaryValuesubtract(int value)Subtracts another value from this object.MonetaryValuesubtract(long value)Subtracts another value from this object.MonetaryValuesubtract(java.lang.CharSequence value)Subtracts another value from this object.MonetaryValuesubtract(java.math.BigDecimal value)Subtracts another value from this object.MonetaryValuesubtract(java.math.BigInteger value)Subtracts another value from this object.MonetaryValuesubtract(MonetaryValue value)Subtracts another value from this object.java.lang.StringtoString()The representation of the value as string
-
Field Details
-
ROUNDING_MODE
public static final java.math.RoundingMode ROUNDING_MODEBanker's rounding -
MATH_CONTEXT
public static final java.math.MathContext MATH_CONTEXTTheMathContextto be used for monetary values -
DEFAULT_SCALE
public static final int DEFAULT_SCALEThe default scale to be used for monetary values- See Also:
- Constant Field Values
-
ZERO
0
-
-
Constructor Details
-
MonetaryValue
public MonetaryValue(java.math.BigDecimal value)Constructor.- Parameters:
value- the monetary value
-
MonetaryValue
Constructor.- Parameters:
value- the monetary value
-
MonetaryValue
public MonetaryValue(java.math.BigDecimal value, java.math.RoundingMode roundingMode)Constructor.- Parameters:
value- the monetary valueroundingMode- the rounding mode to be used
-
MonetaryValue
public MonetaryValue(java.math.BigDecimal value, java.math.RoundingMode roundingMode, java.math.MathContext mathContext, int scale)Constructor.- Parameters:
value- the monetary valueroundingMode- the rounding mode to be usedmathContext- theMathContextto be usedscale- the scale to be used
-
MonetaryValue
public MonetaryValue(java.lang.CharSequence value)Constructor.- Parameters:
value- the monetary value
-
MonetaryValue
public MonetaryValue(double value)Constructor.- Parameters:
value- the monetary value
-
MonetaryValue
public MonetaryValue(java.math.BigInteger value)Constructor.- Parameters:
value- the monetary value
-
MonetaryValue
public MonetaryValue(int value)Constructor.- Parameters:
value- the monetary value
-
MonetaryValue
public MonetaryValue(long value)Constructor.- Parameters:
value- the monetary value
-
-
Method Details
-
getAmount
public java.math.BigDecimal getAmount()Returns the amount.- Returns:
- the amount
-
setAmount
public void setAmount(java.math.BigDecimal amount)Sets the amount.- Parameters:
amount- the amount to set
-
getRoundingMode
public java.math.RoundingMode getRoundingMode()Returns the rounding mode.- Returns:
- the rounding mode
-
setRoundingMode
public void setRoundingMode(java.math.RoundingMode roundingMode)Sets the rounding mode.- Parameters:
roundingMode- the rounding mode to set
-
getScale
public int getScale()Returns the scale.- Returns:
- the scale
-
setScale
public void setScale(int scale)Sets the scale.- Parameters:
scale- the scale to set
-
getMathContext
public java.math.MathContext getMathContext()Returns theMathContext.- Returns:
- the mathContext
-
setMathContext
public void setMathContext(java.math.MathContext mathContext)Sets theMathContext.- Parameters:
mathContext- the mathContext to set
-
isPositive
public boolean isPositive()Is value positive?- Returns:
truewhen value is a positive number
-
isNegative
public boolean isNegative()Is value negative?- Returns:
truewhen value is a negative number
-
isZero
public boolean isZero()Is value positive?- Returns:
truewhen value is a positive number
-
add
Adds another value to this object- Parameters:
value- value to be added- Returns:
- new monetary value holding the result
-
add
Adds another value to this object- Parameters:
value- value to be added- Returns:
- new monetary value holding the result
-
add
Adds another value to this object- Parameters:
value- value to be added- Returns:
- new monetary value holding the result
-
add
Adds another value to this object- Parameters:
value- value to be added- Returns:
- new monetary value holding the result
-
add
Adds another value to this object- Parameters:
value- value to be added- Returns:
- new monetary value holding the result
-
add
Adds another value to this object- Parameters:
value- value to be added- Returns:
- new monetary value holding the result
-
add
Adds another value to this object- Parameters:
value- value to be added- Returns:
- new monetary value holding the result
-
subtract
Subtracts another value from this object.- Parameters:
value- value to be subtracted- Returns:
- new monetary value holding the result
-
subtract
Subtracts another value from this object.- Parameters:
value- value to be subtracted- Returns:
- new monetary value holding the result
-
subtract
Subtracts another value from this object.- Parameters:
value- value to be subtracted- Returns:
- new monetary value holding the result
-
subtract
Subtracts another value from this object.- Parameters:
value- value to be subtracted- Returns:
- new monetary value holding the result
-
subtract
Subtracts another value from this object.- Parameters:
value- value to be subtracted- Returns:
- new monetary value holding the result
-
subtract
Subtracts another value from this object.- Parameters:
value- value to be subtracted- Returns:
- new monetary value holding the result
-
subtract
Subtracts another value from this object.- Parameters:
value- value to be subtracted- Returns:
- new monetary value holding the result
-
multiply
Multiplies another value with this object.- Parameters:
value- value to be multiplied with- Returns:
- new monetary value holding the result
-
multiply
Multiplies another value with this object.- Parameters:
value- value to be multiplied with- Returns:
- new monetary value holding the result
-
multiply
Multiplies another value with this object.- Parameters:
value- value to be multiplied with- Returns:
- new monetary value holding the result
-
multiply
Multiplies another value with this object.- Parameters:
value- value to be multiplied with- Returns:
- new monetary value holding the result
-
multiply
Multiplies another value with this object.- Parameters:
value- value to be multiplied with- Returns:
- new monetary value holding the result
-
multiply
Multiplies another value with this object.- Parameters:
value- value to be multiplied with- Returns:
- new monetary value holding the result
-
divide
Divides this object by another value.- Parameters:
value- value to be divided by- Returns:
- new monetary value holding the result
-
divide
Divides this object by another value.- Parameters:
value- value to be divided by- Returns:
- new monetary value holding the result
-
divide
Divides this object by another value.- Parameters:
value- value to be divided by- Returns:
- new monetary value holding the result
-
divide
Divides this object by another value.- Parameters:
value- value to be divided by- Returns:
- new monetary value holding the result
-
divide
Divides this object by another value.- Parameters:
value- value to be divided by- Returns:
- new monetary value holding the result
-
divide
Divides this object by another value.- Parameters:
value- value to be divided by- Returns:
- new monetary value holding the result
-
divide
Divides this object by another value.- Parameters:
value- value to be divided by- Returns:
- the result of the operation
-
negate
Negates this value.- Returns:
- new monetary value holding the result
-
getDouble
public double getDouble()Returns this value as a double.- Returns:
- value as double
- See Also:
BigDecimal.doubleValue()
-
getFloat
public float getFloat()Returns this value as a float.- Returns:
- value as float
- See Also:
BigDecimal.floatValue()
-
getInt
public int getInt()Returns this value as int.- Returns:
- value as int
- See Also:
BigDecimal.intValue()
-
getBigInteger
public java.math.BigInteger getBigInteger()Returns this value asBigInteger.- Returns:
- value as BigInteger
- See Also:
BigDecimal.toBigInteger()
-
getLong
public long getLong()Returns this value as a long.- Returns:
- value as long
- See Also:
BigDecimal.longValue()
-
compareTo
- Specified by:
compareToin interfacejava.lang.Comparable<MonetaryValue>
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()The representation of the value as string- Overrides:
toStringin classjava.lang.Object- Returns:
- e.g. "12.00" or "0.00" or "-2345.34"
-