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(1234567.3444, "EUR"));
money1 = money1.subtract(Money.of(232323, "EUR"));
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(1234567.3444, "EUR"));
money1 = money1.subtract(FastMoney.of(232323, "EUR"));
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(1234567.3444, "EUR"));
money1 = money1.subtract(FastMoney.of(232323, "EUR"));
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 divisor) |
FastMoney |
divide(long divisor) |
FastMoney |
divide(Number divisor) |
FastMoney[] |
divideAndRemainder(double divisor) |
FastMoney[] |
divideAndRemainder(long divisor) |
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 multiplicand) |
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 |
ofMinor(javax.money.CurrencyUnit currency,
long amountMinor)
Obtains an instance of
FastMoney from an amount in minor units. |
static FastMoney |
ofMinor(javax.money.CurrencyUnit currency,
long amountMinor,
int factionDigits)
Obtains an instance of
FastMoney from an amount in minor units. |
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 divisor) |
FastMoney |
remainder(long divisor) |
FastMoney |
remainder(Number divisor) |
FastMoney |
scaleByPowerOfTen(int power) |
int |
signum() |
FastMoney |
stripTrailingZeros() |
FastMoney |
subtract(javax.money.MonetaryAmount subtrahend) |
String |
toString() |
FastMoney |
with(javax.money.MonetaryOperator operator) |
static FastMoney |
zero(javax.money.CurrencyUnit currency)
Obtains an instance of
FastMoney representing zero. |
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 static FastMoney zero(javax.money.CurrencyUnit currency)
FastMoney representing zero.currency - FastMoney representing zero.public static FastMoney ofMinor(javax.money.CurrencyUnit currency, long amountMinor)
FastMoney from an amount in minor units.
For example, ofMinor(USD, 1234) creates the instance USD 12.34.currency - the currency, not nullamountMinor - the amount of money in the minor division of the currencyNullPointerException - when the currency is nullIllegalArgumentException - when CurrencyUnit.getDefaultFractionDigits() is lesser than zero.CurrencyUnit#getDefaultFractionDigits()},
FastMoney#ofMinor(CurrencyUnit, long, int)}public static FastMoney ofMinor(javax.money.CurrencyUnit currency, long amountMinor, int factionDigits)
FastMoney from an amount in minor units.
For example, ofMinor(USD, 1234, 2) creates the instance USD 12.34.currency - the currency, not nullamountMinor - the amount of money in the minor division of the currencyfactionDigits - number of digitsNullPointerException - when the currency is nullIllegalArgumentException - when the factionDigits is negativeCurrencyUnit#getDefaultFractionDigits()},
FastMoney#ofMinor(CurrencyUnit, long, int)}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 power)
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 representation 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 multiplicand)
multiply in interface javax.money.MonetaryAmountpublic FastMoney divide(long divisor)
divide in interface javax.money.MonetaryAmountpublic FastMoney divide(double divisor)
divide in interface javax.money.MonetaryAmountpublic FastMoney remainder(long divisor)
remainder in interface javax.money.MonetaryAmountpublic FastMoney remainder(double divisor)
remainder in interface javax.money.MonetaryAmountpublic FastMoney[] divideAndRemainder(long divisor)
divideAndRemainder in interface javax.money.MonetaryAmountpublic FastMoney[] divideAndRemainder(double divisor)
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-2016 JavaMoney. All Rights Reserved.