public final class Money extends AbstractMoney implements Comparable<javax.money.MonetaryAmount>, Serializable
MonetaryAmount based
on BigDecimal for the numeric representation.
As required by MonetaryAmount this class is final, thread-safe,
immutable and serializable.
This class can be configured with an arbitrary MonetaryContext. The
default MonetaryContext used models by default the same settings as
MathContext.DECIMAL64 . This default MonetaryContext can also
be reconfigured by adding a file /javamoney.properties to the
classpath, with the following content:
# Default MathContext for Money #------------------------------- # Custom MonetaryContext, overrides default entries from # org.javamoney.moneta.Money.monetaryContext # RoundingMode hereby is optional (default = HALF_EVEN) org.javamoney.moneta.Money.defaults.precision=256 org.javamoney.moneta.Money.defaults.roundingMode=HALF_EVEN
| Modifier and Type | Field and Description |
|---|---|
static javax.money.MonetaryContext |
DEFAULT_MONETARY_CONTEXT
The default
MonetaryContext applied, if not set explicitly on
creation. |
currency, monetaryContext| Modifier and Type | Method and Description |
|---|---|
Money |
abs() |
Money |
add(javax.money.MonetaryAmount amount) |
int |
compareTo(javax.money.MonetaryAmount o) |
Money |
divide(double divisor) |
Money |
divide(long divisor) |
Money |
divide(Number divisor) |
Money[] |
divideAndRemainder(double divisor) |
Money[] |
divideAndRemainder(long divisor) |
Money[] |
divideAndRemainder(Number divisor) |
Money |
divideToIntegralValue(double divisor) |
Money |
divideToIntegralValue(long divisor) |
Money |
divideToIntegralValue(Number divisor) |
boolean |
equals(Object obj) |
static Money |
from(javax.money.MonetaryAmount amt)
Converts (if necessary) the given
MonetaryAmount to a
Money instance. |
protected javax.money.MonetaryContext |
getDefaultMonetaryContext()
Method to be implemented by superclasses to provide the default
MonetaryContext, when not explicit MonetaryContext is
available. |
javax.money.MonetaryAmountFactory<Money> |
getFactory() |
javax.money.NumberValue |
getNumber() |
BigDecimal |
getNumberStripped()
Method that returns BigDecimal.ZERO, if
isZero(), and
#stripTrailingZeros() in all other cases. |
int |
hashCode() |
boolean |
isEqualTo(javax.money.MonetaryAmount amount) |
boolean |
isGreaterThan(javax.money.MonetaryAmount amount) |
boolean |
isGreaterThanOrEqualTo(javax.money.MonetaryAmount amount) |
boolean |
isLessThan(javax.money.MonetaryAmount amount) |
boolean |
isLessThanOrEqualTo(javax.money.MonetaryAmount amount) |
boolean |
isNegative() |
boolean |
isNegativeOrZero() |
boolean |
isPositive() |
boolean |
isPositiveOrZero() |
boolean |
isZero() |
Money |
multiply(double multiplicand) |
Money |
multiply(long multiplicand) |
Money |
multiply(Number multiplicand) |
Money |
negate() |
static Money |
of(javax.money.CurrencyUnit currency,
BigDecimal number)
Creates a new instance of
Money, using the default
MonetaryContext. |
static Money |
of(javax.money.CurrencyUnit currency,
BigDecimal number,
javax.money.MonetaryContext monetaryContext)
Creates a new instance of
Money, using an explicit
MonetaryContext. |
static Money |
of(javax.money.CurrencyUnit currency,
Number number)
Creates a new instance of
Money, using the default
MonetaryContext. |
static Money |
of(javax.money.CurrencyUnit currency,
Number number,
javax.money.MonetaryContext monetaryContext)
Creates a new instance of
Money, using an explicit
MonetaryContext. |
static Money |
of(String currencyCode,
BigDecimal number)
Static factory method for creating a new instance of
Money. |
static Money |
of(String currencyCode,
BigDecimal number,
javax.money.MonetaryContext monetaryContext)
Static factory method for creating a new instance of
Money. |
static Money |
of(String currencyCode,
Number number)
Static factory method for creating a new instance of
Money. |
static Money |
of(String currencyCode,
Number number,
javax.money.MonetaryContext monetaryContext)
Static factory method for creating a new instance of
Money. |
Money |
plus() |
<R> R |
query(javax.money.MonetaryQuery<R> query) |
Money |
remainder(double divisor) |
Money |
remainder(long divisor) |
Money |
remainder(Number divisor) |
Money |
scaleByPowerOfTen(int n) |
int |
signum() |
Money |
stripTrailingZeros() |
Money |
subtract(javax.money.MonetaryAmount subtrahend) |
String |
toString() |
Money |
with(javax.money.MonetaryOperator operator) |
checkAmountParameter, checkNumberParameter, getBigDecimal, getBigDecimal, getBigDecimal, getBigDecimal, getCurrency, getMathContext, getMonetaryContextpublic static final javax.money.MonetaryContext DEFAULT_MONETARY_CONTEXT
MonetaryContext applied, if not set explicitly on
creation.public javax.money.NumberValue getNumber()
getNumber in interface javax.money.MonetaryAmountgetNumber in interface javax.money.NumberSupplierpublic BigDecimal getNumberStripped()
isZero(), and
#stripTrailingZeros() in all other cases.public int compareTo(javax.money.MonetaryAmount o)
compareTo in interface Comparable<javax.money.MonetaryAmount>public Money divide(long divisor)
divide in interface javax.money.MonetaryAmountpublic Money divide(double divisor)
divide in interface javax.money.MonetaryAmountpublic Money[] divideAndRemainder(long divisor)
divideAndRemainder in interface javax.money.MonetaryAmountpublic Money[] divideAndRemainder(double divisor)
divideAndRemainder in interface javax.money.MonetaryAmountpublic Money multiply(long multiplicand)
multiply in interface javax.money.MonetaryAmountpublic Money multiply(double multiplicand)
multiply in interface javax.money.MonetaryAmountpublic Money remainder(long divisor)
remainder in interface javax.money.MonetaryAmountpublic Money remainder(double divisor)
remainder in interface javax.money.MonetaryAmountpublic boolean isZero()
isZero in interface javax.money.MonetaryAmountpublic boolean isPositive()
isPositive in interface javax.money.MonetaryAmountpublic boolean isPositiveOrZero()
isPositiveOrZero in interface javax.money.MonetaryAmountpublic boolean isNegative()
isNegative in interface javax.money.MonetaryAmountpublic boolean isNegativeOrZero()
isNegativeOrZero in interface javax.money.MonetaryAmountpublic <R> R query(javax.money.MonetaryQuery<R> query)
query in interface javax.money.MonetaryAmountpublic Money with(javax.money.MonetaryOperator operator)
with in interface javax.money.MonetaryAmountpublic Money add(javax.money.MonetaryAmount amount)
add in interface javax.money.MonetaryAmountpublic Money divide(Number divisor)
divide in interface javax.money.MonetaryAmountpublic Money[] divideAndRemainder(Number divisor)
divideAndRemainder in interface javax.money.MonetaryAmountpublic Money divideToIntegralValue(long divisor)
divideToIntegralValue in interface javax.money.MonetaryAmountpublic Money divideToIntegralValue(double divisor)
divideToIntegralValue in interface javax.money.MonetaryAmountpublic Money divideToIntegralValue(Number divisor)
divideToIntegralValue in interface javax.money.MonetaryAmountpublic Money multiply(Number multiplicand)
multiply in interface javax.money.MonetaryAmountpublic Money subtract(javax.money.MonetaryAmount subtrahend)
subtract in interface javax.money.MonetaryAmountpublic Money stripTrailingZeros()
stripTrailingZeros in interface javax.money.MonetaryAmountpublic Money remainder(Number divisor)
remainder in interface javax.money.MonetaryAmountpublic Money scaleByPowerOfTen(int n)
scaleByPowerOfTen in interface javax.money.MonetaryAmountpublic int signum()
signum in interface javax.money.MonetaryAmountpublic boolean isLessThan(javax.money.MonetaryAmount amount)
isLessThan in interface javax.money.MonetaryAmountpublic boolean isLessThanOrEqualTo(javax.money.MonetaryAmount amount)
isLessThanOrEqualTo in interface javax.money.MonetaryAmountpublic boolean isGreaterThan(javax.money.MonetaryAmount amount)
isGreaterThan in interface javax.money.MonetaryAmountpublic boolean isGreaterThanOrEqualTo(javax.money.MonetaryAmount amount)
isGreaterThanOrEqualTo in interface javax.money.MonetaryAmountpublic boolean isEqualTo(javax.money.MonetaryAmount amount)
isEqualTo in interface javax.money.MonetaryAmountpublic javax.money.MonetaryAmountFactory<Money> getFactory()
getFactory in interface javax.money.MonetaryAmountprotected javax.money.MonetaryContext getDefaultMonetaryContext()
AbstractMoneyMonetaryContext, when not explicit MonetaryContext is
available.getDefaultMonetaryContext in class AbstractMoneyMonetaryContext, never null.public static Money of(javax.money.CurrencyUnit currency, BigDecimal number)
Money, using the default
MonetaryContext.number - numeric value, not null.currency - currency unit, not null.Money combining the numeric value and currency unit.ArithmeticException - If the number exceeds the capabilities of the default
MonetaryContext used.public static Money of(javax.money.CurrencyUnit currency, BigDecimal number, javax.money.MonetaryContext monetaryContext)
Money, using an explicit
MonetaryContext.number - numeric value, not null.currency - currency unit, not null.monetaryContext - the MonetaryContext to be used, if null the
default MonetaryContext is used.Money instance based on the monetary context with the
given numeric value, currency unit.ArithmeticException - If the number exceeds the capabilities of the
MonetaryContext used.public static Money of(javax.money.CurrencyUnit currency, Number number)
Money, using the default
MonetaryContext.currency - The target currency, not null.number - The numeric part, not null.Money.ArithmeticException - If the number exceeds the capabilities of the default
MonetaryContext used.public static Money of(javax.money.CurrencyUnit currency, Number number, javax.money.MonetaryContext monetaryContext)
Money, using an explicit
MonetaryContext.currency - The target currency, not null.number - The numeric part, not null.monetaryContext - the MonetaryContext to be used, if null the
default MonetaryContext is used.Money.ArithmeticException - If the number exceeds the capabilities of the
MonetaryContext used.public static Money of(String currencyCode, Number number)
Money.currencyCode - The target currency as ISO currency code.number - The numeric part, not null.Money.public static Money of(String currencyCode, BigDecimal number)
Money.currencyCode - The target currency as ISO currency code.number - The numeric part, not null.Money.public static Money of(String currencyCode, Number number, javax.money.MonetaryContext monetaryContext)
Money.currencyCode - The target currency as ISO currency code.number - The numeric part, not null.monetaryContext - the MonetaryContext to be used, if null the
default MonetaryContext is used.Money.public static Money of(String currencyCode, BigDecimal number, javax.money.MonetaryContext monetaryContext)
Money.currencyCode - The target currency as ISO currency code.number - The numeric part, not null.monetaryContext - the MonetaryContext to be used, if null the
default MonetaryContext is used.Money.public static Money from(javax.money.MonetaryAmount amt)
MonetaryAmount to a
Money instance. The MonetaryContext will be adapted as
necessary, if the precision of the given amount exceeds the capabilities
of the default MonetaryContext.amt - the amount to be convertedCopyright © 2012-2014 JavaMoney. All Rights Reserved.