public final class Money extends AbstractMoney implements java.lang.Comparable<javax.money.MonetaryAmount>, java.io.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()
Returns a
MonetaryAmount whose value is the absolute value of this
MonetaryAmount, and whose scale is this.scale(). |
Money |
add(javax.money.MonetaryAmount amount)
Returns a
MonetaryAmount whose value is (this +
amount), and whose scale is max(this.scale(),
amount.scale()). |
int |
compareTo(javax.money.MonetaryAmount o) |
Money |
divide(double divisor)
Returns a
MonetaryAmount whose value is (this /
divisor), and whose preferred scale is (this.scale() -
divisor.scale()); if the exact quotient cannot be represented an ArithmeticException
is thrown. |
Money |
divide(long divisor)
Returns a
MonetaryAmount whose value is (this /
divisor), and whose preferred scale is (this.scale() -
divisor.scale()); if the exact quotient cannot be represented an ArithmeticException
is thrown. |
Money |
divide(java.lang.Number divisor)
Returns a
MonetaryAmount whose value is (this /
divisor), and whose preferred scale is (this.scale() -
divisor.scale()); if the exact quotient cannot be represented an ArithmeticException
is thrown. |
Money[] |
divideAndRemainder(double divisor)
Returns a two-element
MonetaryAmount array containing the result of
divideToIntegralValue followed by the result of remainder on the two
operands. |
Money[] |
divideAndRemainder(long divisor)
Returns a two-element
MonetaryAmount array containing the result of
divideToIntegralValue followed by the result of remainder on the two
operands. |
Money[] |
divideAndRemainder(java.lang.Number divisor)
Returns a two-element
MonetaryAmount array containing the result of
divideToIntegralValue followed by the result of remainder on the two
operands. |
Money |
divideToIntegralValue(double divisor)
Returns a
MonetaryAmount whose value is the integer part of the quotient
(this / divisor) rounded down. |
Money |
divideToIntegralValue(long divisor)
Returns a
MonetaryAmount whose value is the integer part of the quotient
(this / divisor) rounded down. |
Money |
divideToIntegralValue(java.lang.Number divisor)
Returns a
MonetaryAmount whose value is the integer part of the quotient
(this / divisor) rounded down. |
boolean |
equals(java.lang.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()
Creates a new
MonetaryAmountFactory, returning the same implementation type Hereby
this given amount is used as a template, so reusing the CurrencyUnit, its numeric
value, the algorithmic implementation as well as the current MonetaryContext. |
javax.money.NumberValue |
getNumber()
Simple accessor for the numeric part of a
MonetaryAmount. |
java.math.BigDecimal |
getNumberStripped()
Method that returns BigDecimal.ZERO, if
isZero(), and
#stripTrailingZeros() in all other cases. |
int |
hashCode() |
boolean |
isEqualTo(javax.money.MonetaryAmount amount)
Compares two instances of
MonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities. |
boolean |
isGreaterThan(javax.money.MonetaryAmount amount)
Compares two instances of
MonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities. |
boolean |
isGreaterThanOrEqualTo(javax.money.MonetaryAmount amount)
Compares two instances of
MonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities. |
boolean |
isLessThan(javax.money.MonetaryAmount amount)
Compares two instances of
MonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities. |
boolean |
isLessThanOrEqualTo(javax.money.MonetaryAmount amount)
Compares two instances of
MonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities. |
boolean |
isNegative()
Checks if a
MonetaryAmount is negative. |
boolean |
isNegativeOrZero()
Checks if a
MonetaryAmount is negative or zero. |
boolean |
isPositive()
Checks if a
MonetaryAmount is positive. |
boolean |
isPositiveOrZero()
Checks if a
MonetaryAmount is positive or zero. |
boolean |
isZero()
Checks if an
MonetaryAmount is zero. |
Money |
multiply(double multiplicand)
Returns a
MonetaryAmount whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale()). |
Money |
multiply(long multiplicand)
Returns a
MonetaryAmount whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale()). |
Money |
multiply(java.lang.Number multiplicand)
Returns a
MonetaryAmount whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale()). |
Money |
negate()
Returns a
MonetaryAmount whose value is (-this), and whose scale is
this.scale(). |
static Money |
of(javax.money.CurrencyUnit currency,
java.math.BigDecimal number)
Creates a new instance of
Money, using the default
MonetaryContext. |
static Money |
of(javax.money.CurrencyUnit currency,
java.math.BigDecimal number,
javax.money.MonetaryContext monetaryContext)
Creates a new instance of
Money, using an explicit
MonetaryContext. |
static Money |
of(javax.money.CurrencyUnit currency,
java.lang.Number number)
Creates a new instance of
Money, using the default
MonetaryContext. |
static Money |
of(javax.money.CurrencyUnit currency,
java.lang.Number number,
javax.money.MonetaryContext monetaryContext)
Creates a new instance of
Money, using an explicit
MonetaryContext. |
static Money |
of(java.lang.String currencyCode,
java.math.BigDecimal number)
Static factory method for creating a new instance of
Money. |
static Money |
of(java.lang.String currencyCode,
java.math.BigDecimal number,
javax.money.MonetaryContext monetaryContext)
Static factory method for creating a new instance of
Money. |
static Money |
of(java.lang.String currencyCode,
java.lang.Number number)
Static factory method for creating a new instance of
Money. |
static Money |
of(java.lang.String currencyCode,
java.lang.Number number,
javax.money.MonetaryContext monetaryContext)
Static factory method for creating a new instance of
Money. |
Money |
plus()
Returns a
MonetaryAmount whose value is (+this), with rounding according to
the context settings. |
<R> R |
query(javax.money.MonetaryQuery<R> query)
Queries this monetary amount for a value.
|
Money |
remainder(double divisor)
Returns a
MonetaryAmount whose value is (this % divisor). |
Money |
remainder(long divisor)
Returns a
MonetaryAmount whose value is (this % divisor). |
Money |
remainder(java.lang.Number divisor)
Returns a
MonetaryAmount whose value is (this % divisor). |
Money |
scaleByPowerOfTen(int n)
Returns a
MonetaryAmount whose numerical value is equal to ( this *
10n). |
int |
signum()
Returns the signum function of this
MonetaryAmount. |
Money |
stripTrailingZeros()
Returns a
MonetaryAmount which is numerically equal to this one but with any trailing
zeros removed from the representation. |
Money |
subtract(javax.money.MonetaryAmount subtrahend)
Returns a
MonetaryAmount whose value is (this -
amount), and whose scale is max(this.scale(),
subtrahend.scale()). |
java.lang.String |
toString() |
Money |
with(javax.money.MonetaryOperator operator)
Returns an operated object of the same type as this object with the operation made.
|
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 Money abs()
javax.money.MonetaryAmountMonetaryAmount whose value is the absolute value of this
MonetaryAmount, and whose scale is this.scale().abs in interface javax.money.MonetaryAmountabs(this)public Money add(javax.money.MonetaryAmount amount)
javax.money.MonetaryAmountMonetaryAmount whose value is (this +
amount), and whose scale is max(this.scale(),
amount.scale()).add in interface javax.money.MonetaryAmountamount - value to be added to this MonetaryAmount.this + amountpublic int compareTo(javax.money.MonetaryAmount o)
compareTo in interface java.lang.Comparable<javax.money.MonetaryAmount>public Money divide(double divisor)
javax.money.MonetaryAmountMonetaryAmount whose value is (this /
divisor), and whose preferred scale is (this.scale() -
divisor.scale()); if the exact quotient cannot be represented an ArithmeticException
is thrown.divide in interface javax.money.MonetaryAmountdivisor - value by which this MonetaryAmount is to be divided.this / divisorpublic Money divide(long divisor)
javax.money.MonetaryAmountMonetaryAmount whose value is (this /
divisor), and whose preferred scale is (this.scale() -
divisor.scale()); if the exact quotient cannot be represented an ArithmeticException
is thrown.divide in interface javax.money.MonetaryAmountdivisor - value by which this MonetaryAmount is to be divided.this / divisorpublic Money divide(java.lang.Number divisor)
javax.money.MonetaryAmountMonetaryAmount whose value is (this /
divisor), and whose preferred scale is (this.scale() -
divisor.scale()); if the exact quotient cannot be represented an ArithmeticException
is thrown.divide in interface javax.money.MonetaryAmountdivisor - value by which this MonetaryAmount is to be divided.this / divisorpublic Money[] divideAndRemainder(double divisor)
javax.money.MonetaryAmountMonetaryAmount array containing the result of
divideToIntegralValue followed by the result of remainder on the two
operands.
Note that if both the integer quotient and remainder are needed, this method is faster than
using the divideToIntegralValue and remainder methods separately because the
division need only be carried out once.
divideAndRemainder in interface javax.money.MonetaryAmountdivisor - value by which this MonetaryAmount is to be divided, and the remainder
computed.MonetaryAmount array: the quotient (the result of
divideToIntegralValue) is the initial element and the remainder is the final
element.MonetaryAmount.divideToIntegralValue(double),
MonetaryAmount.remainder(double)public Money[] divideAndRemainder(long divisor)
javax.money.MonetaryAmountMonetaryAmount array containing the result of
divideToIntegralValue followed by the result of remainder on the two
operands.
Note that if both the integer quotient and remainder are needed, this method is faster than
using the divideToIntegralValue and remainder methods separately because the
division need only be carried out once.
divideAndRemainder in interface javax.money.MonetaryAmountdivisor - value by which this MonetaryAmount is to be divided, and the remainder
computed.MonetaryAmount array: the quotient (the result of
divideToIntegralValue) is the initial element and the remainder is the final
element.MonetaryAmount.divideToIntegralValue(long),
MonetaryAmount.remainder(long)public Money[] divideAndRemainder(java.lang.Number divisor)
javax.money.MonetaryAmountMonetaryAmount array containing the result of
divideToIntegralValue followed by the result of remainder on the two
operands.
Note that if both the integer quotient and remainder are needed, this method is faster than
using the divideToIntegralValue and remainder methods separately because the
division need only be carried out once.
divideAndRemainder in interface javax.money.MonetaryAmountdivisor - value by which this MonetaryAmount is to be divided, and the remainder
computed.MonetaryAmount array: the quotient (the result of
divideToIntegralValue) is the initial element and the remainder is the final
element.MonetaryAmount.divideToIntegralValue(Number),
MonetaryAmount.remainder(Number)public Money divideToIntegralValue(double divisor)
javax.money.MonetaryAmountMonetaryAmount whose value is the integer part of the quotient
(this / divisor) rounded down. The preferred scale of the result is
(this.scale() -
divisor.scale()).divideToIntegralValue in interface javax.money.MonetaryAmountdivisor - value by which this BigDecimal is to be divided.this / divisor.BigDecimal.divideToIntegralValue(java.math.BigDecimal)public Money divideToIntegralValue(long divisor)
javax.money.MonetaryAmountMonetaryAmount whose value is the integer part of the quotient
(this / divisor) rounded down. The preferred scale of the result is
(this.scale() -
divisor.scale()).divideToIntegralValue in interface javax.money.MonetaryAmountdivisor - value by which this BigDecimal is to be divided.this / divisor.BigDecimal.divideToIntegralValue(java.math.BigDecimal)public Money divideToIntegralValue(java.lang.Number divisor)
javax.money.MonetaryAmountMonetaryAmount whose value is the integer part of the quotient
(this / divisor) rounded down. The preferred scale of the result is
(this.scale() -
divisor.scale()).divideToIntegralValue in interface javax.money.MonetaryAmountdivisor - value by which this BigDecimal is to be divided.this / divisor.BigDecimal.divideToIntegralValue(java.math.BigDecimal)public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic 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 convertedprotected javax.money.MonetaryContext getDefaultMonetaryContext()
AbstractMoneyMonetaryContext, when not explicit MonetaryContext is
available.getDefaultMonetaryContext in class AbstractMoneyMonetaryContext, never null.public javax.money.MonetaryAmountFactory<Money> getFactory()
javax.money.MonetaryAmountMonetaryAmountFactory, returning the same implementation type Hereby
this given amount is used as a template, so reusing the CurrencyUnit, its numeric
value, the algorithmic implementation as well as the current MonetaryContext.
This method is used for creating a new amount result after having done calculations that are not directly mappable to the default monetary arithmetics, e.g. currency conversion.
getFactory in interface javax.money.MonetaryAmountMonetaryAmountFactory with the given MonetaryAmount as its
default values.public javax.money.NumberValue getNumber()
javax.money.MonetaryAmountMonetaryAmount. The representation type
returned should be the best matching according to the internal representation. In all cases
never any truncation should occur, so this method must be exact regarding the numeric value
externalized.getNumber in interface javax.money.MonetaryAmountgetNumber in interface javax.money.NumberSupplierMonetaryAmount, never null.public java.math.BigDecimal getNumberStripped()
isZero(), and
#stripTrailingZeros() in all other cases.public int hashCode()
hashCode in class java.lang.Objectpublic boolean isEqualTo(javax.money.MonetaryAmount amount)
javax.money.MonetaryAmountMonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities.isEqualTo in interface javax.money.MonetaryAmountamount - the MonetaryAmount to be compared with this instance.true if amount == this.public boolean isGreaterThan(javax.money.MonetaryAmount amount)
javax.money.MonetaryAmountMonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities.isGreaterThan in interface javax.money.MonetaryAmountamount - the MonetaryAmount to be compared with this instance.true if amount > this.public boolean isGreaterThanOrEqualTo(javax.money.MonetaryAmount amount)
javax.money.MonetaryAmountMonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities.isGreaterThanOrEqualTo in interface javax.money.MonetaryAmountamount - the MonetaryAmount to be compared with this instance.true if amount >= this.public boolean isLessThan(javax.money.MonetaryAmount amount)
javax.money.MonetaryAmountMonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities.isLessThan in interface javax.money.MonetaryAmountamount - the MonetaryAmount to be compared with this instance.true if amount < this.public boolean isLessThanOrEqualTo(javax.money.MonetaryAmount amount)
javax.money.MonetaryAmountMonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities.isLessThanOrEqualTo in interface javax.money.MonetaryAmountamount - the MonetaryAmount to be compared with this instance.true if amount <= this.public boolean isNegative()
javax.money.MonetaryAmountMonetaryAmount is negative.isNegative in interface javax.money.MonetaryAmounttrue if MonetaryAmount.signum() < 0.public boolean isNegativeOrZero()
javax.money.MonetaryAmountMonetaryAmount is negative or zero.isNegativeOrZero in interface javax.money.MonetaryAmounttrue if MonetaryAmount.signum() <= 0.public boolean isPositive()
javax.money.MonetaryAmountMonetaryAmount is positive.isPositive in interface javax.money.MonetaryAmounttrue if MonetaryAmount.signum() > 0.public boolean isPositiveOrZero()
javax.money.MonetaryAmountMonetaryAmount is positive or zero.isPositiveOrZero in interface javax.money.MonetaryAmounttrue if MonetaryAmount.signum() >= 0.public boolean isZero()
javax.money.MonetaryAmountMonetaryAmount is zero.isZero in interface javax.money.MonetaryAmounttrue if MonetaryAmount.signum() == 0.public Money multiply(double multiplicand)
javax.money.MonetaryAmountMonetaryAmount whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale()).multiply in interface javax.money.MonetaryAmountmultiplicand - value to be multiplied by this MonetaryAmount.this * multiplicandpublic Money multiply(long multiplicand)
javax.money.MonetaryAmountMonetaryAmount whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale()).multiply in interface javax.money.MonetaryAmountmultiplicand - value to be multiplied by this MonetaryAmount.this * multiplicandpublic Money multiply(java.lang.Number multiplicand)
javax.money.MonetaryAmountMonetaryAmount whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale()).multiply in interface javax.money.MonetaryAmountmultiplicand - value to be multiplied by this MonetaryAmount.this * multiplicandpublic Money negate()
javax.money.MonetaryAmountMonetaryAmount whose value is (-this), and whose scale is
this.scale().negate in interface javax.money.MonetaryAmount-this.public static Money of(javax.money.CurrencyUnit currency, java.math.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.java.lang.ArithmeticException - If the number exceeds the capabilities of the default
MonetaryContext used.public static Money of(javax.money.CurrencyUnit currency, java.math.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.java.lang.ArithmeticException - If the number exceeds the capabilities of the
MonetaryContext used.public static Money of(javax.money.CurrencyUnit currency, java.lang.Number number)
Money, using the default
MonetaryContext.currency - The target currency, not null.number - The numeric part, not null.Money.java.lang.ArithmeticException - If the number exceeds the capabilities of the default
MonetaryContext used.public static Money of(javax.money.CurrencyUnit currency, java.lang.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.java.lang.ArithmeticException - If the number exceeds the capabilities of the
MonetaryContext used.public static Money of(java.lang.String currencyCode, java.math.BigDecimal number)
Money.currencyCode - The target currency as ISO currency code.number - The numeric part, not null.Money.public static Money of(java.lang.String currencyCode, java.math.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 of(java.lang.String currencyCode, java.lang.Number number)
Money.currencyCode - The target currency as ISO currency code.number - The numeric part, not null.Money.public static Money of(java.lang.String currencyCode, java.lang.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 Money plus()
javax.money.MonetaryAmountMonetaryAmount whose value is (+this), with rounding according to
the context settings.plus in interface javax.money.MonetaryAmountthis, rounded as necessary. A zero result will have a scale of 0.BigDecimal.plus()public <R> R query(javax.money.MonetaryQuery<R> query)
javax.money.MonetaryAmountThis queries this amount using the specified query strategy object.
Implementations must ensure that no observable state is altered when this read-only method is invoked.
query in interface javax.money.MonetaryAmountR - the type of the resultquery - the query to invoke, not nullpublic Money remainder(double divisor)
javax.money.MonetaryAmountMonetaryAmount whose value is (this % divisor).
The remainder is given by
this.subtract(this.divideToIntegralValue(divisor).multiply(divisor)) . Note that this
is not the modulo operation (the result can be negative).
remainder in interface javax.money.MonetaryAmountdivisor - value by which this MonetaryAmount is to be divided.this % divisor.public Money remainder(long divisor)
javax.money.MonetaryAmountMonetaryAmount whose value is (this % divisor).
The remainder is given by
this.subtract(this.divideToIntegralValue(divisor).multiply(divisor)) . Note that this
is not the modulo operation (the result can be negative).
remainder in interface javax.money.MonetaryAmountdivisor - value by which this MonetaryAmount is to be divided.this % divisor.public Money remainder(java.lang.Number divisor)
javax.money.MonetaryAmountMonetaryAmount whose value is (this % divisor).
The remainder is given by
this.subtract(this.divideToIntegralValue(divisor).multiply(divisor)) . Note that this
is not the modulo operation (the result can be negative).
remainder in interface javax.money.MonetaryAmountdivisor - value by which this MonetaryAmount is to be divided.this % divisor.public Money scaleByPowerOfTen(int n)
javax.money.MonetaryAmountMonetaryAmount whose numerical value is equal to ( this *
10n). The scale of the result is (this.scale() - n).scaleByPowerOfTen in interface javax.money.MonetaryAmountn - the power.public int signum()
javax.money.MonetaryAmountMonetaryAmount.signum in interface javax.money.MonetaryAmountMonetaryAmount is negative, zero, or
positive.public Money stripTrailingZeros()
javax.money.MonetaryAmountMonetaryAmount which is numerically equal to this one but with any trailing
zeros removed from the representation. For example, stripping the trailing zeros from the
MonetaryAmount value CHF 600.0, which has [BigInteger, scale]
components equals to [6000, 1], yields 6E2 with [ BigInteger, scale]
components equals to [6, -2]stripTrailingZeros in interface javax.money.MonetaryAmountMonetaryAmount with any trailing zeros removed.public Money subtract(javax.money.MonetaryAmount subtrahend)
javax.money.MonetaryAmountMonetaryAmount whose value is (this -
amount), and whose scale is max(this.scale(),
subtrahend.scale()).subtract in interface javax.money.MonetaryAmountsubtrahend - value to be subtracted from this MonetaryAmount.this - amountpublic java.lang.String toString()
toString in class java.lang.Objectpublic Money with(javax.money.MonetaryOperator operator)
javax.money.MonetaryAmountMonetaryAmountFactory instances: // converting from Money to MyMoney Money m = ...; MonetartyAmountFactoryf = MonetaryAmounts.getAmountFactory(MyMoney.class); MyMoney myMoney = f.setAmount(m).create();
This converts this monetary amount according to the rules of the specified operator. A typical operator will change the amount and leave the currency unchanged. A more complex operator might also change the currency.
Some example code indicating how and why this method is used:
Hereby also the method signature on the implementation type must return the concrete type, to enable a fluent API, e.g.MonetaryAmount money = money.with(amountMultipliedBy(2)); money = money.with(amountRoundedToNearestWholeUnit());
public final class MyMoney implements MonetaryAmount{
...
public MyMoney with(MonetaryOperator operator){
...
}
...
}
with in interface javax.money.MonetaryAmountoperator - the operator to use, not null