public final class FastMoney extends AbstractMoney implements Comparable<javax.money.MonetaryAmount>, Serializable
MonetaryAmount. This class internally uses a
single long number as numeric representation, which basically is interpreted as minor units.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(EURO, 1234567.3444)); money1 = money1.subtract(Money.of(EURO, 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.
whrereas
FastMoney money1 = money1.add(FastMoney.of(EURO, 1234567.3444)); money1 = money1.subtract(FastMoney.of(EURO, 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(EURO, 1234567.3444)); money1 = money1.subtract(FastMoney.of(EURO, 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.
currency, monetaryContext| Modifier and Type | Method and Description |
|---|---|
FastMoney |
abs() |
FastMoney |
add(javax.money.MonetaryAmount amount) |
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.CurrencyUnit |
getCurrency()
Returns the amount’s currency, modelled as
CurrencyUnit. |
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<FastMoney> |
getFactory() |
javax.money.MonetaryContext |
getMonetaryContext()
Access the
MonetaryContext used by this instance. |
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 |
isNotEqualTo(javax.money.MonetaryAmount amount) |
boolean |
isNotEqualTo(Number number) |
boolean |
isPositive() |
boolean |
isPositiveOrZero() |
boolean |
isZero() |
FastMoney |
multiply(double amount) |
FastMoney |
multiply(long multiplicand) |
FastMoney |
multiply(Number multiplicand) |
FastMoney |
negate() |
static FastMoney |
of(javax.money.CurrencyUnit currency,
Number number)
Static factory method for creating a new instance of
FastMoney. |
static FastMoney |
of(javax.money.CurrencyUnit currency,
javax.money.NumberValue numberBinding)
Static factory method for creating a new instance of
FastMoney. |
static FastMoney |
of(String currencyCode,
Number number)
Static factory method for creating a new instance of
FastMoney. |
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) |
checkAmountParameter, checkNumberParameter, getBigDecimal, getBigDecimal, getBigDecimal, getBigDecimal, getMathContextpublic static FastMoney of(javax.money.CurrencyUnit currency, javax.money.NumberValue numberBinding)
FastMoney.currency - The target currency, not null.numberBinding - The numeric part, not null.FastMoney.public static FastMoney of(javax.money.CurrencyUnit currency, Number number)
FastMoney.currency - The target currency, not null.number - The numeric part, not null.FastMoney.public static FastMoney of(String currencyCode, Number number)
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 javax.money.CurrencyUnit getCurrency()
AbstractMoneyCurrencyUnit.
Implementations may co-variantly change the return type to a more
specific implementation of CurrencyUnit if desired.getCurrency in interface javax.money.CurrencySuppliergetCurrency in interface javax.money.MonetaryAmountgetCurrency in class AbstractMoneynullMonetaryAmount.getCurrency()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 boolean isNotEqualTo(javax.money.MonetaryAmount amount)
public boolean isNotEqualTo(Number number)
public javax.money.NumberValue getNumber()
getNumber in interface javax.money.MonetaryAmountgetNumber in interface javax.money.NumberSupplierNumber represention matching best.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 javax.money.MonetaryContext getMonetaryContext()
AbstractMoneyMonetaryContext used by this instance.getMonetaryContext in interface javax.money.MonetaryAmountgetMonetaryContext in class AbstractMoneyMonetaryContext used, never null.MonetaryAmount.getMonetaryContext()public 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.MonetaryAmountprotected javax.money.MonetaryContext getDefaultMonetaryContext()
AbstractMoneyMonetaryContext, when not explicit MonetaryContext is
available.getDefaultMonetaryContext in class AbstractMoneyMonetaryContext, never null.public javax.money.MonetaryAmountFactory<FastMoney> getFactory()
getFactory in interface javax.money.MonetaryAmountCopyright © 2012-2014 JavaMoney. All Rights Reserved.