public final class DummyAmount extends java.lang.Object implements MonetaryAmount
Constructor and Description |
---|
DummyAmount() |
Modifier and Type | Method and Description |
---|---|
DummyAmount |
abs()
Returns a
MonetaryAmount whose value is the absolute value of this
MonetaryAmount , and whose scale is this.scale() . |
DummyAmount |
add(MonetaryAmount amount)
Returns a
MonetaryAmount whose value is (this +
amount) , and whose scale is max(this.scale(),
amount.scale()) . |
DummyAmount |
divide(double amount)
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. |
DummyAmount |
divide(long amount)
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. |
DummyAmount |
divide(java.lang.Number amount)
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. |
DummyAmount[] |
divideAndRemainder(double amount)
Returns a two-element
MonetaryAmount array containing the result of
divideToIntegralValue followed by the result of remainder on the two
operands. |
DummyAmount[] |
divideAndRemainder(long amount)
Returns a two-element
MonetaryAmount array containing the result of
divideToIntegralValue followed by the result of remainder on the two
operands. |
DummyAmount[] |
divideAndRemainder(java.lang.Number amount)
Returns a two-element
MonetaryAmount array containing the result of
divideToIntegralValue followed by the result of remainder on the two
operands. |
DummyAmount |
divideToIntegralValue(double divisor)
Returns a
MonetaryAmount whose value is the integer part of the quotient
(this / divisor) rounded down. |
DummyAmount |
divideToIntegralValue(long divisor)
Returns a
MonetaryAmount whose value is the integer part of the quotient
(this / divisor) rounded down. |
DummyAmount |
divideToIntegralValue(java.lang.Number divisor)
Returns a
MonetaryAmount whose value is the integer part of the quotient
(this / divisor) rounded down. |
CurrencyUnit |
getCurrency()
Returns the amount’s currency, modeled as
CurrencyUnit . |
MonetaryAmountFactory<DummyAmount> |
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 . |
MonetaryContext |
getMonetaryContext()
Returns the
MonetaryContext of this MonetaryAmount . |
NumberValue |
getNumber()
Simple accessor for the numeric part of a
MonetaryAmount . |
boolean |
isEqualTo(MonetaryAmount amount)
Compares two instances of
MonetaryAmount , hereby ignoring non significant trailing
zeroes and different numeric capabilities. |
boolean |
isGreaterThan(MonetaryAmount amount)
Compares two instances of
MonetaryAmount , hereby ignoring non significant trailing
zeroes and different numeric capabilities. |
boolean |
isGreaterThanOrEqualTo(MonetaryAmount amt)
Compares two instances of
MonetaryAmount , hereby ignoring non significant trailing
zeroes and different numeric capabilities. |
boolean |
isLessThan(MonetaryAmount amt)
Compares two instances of
MonetaryAmount , hereby ignoring non significant trailing
zeroes and different numeric capabilities. |
boolean |
isLessThanOrEqualTo(MonetaryAmount amt)
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. |
DummyAmount |
multiply(double multiplicand)
Returns a
MonetaryAmount whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale()) . |
DummyAmount |
multiply(long multiplicand)
Returns a
MonetaryAmount whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale()) . |
DummyAmount |
multiply(java.lang.Number multiplicand)
Returns a
MonetaryAmount whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale()) . |
DummyAmount |
negate()
Returns a
MonetaryAmount whose value is (-this) , and whose scale is
this.scale() . |
DummyAmount |
plus()
Returns a
MonetaryAmount whose value is (+this) , with rounding according to
the context settings. |
<R> R |
query(MonetaryQuery<R> query)
Queries this monetary amount for a value.
|
DummyAmount |
remainder(double amount)
Returns a
MonetaryAmount whose value is (this % divisor) . |
DummyAmount |
remainder(long amount)
Returns a
MonetaryAmount whose value is (this % divisor) . |
DummyAmount |
remainder(java.lang.Number amount)
Returns a
MonetaryAmount whose value is (this % divisor) . |
DummyAmount |
scaleByPowerOfTen(int power)
Returns a
MonetaryAmount whose numerical value is equal to ( this *
10n). |
int |
signum()
Returns the signum function of this
MonetaryAmount . |
DummyAmount |
stripTrailingZeros()
Returns a
MonetaryAmount which is numerically equal to this one but with any trailing
zeros removed from the representation. |
DummyAmount |
subtract(MonetaryAmount amount)
Returns a
MonetaryAmount whose value is (this -
amount) , and whose scale is max(this.scale(),
subtrahend.scale()) . |
DummyAmount |
with(MonetaryOperator operator)
Returns an operated object of the same type as this object with the operation made.
|
public CurrencyUnit getCurrency()
MonetaryAmount
CurrencyUnit
. Implementations may
co-variantly change the return type to a more specific implementation of CurrencyUnit
if desired.getCurrency
in interface CurrencySupplier
getCurrency
in interface MonetaryAmount
null
public MonetaryContext getMonetaryContext()
MonetaryAmount
MonetaryContext
of this MonetaryAmount
. The
MonetaryContext
provides additional information about the numeric representation and
the numeric capabilities. This information can be used by code to determine situations where
MonetaryAmount
instances must be converted to avoid implicit truncation, which can
lead to invalid results.getMonetaryContext
in interface MonetaryAmount
MonetaryContext
of this MonetaryAmount
, never null
.public NumberValue getNumber()
MonetaryAmount
MonetaryAmount
. 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 MonetaryAmount
getNumber
in interface NumberSupplier
MonetaryAmount
, never null
.public <R> R query(MonetaryQuery<R> query)
MonetaryAmount
This 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 MonetaryAmount
R
- the type of the resultquery
- the query to invoke, not nullpublic DummyAmount with(MonetaryOperator operator)
MonetaryAmount
MonetaryAmountFactory
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 MonetaryAmount
operator
- the operator to use, not nullpublic boolean isGreaterThan(MonetaryAmount amount)
MonetaryAmount
MonetaryAmount
, hereby ignoring non significant trailing
zeroes and different numeric capabilities.isGreaterThan
in interface MonetaryAmount
amount
- the MonetaryAmount
to be compared with this instance.true
if amount > this
.public boolean isGreaterThanOrEqualTo(MonetaryAmount amt)
MonetaryAmount
MonetaryAmount
, hereby ignoring non significant trailing
zeroes and different numeric capabilities.isGreaterThanOrEqualTo
in interface MonetaryAmount
amt
- the MonetaryAmount
to be compared with this instance.true
if amount >= this
.public boolean isLessThan(MonetaryAmount amt)
MonetaryAmount
MonetaryAmount
, hereby ignoring non significant trailing
zeroes and different numeric capabilities.isLessThan
in interface MonetaryAmount
amt
- the MonetaryAmount
to be compared with this instance.true
if amount < this
.public boolean isLessThanOrEqualTo(MonetaryAmount amt)
MonetaryAmount
MonetaryAmount
, hereby ignoring non significant trailing
zeroes and different numeric capabilities.isLessThanOrEqualTo
in interface MonetaryAmount
amt
- the MonetaryAmount
to be compared with this instance.true
if amount <= this
.public boolean isEqualTo(MonetaryAmount amount)
MonetaryAmount
MonetaryAmount
, hereby ignoring non significant trailing
zeroes and different numeric capabilities.isEqualTo
in interface MonetaryAmount
amount
- the MonetaryAmount
to be compared with this instance.true
if amount == this
.public boolean isNegative()
MonetaryAmount
MonetaryAmount
is negative.isNegative
in interface MonetaryAmount
true
if MonetaryAmount.signum()
< 0.public boolean isNegativeOrZero()
MonetaryAmount
MonetaryAmount
is negative or zero.isNegativeOrZero
in interface MonetaryAmount
true
if MonetaryAmount.signum()
<= 0.public boolean isPositive()
MonetaryAmount
MonetaryAmount
is positive.isPositive
in interface MonetaryAmount
true
if MonetaryAmount.signum()
> 0.public boolean isPositiveOrZero()
MonetaryAmount
MonetaryAmount
is positive or zero.isPositiveOrZero
in interface MonetaryAmount
true
if MonetaryAmount.signum()
>= 0.public boolean isZero()
MonetaryAmount
MonetaryAmount
is zero.isZero
in interface MonetaryAmount
true
if MonetaryAmount.signum()
== 0.public int signum()
MonetaryAmount
MonetaryAmount
.signum
in interface MonetaryAmount
MonetaryAmount
is negative, zero, or
positive.public DummyAmount add(MonetaryAmount amount)
MonetaryAmount
MonetaryAmount
whose value is (this +
amount)
, and whose scale is max(this.scale(),
amount.scale())
.add
in interface MonetaryAmount
amount
- value to be added to this MonetaryAmount
.this + amount
public DummyAmount subtract(MonetaryAmount amount)
MonetaryAmount
MonetaryAmount
whose value is (this -
amount)
, and whose scale is max(this.scale(),
subtrahend.scale())
.subtract
in interface MonetaryAmount
amount
- value to be subtracted from this MonetaryAmount
.this - amount
public DummyAmount multiply(long multiplicand)
MonetaryAmount
MonetaryAmount
whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale())
.multiply
in interface MonetaryAmount
multiplicand
- value to be multiplied by this MonetaryAmount
.this * multiplicand
public DummyAmount multiply(double multiplicand)
MonetaryAmount
MonetaryAmount
whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale())
.multiply
in interface MonetaryAmount
multiplicand
- value to be multiplied by this MonetaryAmount
.this * multiplicand
public DummyAmount multiply(java.lang.Number multiplicand)
MonetaryAmount
MonetaryAmount
whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale())
.multiply
in interface MonetaryAmount
multiplicand
- value to be multiplied by this MonetaryAmount
.this * multiplicand
public DummyAmount divide(long amount)
MonetaryAmount
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.divide
in interface MonetaryAmount
amount
- value by which this MonetaryAmount
is to be divided.this / divisor
public DummyAmount divide(double amount)
MonetaryAmount
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.divide
in interface MonetaryAmount
amount
- value by which this MonetaryAmount
is to be divided.this / divisor
public DummyAmount divide(java.lang.Number amount)
MonetaryAmount
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.divide
in interface MonetaryAmount
amount
- value by which this MonetaryAmount
is to be divided.this / divisor
public DummyAmount remainder(long amount)
MonetaryAmount
MonetaryAmount
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 MonetaryAmount
amount
- value by which this MonetaryAmount
is to be divided.this % divisor
.public DummyAmount remainder(double amount)
MonetaryAmount
MonetaryAmount
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 MonetaryAmount
amount
- value by which this MonetaryAmount
is to be divided.this % divisor
.public DummyAmount remainder(java.lang.Number amount)
MonetaryAmount
MonetaryAmount
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 MonetaryAmount
amount
- value by which this MonetaryAmount
is to be divided.this % divisor
.public DummyAmount[] divideAndRemainder(long amount)
MonetaryAmount
MonetaryAmount
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 MonetaryAmount
amount
- 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 DummyAmount[] divideAndRemainder(double amount)
MonetaryAmount
MonetaryAmount
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 MonetaryAmount
amount
- 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 DummyAmount[] divideAndRemainder(java.lang.Number amount)
MonetaryAmount
MonetaryAmount
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 MonetaryAmount
amount
- 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 DummyAmount divideToIntegralValue(long divisor)
MonetaryAmount
MonetaryAmount
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 MonetaryAmount
divisor
- value by which this BigDecimal
is to be divided.this / divisor
.BigDecimal.divideToIntegralValue(java.math.BigDecimal)
public DummyAmount divideToIntegralValue(double divisor)
MonetaryAmount
MonetaryAmount
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 MonetaryAmount
divisor
- value by which this BigDecimal
is to be divided.this / divisor
.BigDecimal.divideToIntegralValue(java.math.BigDecimal)
public DummyAmount divideToIntegralValue(java.lang.Number divisor)
MonetaryAmount
MonetaryAmount
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 MonetaryAmount
divisor
- value by which this BigDecimal
is to be divided.this / divisor
.BigDecimal.divideToIntegralValue(java.math.BigDecimal)
public DummyAmount scaleByPowerOfTen(int power)
MonetaryAmount
MonetaryAmount
whose numerical value is equal to ( this
*
10n). The scale of the result is (this.scale() - n)
.scaleByPowerOfTen
in interface MonetaryAmount
power
- the power.public DummyAmount abs()
MonetaryAmount
MonetaryAmount
whose value is the absolute value of this
MonetaryAmount
, and whose scale is this.scale()
.abs
in interface MonetaryAmount
abs(this)
public DummyAmount negate()
MonetaryAmount
MonetaryAmount
whose value is (-this)
, and whose scale is
this.scale()
.negate
in interface MonetaryAmount
-this
.public DummyAmount plus()
MonetaryAmount
MonetaryAmount
whose value is (+this)
, with rounding according to
the context settings.plus
in interface MonetaryAmount
this
, rounded as necessary. A zero result will have a scale of 0.BigDecimal.plus()
public DummyAmount stripTrailingZeros()
MonetaryAmount
MonetaryAmount
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 MonetaryAmount
MonetaryAmount
with any trailing zeros removed.public MonetaryAmountFactory<DummyAmount> getFactory()
MonetaryAmount
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
.
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 MonetaryAmount
MonetaryAmountFactory
with the given MonetaryAmount
as its
default values.