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()
MonetaryAmountCurrencyUnit. Implementations may
co-variantly change the return type to a more specific implementation of CurrencyUnit
if desired.getCurrency in interface CurrencySuppliergetCurrency in interface MonetaryAmountnullpublic MonetaryContext getMonetaryContext()
MonetaryAmountMonetaryContext 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 MonetaryAmountMonetaryContext of this MonetaryAmount, never null .public NumberValue getNumber()
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 MonetaryAmountgetNumber in interface NumberSupplierMonetaryAmount, never null.public <R> R query(MonetaryQuery<R> query)
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 MonetaryAmountR - the type of the resultquery - the query to invoke, not nullpublic DummyAmount with(MonetaryOperator operator)
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 MonetaryAmountoperator - the operator to use, not nullpublic boolean isGreaterThan(MonetaryAmount amount)
MonetaryAmountMonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities.isGreaterThan in interface MonetaryAmountamount - the MonetaryAmount to be compared with this instance.true if amount > this.public boolean isGreaterThanOrEqualTo(MonetaryAmount amt)
MonetaryAmountMonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities.isGreaterThanOrEqualTo in interface MonetaryAmountamt - the MonetaryAmount to be compared with this instance.true if amount >= this.public boolean isLessThan(MonetaryAmount amt)
MonetaryAmountMonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities.isLessThan in interface MonetaryAmountamt - the MonetaryAmount to be compared with this instance.true if amount < this.public boolean isLessThanOrEqualTo(MonetaryAmount amt)
MonetaryAmountMonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities.isLessThanOrEqualTo in interface MonetaryAmountamt - the MonetaryAmount to be compared with this instance.true if amount <= this.public boolean isEqualTo(MonetaryAmount amount)
MonetaryAmountMonetaryAmount, hereby ignoring non significant trailing
zeroes and different numeric capabilities.isEqualTo in interface MonetaryAmountamount - the MonetaryAmount to be compared with this instance.true if amount == this.public boolean isNegative()
MonetaryAmountMonetaryAmount is negative.isNegative in interface MonetaryAmounttrue if MonetaryAmount.signum() < 0.public boolean isNegativeOrZero()
MonetaryAmountMonetaryAmount is negative or zero.isNegativeOrZero in interface MonetaryAmounttrue if MonetaryAmount.signum() <= 0.public boolean isPositive()
MonetaryAmountMonetaryAmount is positive.isPositive in interface MonetaryAmounttrue if MonetaryAmount.signum() > 0.public boolean isPositiveOrZero()
MonetaryAmountMonetaryAmount is positive or zero.isPositiveOrZero in interface MonetaryAmounttrue if MonetaryAmount.signum() >= 0.public boolean isZero()
MonetaryAmountMonetaryAmount is zero.isZero in interface MonetaryAmounttrue if MonetaryAmount.signum() == 0.public int signum()
MonetaryAmountMonetaryAmount.signum in interface MonetaryAmountMonetaryAmount is negative, zero, or
positive.public DummyAmount add(MonetaryAmount amount)
MonetaryAmountMonetaryAmount whose value is (this +
amount), and whose scale is max(this.scale(),
amount.scale()).add in interface MonetaryAmountamount - value to be added to this MonetaryAmount.this + amountpublic DummyAmount subtract(MonetaryAmount amount)
MonetaryAmountMonetaryAmount whose value is (this -
amount), and whose scale is max(this.scale(),
subtrahend.scale()).subtract in interface MonetaryAmountamount - value to be subtracted from this MonetaryAmount.this - amountpublic DummyAmount multiply(long multiplicand)
MonetaryAmountMonetaryAmount whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale()).multiply in interface MonetaryAmountmultiplicand - value to be multiplied by this MonetaryAmount.this * multiplicandpublic DummyAmount multiply(double multiplicand)
MonetaryAmountMonetaryAmount whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale()).multiply in interface MonetaryAmountmultiplicand - value to be multiplied by this MonetaryAmount.this * multiplicandpublic DummyAmount multiply(java.lang.Number multiplicand)
MonetaryAmountMonetaryAmount whose value is (this ×
multiplicand), and whose scale is (this.scale() +
multiplicand.scale()).multiply in interface MonetaryAmountmultiplicand - value to be multiplied by this MonetaryAmount.this * multiplicandpublic DummyAmount divide(long amount)
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 MonetaryAmountamount - value by which this MonetaryAmount is to be divided.this / divisorpublic DummyAmount divide(double amount)
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 MonetaryAmountamount - value by which this MonetaryAmount is to be divided.this / divisorpublic DummyAmount divide(java.lang.Number amount)
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 MonetaryAmountamount - value by which this MonetaryAmount is to be divided.this / divisorpublic DummyAmount remainder(long amount)
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 MonetaryAmountamount - value by which this MonetaryAmount is to be divided.this % divisor.public DummyAmount remainder(double amount)
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 MonetaryAmountamount - value by which this MonetaryAmount is to be divided.this % divisor.public DummyAmount remainder(java.lang.Number amount)
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 MonetaryAmountamount - value by which this MonetaryAmount is to be divided.this % divisor.public DummyAmount[] divideAndRemainder(long amount)
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 MonetaryAmountamount - 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)
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 MonetaryAmountamount - 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)
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 MonetaryAmountamount - 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)
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 MonetaryAmountdivisor - value by which this BigDecimal is to be divided.this / divisor.BigDecimal.divideToIntegralValue(java.math.BigDecimal)public DummyAmount divideToIntegralValue(double divisor)
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 MonetaryAmountdivisor - value by which this BigDecimal is to be divided.this / divisor.BigDecimal.divideToIntegralValue(java.math.BigDecimal)public DummyAmount divideToIntegralValue(java.lang.Number divisor)
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 MonetaryAmountdivisor - value by which this BigDecimal is to be divided.this / divisor.BigDecimal.divideToIntegralValue(java.math.BigDecimal)public DummyAmount scaleByPowerOfTen(int power)
MonetaryAmountMonetaryAmount whose numerical value is equal to ( this *
10n). The scale of the result is (this.scale() - n).scaleByPowerOfTen in interface MonetaryAmountpower - the power.public DummyAmount abs()
MonetaryAmountMonetaryAmount whose value is the absolute value of this
MonetaryAmount, and whose scale is this.scale().abs in interface MonetaryAmountabs(this)public DummyAmount negate()
MonetaryAmountMonetaryAmount whose value is (-this), and whose scale is
this.scale().negate in interface MonetaryAmount-this.public DummyAmount plus()
MonetaryAmountMonetaryAmount whose value is (+this), with rounding according to
the context settings.plus in interface MonetaryAmountthis, rounded as necessary. A zero result will have a scale of 0.BigDecimal.plus()public DummyAmount stripTrailingZeros()
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 MonetaryAmountMonetaryAmount with any trailing zeros removed.public MonetaryAmountFactory<DummyAmount> getFactory()
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 MonetaryAmountMonetaryAmountFactory with the given MonetaryAmount as its
default values.