public final class FastMoney extends Object implements javax.money.MonetaryAmount, Comparable<javax.money.MonetaryAmount>, Serializable
long based implementation of MonetaryAmount.This class internally uses a
single long number as numeric representation, which basically is interpreted as minor units.
It suggested to have a performance advantage of a 10-15 times faster compared to Money,
which internally uses BigDecimal. Nevertheless this comes with a price of less precision.
As an example performing the following calculation one million times, results in slightly
different results:
Money money1 = money1.add(Money.of("EUR", 1234567.3444));
money1 = money1.subtract(Money.of("EUR", 232323));
money1 = money1.multiply(3.4);
money1 = money1.divide(5.456);
Executed one million (1000000) times this results in EUR 1657407.962529182, calculated in
3680 ms, or roughly 3ns/loop.
whereas
FastMoney money1 = money1.add(FastMoney.of("EUR", 1234567.3444));
money1 = money1.subtract(FastMoney.of("EUR", 232323));
money1 = money1.multiply(3.4);
money1 = money1.divide(5.456);
executed one million (1000000) times results in EUR 1657407.96251, calculated in 179 ms,
which is less than 1ns/loop.
Also note than mixing up types my drastically change the performance behavior. E.g. replacing the code above with the following: *
FastMoney money1 = money1.add(Money.of("EUR", 1234567.3444));
money1 = money1.subtract(FastMoney.of("EUR", 232323));
money1 = money1.multiply(3.4);
money1 = money1.divide(5.456);
executed one million (1000000) times may execute significantly longer, since monetary amount type conversion is involved.
Basically, when mixing amount implementations, the performance of the amount, on which most of the operations are operated, has the most significant impact on the overall performance behavior.
| Modifier and Type | Field and Description |
|---|---|
static FastMoney |
MAX_VALUE
Maximum possible value supported, using XX (no currency).
|
static FastMoney |
MIN_VALUE
Minimum possible value supported, using XX (no currency).
|
| Modifier and Type | Method and Description |
|---|---|
FastMoney |
abs() |
FastMoney |
add(javax.money.MonetaryAmount amount) |
protected void |
checkNumber(Number number)
Internal method to check for correct number parameter.
|
int |
compareTo(javax.money.MonetaryAmount o) |
FastMoney |
divide(double number) |
FastMoney |
divide(long amount) |
FastMoney |
divide(Number divisor) |
FastMoney[] |
divideAndRemainder(double amount) |
FastMoney[] |
divideAndRemainder(long amount) |
FastMoney[] |
divideAndRemainder(Number divisor) |
FastMoney |
divideToIntegralValue(double divisor) |
FastMoney |
divideToIntegralValue(long divisor) |
FastMoney |
divideToIntegralValue(Number divisor) |
boolean |
equals(Object obj) |
static FastMoney |
from(javax.money.MonetaryAmount amount) |
javax.money.MonetaryContext |
getContext()
Access the
MonetaryContext used by this instance. |
javax.money.CurrencyUnit |
getCurrency()
Returns the amount’s currency, modelled as
CurrencyUnit. |
javax.money.MonetaryAmountFactory<FastMoney> |
getFactory() |
javax.money.NumberValue |
getNumber()
Gets the number representation of the numeric value of this item.
|
int |
getPrecision() |
int |
getScale() |
int |
hashCode() |
boolean |
hasSameNumberAs(Number number) |
boolean |
isEqualTo(javax.money.MonetaryAmount amount) |
boolean |
isGreaterThan(javax.money.MonetaryAmount amount) |
boolean |
isGreaterThan(Number number) |
boolean |
isGreaterThanOrEqualTo(javax.money.MonetaryAmount amount) |
boolean |
isGreaterThanOrEqualTo(Number number) |
boolean |
isLessThan(javax.money.MonetaryAmount amount) |
boolean |
isLessThan(Number number) |
boolean |
isLessThanOrEqualTo(javax.money.MonetaryAmount amount) |
boolean |
isLessThanOrEqualTo(Number number) |
boolean |
isNegative() |
boolean |
isNegativeOrZero() |
boolean |
isPositive() |
boolean |
isPositiveOrZero() |
boolean |
isZero() |
FastMoney |
multiply(double amount) |
FastMoney |
multiply(long multiplicand) |
FastMoney |
multiply(Number multiplicand) |
FastMoney |
negate() |
static FastMoney |
of(Number number,
javax.money.CurrencyUnit currency)
Static factory method for creating a new instance of
FastMoney. |
static FastMoney |
of(Number number,
String currencyCode)
Static factory method for creating a new instance of
FastMoney. |
static FastMoney |
of(javax.money.NumberValue numberBinding,
javax.money.CurrencyUnit currency)
Static factory method for creating a new instance of
FastMoney. |
static FastMoney |
parse(CharSequence text)
Obtains an instance of FastMoney from a text string such as 'EUR 25.25'.
|
static FastMoney |
parse(CharSequence text,
javax.money.format.MonetaryAmountFormat formatter)
Obtains an instance of FastMoney from a text using specific formatter.
|
FastMoney |
plus() |
<R> R |
query(javax.money.MonetaryQuery<R> query) |
FastMoney |
remainder(double amount) |
FastMoney |
remainder(long number) |
FastMoney |
remainder(Number divisor) |
FastMoney |
scaleByPowerOfTen(int n) |
int |
signum() |
FastMoney |
stripTrailingZeros() |
FastMoney |
subtract(javax.money.MonetaryAmount subtrahend) |
String |
toString() |
FastMoney |
with(javax.money.MonetaryOperator operator) |
public static final FastMoney MAX_VALUE
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.CurrencySuppliernullCurrencySupplier.getCurrency()public javax.money.MonetaryContext getContext()
MonetaryContext used by this instance.getContext in interface javax.money.MonetaryAmountMonetaryContext used, never null.MonetaryAmount.getContext()public static FastMoney of(javax.money.NumberValue numberBinding, javax.money.CurrencyUnit currency)
FastMoney.currency - The target currency, not null.numberBinding - The numeric part, not null.FastMoney.public static FastMoney of(Number number, javax.money.CurrencyUnit currency)
FastMoney.currency - The target currency, not null.number - The numeric part, not null.FastMoney.public static FastMoney of(Number number, String currencyCode)
FastMoney.currencyCode - The target currency as currency code.number - The numeric part, not null.FastMoney.public int compareTo(javax.money.MonetaryAmount o)
compareTo in interface Comparable<javax.money.MonetaryAmount>public FastMoney add(javax.money.MonetaryAmount amount)
add in interface javax.money.MonetaryAmountpublic FastMoney divide(Number divisor)
divide in interface javax.money.MonetaryAmountpublic FastMoney[] divideAndRemainder(Number divisor)
divideAndRemainder in interface javax.money.MonetaryAmountpublic FastMoney divideToIntegralValue(Number divisor)
divideToIntegralValue in interface javax.money.MonetaryAmountpublic FastMoney multiply(Number multiplicand)
multiply in interface javax.money.MonetaryAmountpublic FastMoney subtract(javax.money.MonetaryAmount subtrahend)
subtract in interface javax.money.MonetaryAmountpublic FastMoney remainder(Number divisor)
remainder in interface javax.money.MonetaryAmountpublic FastMoney scaleByPowerOfTen(int n)
scaleByPowerOfTen in interface javax.money.MonetaryAmountpublic boolean isZero()
isZero in interface javax.money.MonetaryAmountpublic boolean isPositive()
isPositive in interface javax.money.MonetaryAmountpublic boolean isPositiveOrZero()
isPositiveOrZero in interface javax.money.MonetaryAmountpublic boolean isNegative()
isNegative in interface javax.money.MonetaryAmountpublic boolean isNegativeOrZero()
isNegativeOrZero in interface javax.money.MonetaryAmountpublic int getScale()
public int getPrecision()
public int signum()
signum in interface javax.money.MonetaryAmountpublic boolean isLessThan(javax.money.MonetaryAmount amount)
isLessThan in interface javax.money.MonetaryAmountpublic boolean isLessThan(Number number)
public boolean isLessThanOrEqualTo(javax.money.MonetaryAmount amount)
isLessThanOrEqualTo in interface javax.money.MonetaryAmountpublic boolean isLessThanOrEqualTo(Number number)
public boolean isGreaterThan(javax.money.MonetaryAmount amount)
isGreaterThan in interface javax.money.MonetaryAmountpublic boolean isGreaterThan(Number number)
public boolean isGreaterThanOrEqualTo(javax.money.MonetaryAmount amount)
isGreaterThanOrEqualTo in interface javax.money.MonetaryAmountpublic boolean isGreaterThanOrEqualTo(Number number)
public boolean isEqualTo(javax.money.MonetaryAmount amount)
isEqualTo in interface javax.money.MonetaryAmountpublic boolean hasSameNumberAs(Number number)
public javax.money.NumberValue getNumber()
getNumber in interface javax.money.NumberSupplierNumber represention matching best.protected void checkNumber(Number number)
number - the number to be checked, including null..NullPointerException - If the number is nullArithmeticException - If the number exceeds the capabilities of this class.public FastMoney with(javax.money.MonetaryOperator operator)
with in interface javax.money.MonetaryAmountpublic <R> R query(javax.money.MonetaryQuery<R> query)
query in interface javax.money.MonetaryAmountpublic static FastMoney parse(CharSequence text)
text - the text to parse not nullNullPointerExceptionNumberFormatExceptionjavax.money.UnknownCurrencyExceptionpublic static FastMoney parse(CharSequence text, javax.money.format.MonetaryAmountFormat formatter)
text - the text to parse not nullformatter - the formatter to use not nullpublic FastMoney multiply(double amount)
multiply in interface javax.money.MonetaryAmountpublic FastMoney divide(long amount)
divide in interface javax.money.MonetaryAmountpublic FastMoney divide(double number)
divide in interface javax.money.MonetaryAmountpublic FastMoney remainder(long number)
remainder in interface javax.money.MonetaryAmountpublic FastMoney remainder(double amount)
remainder in interface javax.money.MonetaryAmountpublic FastMoney[] divideAndRemainder(long amount)
divideAndRemainder in interface javax.money.MonetaryAmountpublic FastMoney[] divideAndRemainder(double amount)
divideAndRemainder in interface javax.money.MonetaryAmountpublic FastMoney stripTrailingZeros()
stripTrailingZeros in interface javax.money.MonetaryAmountpublic FastMoney multiply(long multiplicand)
multiply in interface javax.money.MonetaryAmountpublic FastMoney divideToIntegralValue(long divisor)
divideToIntegralValue in interface javax.money.MonetaryAmountpublic FastMoney divideToIntegralValue(double divisor)
divideToIntegralValue in interface javax.money.MonetaryAmountpublic javax.money.MonetaryAmountFactory<FastMoney> getFactory()
getFactory in interface javax.money.MonetaryAmountCopyright © 2012-2015 JavaMoney. All Rights Reserved.