public final class Money extends Object implements javax.money.MonetaryAmount, Comparable<javax.money.MonetaryAmount>, Serializable
MonetaryAmount
based
on BigDecimal
as 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. |
Modifier and Type | Method and Description |
---|---|
Money |
abs() |
Money |
add(javax.money.MonetaryAmount amount) |
static void |
checkNoInfinityOrNaN(Number number) |
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. |
javax.money.MonetaryContext |
getContext()
Access the
MonetaryContext used by this instance. |
javax.money.CurrencyUnit |
getCurrency()
Returns the amount’s currency, modelled as
CurrencyUnit . |
javax.money.MonetaryAmountFactory<Money> |
getFactory() |
javax.money.NumberValue |
getNumber()
Gets the number representation of the numeric value of this item.
|
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) |
static boolean |
isInfinityAndNotNaN(Number number) |
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(BigDecimal number,
javax.money.CurrencyUnit currency)
Creates a new instance of
Money , using the default
MonetaryContext . |
static Money |
of(BigDecimal number,
javax.money.CurrencyUnit currency,
javax.money.MonetaryContext monetaryContext)
Creates a new instance of
Money , using an explicit
MonetaryContext . |
static Money |
of(BigDecimal number,
String currencyCode)
Static factory method for creating a new instance of
Money . |
static Money |
of(BigDecimal number,
String currencyCode,
javax.money.MonetaryContext monetaryContext)
Static factory method for creating a new instance of
Money . |
static Money |
of(Number number,
javax.money.CurrencyUnit currency)
Creates a new instance of
Money , using the default
MonetaryContext . |
static Money |
of(Number number,
javax.money.CurrencyUnit currency,
javax.money.MonetaryContext monetaryContext)
Creates a new instance of
Money , using an explicit
MonetaryContext . |
static Money |
of(Number number,
String currencyCode)
Static factory method for creating a new instance of
Money . |
static Money |
of(Number number,
String currencyCode,
javax.money.MonetaryContext monetaryContext)
Static factory method for creating a new instance of
Money . |
static Money |
parse(CharSequence text)
Obtains an instance of Money from a text string such as 'EUR 25.25'.
|
static Money |
parse(CharSequence text,
javax.money.format.MonetaryAmountFormat formatter)
Obtains an instance of Money from a text using specific formatter.
|
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 power) |
int |
signum() |
Money |
stripTrailingZeros() |
Money |
subtract(javax.money.MonetaryAmount amount) |
String |
toString() |
Money |
with(javax.money.MonetaryOperator operator) |
public static final javax.money.MonetaryContext DEFAULT_MONETARY_CONTEXT
MonetaryContext
applied, if not set explicitly on
creation.public javax.money.CurrencyUnit getCurrency()
CurrencyUnit
.
Implementations may co-variantly change the return type to a more
specific implementation of CurrencyUnit
if desired.getCurrency
in interface javax.money.CurrencySupplier
null
CurrencySupplier.getCurrency()
public javax.money.MonetaryContext getContext()
MonetaryContext
used by this instance.getContext
in interface javax.money.MonetaryAmount
MonetaryContext
used, never null.MonetaryAmount.getContext()
public javax.money.NumberValue getNumber()
getNumber
in interface javax.money.NumberSupplier
Number
representation matching best.public 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.MonetaryAmount
public Money divide(double divisor)
divide
in interface javax.money.MonetaryAmount
public Money[] divideAndRemainder(long divisor)
divideAndRemainder
in interface javax.money.MonetaryAmount
public Money[] divideAndRemainder(double divisor)
divideAndRemainder
in interface javax.money.MonetaryAmount
public Money multiply(long multiplicand)
multiply
in interface javax.money.MonetaryAmount
public Money multiply(double multiplicand)
multiply
in interface javax.money.MonetaryAmount
public Money remainder(long divisor)
remainder
in interface javax.money.MonetaryAmount
public Money remainder(double divisor)
remainder
in interface javax.money.MonetaryAmount
public boolean isZero()
isZero
in interface javax.money.MonetaryAmount
public boolean isPositive()
isPositive
in interface javax.money.MonetaryAmount
public boolean isPositiveOrZero()
isPositiveOrZero
in interface javax.money.MonetaryAmount
public boolean isNegative()
isNegative
in interface javax.money.MonetaryAmount
public boolean isNegativeOrZero()
isNegativeOrZero
in interface javax.money.MonetaryAmount
public <R> R query(javax.money.MonetaryQuery<R> query)
query
in interface javax.money.MonetaryAmount
public Money with(javax.money.MonetaryOperator operator)
with
in interface javax.money.MonetaryAmount
public Money add(javax.money.MonetaryAmount amount)
add
in interface javax.money.MonetaryAmount
public Money divide(Number divisor)
divide
in interface javax.money.MonetaryAmount
public Money[] divideAndRemainder(Number divisor)
divideAndRemainder
in interface javax.money.MonetaryAmount
public Money divideToIntegralValue(long divisor)
divideToIntegralValue
in interface javax.money.MonetaryAmount
public Money divideToIntegralValue(double divisor)
divideToIntegralValue
in interface javax.money.MonetaryAmount
public Money divideToIntegralValue(Number divisor)
divideToIntegralValue
in interface javax.money.MonetaryAmount
public Money multiply(Number multiplicand)
multiply
in interface javax.money.MonetaryAmount
public Money subtract(javax.money.MonetaryAmount amount)
subtract
in interface javax.money.MonetaryAmount
public Money stripTrailingZeros()
stripTrailingZeros
in interface javax.money.MonetaryAmount
public Money remainder(Number divisor)
remainder
in interface javax.money.MonetaryAmount
public Money scaleByPowerOfTen(int power)
scaleByPowerOfTen
in interface javax.money.MonetaryAmount
public int signum()
signum
in interface javax.money.MonetaryAmount
public boolean isLessThan(javax.money.MonetaryAmount amount)
isLessThan
in interface javax.money.MonetaryAmount
public boolean isLessThanOrEqualTo(javax.money.MonetaryAmount amount)
isLessThanOrEqualTo
in interface javax.money.MonetaryAmount
public boolean isGreaterThan(javax.money.MonetaryAmount amount)
isGreaterThan
in interface javax.money.MonetaryAmount
public boolean isGreaterThanOrEqualTo(javax.money.MonetaryAmount amount)
isGreaterThanOrEqualTo
in interface javax.money.MonetaryAmount
public boolean isEqualTo(javax.money.MonetaryAmount amount)
isEqualTo
in interface javax.money.MonetaryAmount
public javax.money.MonetaryAmountFactory<Money> getFactory()
getFactory
in interface javax.money.MonetaryAmount
public static Money of(BigDecimal number, javax.money.CurrencyUnit currency)
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(BigDecimal number, javax.money.CurrencyUnit currency, 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(Number number, javax.money.CurrencyUnit currency)
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(Number number, javax.money.CurrencyUnit currency, 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(Number number, String currencyCode)
Money
.currencyCode
- The target currency as ISO currency code.number
- The numeric part, not null.Money
.public static Money of(BigDecimal number, String currencyCode)
Money
.currencyCode
- The target currency as ISO currency code.number
- The numeric part, not null.Money
.public static Money of(Number number, String currencyCode, 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(BigDecimal number, String currencyCode, 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 convertedpublic static Money parse(CharSequence text)
text
- the text to parse not nullNullPointerException
NumberFormatException
javax.money.UnknownCurrencyException
public static Money parse(CharSequence text, javax.money.format.MonetaryAmountFormat formatter)
text
- the text to parse not nullformatter
- the formatter to use not nullpublic static void checkNoInfinityOrNaN(Number number)
public static boolean isInfinityAndNotNaN(Number number)
Copyright © 2012-2015 JavaMoney. All Rights Reserved.