Package ch.tocco.nice2.toolbox.api.util
Class Money
java.lang.Object
ch.tocco.nice2.toolbox.api.util.Money
- All Implemented Interfaces:
Serializable
,Cloneable
,Comparable<Money>
This value class handles money.
The code is based on the proposal of Martin Fowler and Matt Foemmel
as read in "Patterns of Enterprise Application Architecture"
(p.488ff) where a Money class was discussed and introduced.
- See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
Money()
used to skip calculations in public constructorsCloning ctor.Money
(BigDecimal amount, Currency cur) Money
(BigDecimal amount, Currency currency, RoundingMode roundingMode) Creates a new money of the provided m_amount and m_currency. -
Method Summary
Modifier and TypeMethodDescriptionMoney[]
allocate
(int n) Money[]
allocate
(long[] ratios) clone()
int
convertCurrency
(double factor, Currency currency) convertCurrency
(BigDecimal factor, Currency currency) divideBy
(double div) divideBy
(int div) divideBy
(BigDecimal div) divideBy
(BigDecimal div, RoundingMode roundingMode) static Money
dollars
(double amount) double
Return the amount as double value.boolean
static Money
euros
(double amount) formatAmount
(@Nullable Locale locale) static Money
franc
(double amount) static NumberFormat
getAmountFormatter
(@Nullable Locale locale) static NumberFormat
getFormatter
(Currency currency, @Nullable Locale locale) int
hashCode()
boolean
isGreaterThan
(Money other) boolean
isLowerThan
(Money other) multiply
(double fac) multiply
(BigDecimal fac) multiply
(BigDecimal fac, RoundingMode roundingmode) static @Nullable Money
toString()
withAmount
(double amount) withAmount
(long amount) withAmount
(BigDecimal amount) withCurrency
(Currency currency)
-
Constructor Details
-
Money
-
Money
-
Money
-
Money
-
Money
Creates a new money of the provided m_amount and m_currency. User defined rounding mode is used - this method is alluded to in Fowlers book if not actually defined there. -
Money
Cloning ctor. -
Money
protected Money()used to skip calculations in public constructors
-
-
Method Details
-
getFormatter
-
getAmountFormatter
-
getCurrency
-
getAmount
-
withCurrency
-
withAmount
-
withAmount
-
withAmount
-
doubleValue
public double doubleValue()Return the amount as double value. -
add
-
subtract
-
multiply
-
multiply
-
multiply
-
divideBy
-
divideBy
-
divideBy
-
divideBy
-
allocate
-
allocate
-
euros
-
dollars
-
franc
-
convertCurrency
-
convertCurrency
-
parse
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Money>
-
isGreaterThan
-
isLowerThan
-
toParsableString
-
toString
-
formatAmount
-
toString
-
hashCode
public int hashCode() -
equals
-
clone
-