|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.retek.commons.util.type.Money
An immutable class to represent monetary values.
divide(int)
does not result in an arithmetic division of a money's value,
rather it returns a collection of new money objects of even (or close to even) in value.
multiply(Quantity)
and multiply(Percent)
methods are not commutative because each
intermediate operation returns a new Money, and thus is rounded.
For example, moneyA.multiply(quanityB).multiply(percentC)
may not necessarily equal moneyA.multiply(percentC).multiply(quantityB)
. If this is
unacceptable in a specific situation, you can work-around it using toBigDecimal()
on each
value, do all multiplications with BigDecimal.multiply(BigDecimal) (no scale or rounding),
then create a new Money with the result.
Field Summary | |
static Money |
INFINITY
|
static int |
ROUNDING
|
static int |
SCALE
|
static int |
SCALE_FOR_DIVISION
|
static Money |
ZERO
|
Constructor Summary | |
Money(java.math.BigDecimal value)
Note: value will be rounded to SCALE using the ROUNDING rule if necessary. |
|
Money(java.math.BigDecimal value,
boolean isRounding)
Note: value will be rounded to SCALE using the ROUNDING rule if isRounding is true. |
|
Money(long amount)
Convenience constructor for creating whole integer Money, such as $10 |
|
Money(java.lang.String amount)
Convenience constructor. |
|
Money(java.lang.String amount,
boolean isRounding)
|
Method Summary | |
Money |
absoluteValue()
|
Money |
add(Money other)
|
Money |
add(Percent percent)
Increment a Money by a percent. |
Money |
businessAverage(java.lang.Integer numberOfThings)
|
int |
compareTo(java.lang.Object o)
|
java.util.List |
divide(int divisor)
Splits this Money into a divisor-number of smaller Monies of approximately equal size. |
boolean |
equals(java.lang.Object other)
|
int |
hashCode()
|
boolean |
isGreaterThan(Money that)
|
boolean |
isGreaterThanOrEqualTo(Money that)
|
boolean |
isLessThan(Money that)
|
boolean |
isLessThanOrEqualTo(Money that)
|
boolean |
isNegative()
|
boolean |
isPositive()
|
boolean |
isZero()
|
static Money |
min(Money money1,
Money money2)
|
Money |
multiply(long quantity)
|
Money |
multiply(Percent percent)
Note that this method results in a new Money, and thus, the result is rounded according to SCALE and ROUNDING , therefore, using it in combination with
multiply(Quantity) should be done with care (see class-level javadoc). |
Money |
multiply(Quantity quantity)
Note that this method results in a new Money, and thus, the result is rounded according to SCALE and ROUNDING , therefore, using it in combination with
multiply(Percent) should be done with care (see class-level javadoc). |
Money |
prorate(Money prevTotalCharge,
Money currentCharge,
Money grandTotalCharge)
Return the proportionate amount of 'this' dollar value, for the dollar current charge/fee/value. |
Money |
prorate(Quantity prevQty,
Quantity currentQty,
Quantity grandTotalQty)
Return the proportionate amount of 'this' dollar value, for the currentQty. |
Money |
subtract(Money other)
|
Money |
subtract(Percent percent)
Decrement a Money by a percent. |
java.math.BigDecimal |
toBigDecimal()
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final Money INFINITY
public static final Money ZERO
public static final int SCALE_FOR_DIVISION
public static final int SCALE
public static final int ROUNDING
Constructor Detail |
public Money(java.math.BigDecimal value)
public Money(java.math.BigDecimal value, boolean isRounding)
public Money(long amount)
public Money(java.lang.String amount)
SCALE
java.lang.NumberFormatException
- if String amount is null, empty or can't be parsed as a number.public Money(java.lang.String amount, boolean isRounding)
Method Detail |
public Money add(Money other)
public Money add(Percent percent)
public Money subtract(Money other)
public Money subtract(Percent percent)
public Money multiply(long quantity)
public Money multiply(Percent percent)
SCALE
and ROUNDING
, therefore, using it in combination with
multiply(Quantity)
should be done with care (see class-level javadoc).
public Money multiply(Quantity quantity)
SCALE
and ROUNDING
, therefore, using it in combination with
multiply(Percent)
should be done with care (see class-level javadoc).
public java.util.List divide(int divisor)
public Money absoluteValue()
public boolean equals(java.lang.Object other)
public int hashCode()
public int compareTo(java.lang.Object o)
compareTo
in interface java.lang.Comparable
public java.math.BigDecimal toBigDecimal()
public java.lang.String toString()
public boolean isNegative()
public boolean isPositive()
public boolean isZero()
public boolean isGreaterThanOrEqualTo(Money that)
public boolean isGreaterThan(Money that)
public boolean isLessThanOrEqualTo(Money that)
public boolean isLessThan(Money that)
public Money prorate(Quantity prevQty, Quantity currentQty, Quantity grandTotalQty)
prevQty
- is the total of all previous quantities.currentQty
- is the quantity for which the portion will be calculated.
java.lang.NullPointerException
- if any of the three arguments is null.public Money prorate(Money prevTotalCharge, Money currentCharge, Money grandTotalCharge)
prevTotalCharge
- is the total of all previous charges/fees/etc.currentCharge
- is the dollar value for which the portion will be calculated.grandTotalCharge
- is the dollar value with which 'this' money value is associated.
java.lang.NullPointerException
- if any of the three arguments is null.public Money businessAverage(java.lang.Integer numberOfThings) throws AverageOverZeroException
AverageOverZeroException
public static Money min(Money money1, Money money2)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |