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
ConstructorsModifierConstructorDescriptionprotectedMoney()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()intconvertCurrency(double factor, Currency currency) convertCurrency(BigDecimal factor, Currency currency) divideBy(double div) divideBy(int div) divideBy(BigDecimal div) divideBy(BigDecimal div, RoundingMode roundingMode) static Moneydollars(double amount) doubleReturn the amount as double value.booleanstatic Moneyeuros(double amount) formatAmount(@Nullable Locale locale) static Moneyfranc(double amount) static NumberFormatgetAmountFormatter(@Nullable Locale locale) static NumberFormatgetFormatter(Currency currency, @Nullable Locale locale) inthashCode()booleanisGreaterThan(Money other) booleanisLowerThan(Money other) multiply(double fac) multiply(BigDecimal fac) multiply(BigDecimal fac, RoundingMode roundingmode) static @Nullable MoneytoString()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:
compareToin interfaceComparable<Money>
-
isGreaterThan
-
isLowerThan
-
toParsableString
-
toString
-
formatAmount
-
toString
-
hashCode
public int hashCode() -
equals
-
clone
-