public final class Money extends Object implements javax.money.MonetaryAmount, 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.
Modifier and Type | Field and Description |
---|---|
static MathContext |
DEFAULT_MATH_CONTEXT |
Modifier and Type | Method and Description |
---|---|
Money |
abs() |
Money |
add(javax.money.MonetaryAmount amount) |
Number |
asNumber()
Gets the number representation of the numeric value of this item.
|
static BigDecimal |
asNumber(javax.money.MonetaryAmount amt) |
<T> T |
asType(Class<T> type) |
int |
compareTo(javax.money.MonetaryAmount o) |
Money |
divide(javax.money.MonetaryAmount divisor) |
Money |
divide(Number divisor) |
Money[] |
divideAndRemainder(javax.money.MonetaryAmount divisor) |
Money[] |
divideAndRemainder(Number divisor) |
Money |
divideToIntegralValue(javax.money.MonetaryAmount divisor) |
Money |
divideToIntegralValue(Number divisor) |
double |
doubleValue() |
boolean |
equals(Object obj) |
static Money |
from(javax.money.MonetaryAmount amt) |
long |
getAmountFractionDenominator() |
long |
getAmountFractionNumerator() |
long |
getAmountWhole() |
javax.money.CurrencyUnit |
getCurrency() |
MathContext |
getMathContext()
Access the
MathContext used by this instance. |
Class<?> |
getNumberType() |
int |
getPrecision() |
int |
getScale() |
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 |
isNotEqualTo(javax.money.MonetaryAmount amount) |
boolean |
isPositive() |
boolean |
isPositiveOrZero() |
boolean |
isZero() |
long |
longValue() |
long |
longValueExact() |
Money |
multiply(javax.money.MonetaryAmount multiplicand) |
Money |
multiply(Number multiplicand) |
Money |
negate() |
static Money |
of(javax.money.CurrencyUnit currency,
BigDecimal number)
Translates a
BigDecimal value and a CurrencyUnit currency
into a Money . |
static Money |
of(javax.money.CurrencyUnit currency,
BigDecimal number,
MathContext mathContext)
Translates a
BigDecimal value and a CurrencyUnit currency
into a Money . |
static Money |
of(javax.money.CurrencyUnit currency,
Number number)
Static factory method for creating a new instance of
Money . |
static Money |
of(javax.money.CurrencyUnit currency,
Number number,
MathContext mathContext)
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,
MathContext mathContext)
Static factory method for creating a new instance of
Money . |
static Money |
ofZero(javax.money.CurrencyUnit currency)
Factory method creating a zero instance with the given {@code currency);
|
static Money |
ofZero(String currency)
Factory method creating a zero instance with the given {@code currency);
|
Money |
plus() |
Money |
pow(int n) |
<T> T |
query(javax.money.MonetaryQuery<T> query) |
Money |
remainder(javax.money.MonetaryAmount divisor) |
Money |
remainder(Number divisor) |
Money |
scaleByPowerOfTen(int n) |
int |
signum() |
Money |
subtract(javax.money.MonetaryAmount subtrahend) |
String |
toEngineeringString() |
String |
toPlainString() |
String |
toString() |
Money |
ulp() |
Money |
with(javax.money.CurrencyUnit currency)
Creates a new Money instance, by just replacing the
CurrencyUnit . |
Money |
with(javax.money.CurrencyUnit currency,
Number amount)
Creates a new Money instance, by just replacing the
CurrencyUnit
and the numeric amount. |
Money |
with(MathContext context)
Creates a new Money instance, hereby changing the
MathContext to
be used. |
Money |
with(javax.money.MonetaryAdjuster adjuster) |
Money |
with(Number amount) |
Money |
withMathContext(MathContext mathContext)
Allows to change the
MathContext . |
public static final MathContext DEFAULT_MATH_CONTEXT
public static Money of(javax.money.CurrencyUnit currency, BigDecimal number)
BigDecimal
value and a CurrencyUnit
currency
into a Money
.number
- numeric value of the Money
.currency
- currency unit of the Money
.Money
combining the numeric value and currency unit.public static Money of(javax.money.CurrencyUnit currency, BigDecimal number, MathContext mathContext)
BigDecimal
value and a CurrencyUnit
currency
into a Money
.number
- numeric value of the Money
.currency
- currency unit of the Money
.mathContext
- the MathContext
to be used.Money
combining the numeric value and currency unit.public static Money of(javax.money.CurrencyUnit currency, Number number)
Money
.currency
- The target currency, not null.number
- The numeric part, not null.Money
.public static Money of(javax.money.CurrencyUnit currency, Number number, MathContext mathContext)
Money
.currency
- The target currency, not null.number
- The numeric part, not null.Money
.public static Money of(String currencyCode, Number number)
Money
.isoCurrencyCode
- The target currency as ISO currency code.number
- The numeric part, not null.Money
.public static Money of(String currencyCode, Number number, MathContext mathContext)
Money
.isoCurrencyCode
- The target currency as ISO currency code.number
- The numeric part, not null.Money
.public static Money ofZero(javax.money.CurrencyUnit currency)
currency
- the target currency of the amount being created.public static Money ofZero(String currency)
currency
- the target currency of the amount being created.public int compareTo(javax.money.MonetaryAmount o)
compareTo
in interface Comparable<javax.money.MonetaryAmount>
public javax.money.CurrencyUnit getCurrency()
getCurrency
in interface javax.money.MonetaryAmount
public MathContext getMathContext()
MathContext
used by this instance.MathContext
used, never null.public Money withMathContext(MathContext mathContext)
MathContext
. The context will used, on
subsequent operation, where feasible and also propagated to child results
of arithmetic calculations.mathContext
- The new MathContext
, not null.Money
instance, with the new MathContext
.public Money[] divideAndRemainder(javax.money.MonetaryAmount divisor)
public Money[] divideAndRemainder(Number divisor)
public Money divideToIntegralValue(javax.money.MonetaryAmount divisor)
public Money divideToIntegralValue(Number divisor)
public Money scaleByPowerOfTen(int n)
public boolean isZero()
public boolean isPositive()
public boolean isPositiveOrZero()
public boolean isNegative()
public boolean isNegativeOrZero()
public Money with(MathContext context)
MathContext
to
be used. This allows to adapt the MathContext
, when required.context
- the MathContext
to be replaced, not null
CurrencyUnit
, but the new MathContext
.public Money with(javax.money.CurrencyUnit currency, Number amount)
CurrencyUnit
and the numeric amount.currency
- the currency unit to be replaced, not null
MathContext
, but the new CurrencyUnit
.public Money with(javax.money.CurrencyUnit currency)
CurrencyUnit
.currency
- the currency unit to be replaced, not null
MathContext
, but the new CurrencyUnit
.public int getScale()
public int getPrecision()
public long longValue()
public long longValueExact()
public double doubleValue()
public int signum()
public String toEngineeringString()
public String toPlainString()
public boolean isLessThan(javax.money.MonetaryAmount amount)
public boolean isLessThanOrEqualTo(javax.money.MonetaryAmount amount)
public boolean isGreaterThan(javax.money.MonetaryAmount amount)
public boolean isGreaterThanOrEqualTo(javax.money.MonetaryAmount amount)
public boolean isEqualTo(javax.money.MonetaryAmount amount)
public boolean isNotEqualTo(javax.money.MonetaryAmount amount)
public Class<?> getNumberType()
public <T> T query(javax.money.MonetaryQuery<T> query)
query
in interface javax.money.MonetaryAmount
public Number asNumber()
Number
represention matching best.public long getAmountWhole()
getAmountWhole
in interface javax.money.MonetaryAmount
public long getAmountFractionNumerator()
getAmountFractionNumerator
in interface javax.money.MonetaryAmount
public long getAmountFractionDenominator()
getAmountFractionDenominator
in interface javax.money.MonetaryAmount
public Money with(javax.money.MonetaryAdjuster adjuster)
with
in interface javax.money.MonetaryAmount
public static BigDecimal asNumber(javax.money.MonetaryAmount amt)
Copyright © 2012–2013 JSR 354 - Expert Group. All rights reserved.