public abstract class AbstractMoney
extends java.lang.Object
implements javax.money.MonetaryAmount, java.io.Serializable
MonetaryAmount
,
by providing the common functionality. The different explicitly typed methods
are all reduced to methods using BigDecimal
as input, hereby
performing any conversion to BigDecimal
as needed. Obviosly this
takes some time, so implementors that want to avoid this overhead should
implement MonetaryAmount
directly.Modifier and Type | Field and Description |
---|---|
protected javax.money.CurrencyUnit |
currency
The currency of this amount.
|
protected javax.money.MonetaryContext |
monetaryContext
the
MonetaryContext used by this instance, e.g. on division. |
Modifier | Constructor and Description |
---|---|
protected |
AbstractMoney()
Required for deserialization.
|
protected |
AbstractMoney(javax.money.CurrencyUnit currency)
Constructor of
AbstractMoney . |
protected |
AbstractMoney(javax.money.CurrencyUnit currency,
javax.money.MonetaryContext monetaryContext)
Creates a new instance os
AbstractMoney . |
Modifier and Type | Method and Description |
---|---|
protected void |
checkAmountParameter(javax.money.MonetaryAmount amount)
Method to check if a currency is compatible with this amount instance.
|
protected static void |
checkNumberParameter(java.lang.Number number)
Internal method to check for correct number parameter.
|
protected static java.math.BigDecimal |
getBigDecimal(double num)
Creates a
BigDecimal from the given Number doing the
valid conversion depending the type given. |
protected static java.math.BigDecimal |
getBigDecimal(long num)
Creates a
BigDecimal from the given Number doing the
valid conversion depending the type given. |
protected static java.math.BigDecimal |
getBigDecimal(java.lang.Number num)
Creates a
BigDecimal from the given Number doing the
valid conversion depending the type given. |
protected static java.math.BigDecimal |
getBigDecimal(java.lang.Number num,
javax.money.MonetaryContext moneyContext)
Creates a
BigDecimal from the given Number doing the
valid conversion depending the type given, if a MonetaryContext
is given, it is applied to the number returned. |
javax.money.CurrencyUnit |
getCurrency()
Returns the amount’s currency, modelled as
CurrencyUnit . |
protected abstract javax.money.MonetaryContext |
getDefaultMonetaryContext()
Method to be implemented by superclasses to provide the default
MonetaryContext , when not explicit MonetaryContext is
available. |
protected static java.math.MathContext |
getMathContext(javax.money.MonetaryContext monetaryContext,
java.math.RoundingMode defaultMode)
Evaluates the
MathContext from the given MonetaryContext . |
javax.money.MonetaryContext |
getMonetaryContext()
Access the
MonetaryContext used by this instance. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
abs, add, divide, divide, divide, divideAndRemainder, divideAndRemainder, divideAndRemainder, divideToIntegralValue, divideToIntegralValue, divideToIntegralValue, getFactory, getNumber, isEqualTo, isGreaterThan, isGreaterThanOrEqualTo, isLessThan, isLessThanOrEqualTo, isNegative, isNegativeOrZero, isPositive, isPositiveOrZero, isZero, multiply, multiply, multiply, negate, plus, query, remainder, remainder, remainder, scaleByPowerOfTen, signum, stripTrailingZeros, subtract, with
protected javax.money.CurrencyUnit currency
protected javax.money.MonetaryContext monetaryContext
MonetaryContext
used by this instance, e.g. on division.protected AbstractMoney()
protected AbstractMoney(javax.money.CurrencyUnit currency)
AbstractMoney
.currency
- the currency, not null
.protected AbstractMoney(javax.money.CurrencyUnit currency, javax.money.MonetaryContext monetaryContext)
AbstractMoney
.currency
- the currency, not null
.monetaryContext
- the MonetaryContext
, not null
.protected void checkAmountParameter(javax.money.MonetaryAmount amount)
amount
- The monetary amount to be compared to, never null.javax.money.MonetaryException
- If the amount is null, or the amount's currency is not
compatible (same CurrencyUnit#getNamespace()
and same
CurrencyUnit.getCurrencyCode()
).protected static void checkNumberParameter(java.lang.Number number)
number
- java.lang.IllegalArgumentException
- If the number is nullprotected static java.math.BigDecimal getBigDecimal(double num)
BigDecimal
from the given Number
doing the
valid conversion depending the type given.num
- the number typeBigDecimal
protected static java.math.BigDecimal getBigDecimal(long num)
BigDecimal
from the given Number
doing the
valid conversion depending the type given.num
- the number typeBigDecimal
protected static java.math.BigDecimal getBigDecimal(java.lang.Number num)
BigDecimal
from the given Number
doing the
valid conversion depending the type given.num
- the number typeBigDecimal
protected static java.math.BigDecimal getBigDecimal(java.lang.Number num, javax.money.MonetaryContext moneyContext)
BigDecimal
from the given Number
doing the
valid conversion depending the type given, if a MonetaryContext
is given, it is applied to the number returned.num
- the number typeBigDecimal
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
getCurrency
in interface javax.money.MonetaryAmount
null
MonetaryAmount.getCurrency()
protected abstract javax.money.MonetaryContext getDefaultMonetaryContext()
MonetaryContext
, when not explicit MonetaryContext
is
available.MonetaryContext
, never null
.protected static java.math.MathContext getMathContext(javax.money.MonetaryContext monetaryContext, java.math.RoundingMode defaultMode)
MathContext
from the given MonetaryContext
.monetaryContext
- the MonetaryContext
defaultMode
- the default RoundingMode
, to be used if no one is set
in MonetaryContext
.MathContext
public javax.money.MonetaryContext getMonetaryContext()
MonetaryContext
used by this instance.getMonetaryContext
in interface javax.money.MonetaryAmount
MonetaryContext
used, never null.MonetaryAmount.getMonetaryContext()