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) |
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 |
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) |
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.CurrencySupplier
null
CurrencySupplier.getCurrency()
public javax.money.MonetaryContext getContext()
MonetaryContext
used by this instance.getContext
in interface javax.money.MonetaryAmount
MonetaryContext
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.MonetaryAmount
public FastMoney divide(Number divisor)
divide
in interface javax.money.MonetaryAmount
public FastMoney[] divideAndRemainder(Number divisor)
divideAndRemainder
in interface javax.money.MonetaryAmount
public FastMoney divideToIntegralValue(Number divisor)
divideToIntegralValue
in interface javax.money.MonetaryAmount
public FastMoney multiply(Number multiplicand)
multiply
in interface javax.money.MonetaryAmount
public FastMoney subtract(javax.money.MonetaryAmount subtrahend)
subtract
in interface javax.money.MonetaryAmount
public FastMoney remainder(Number divisor)
remainder
in interface javax.money.MonetaryAmount
public FastMoney scaleByPowerOfTen(int power)
scaleByPowerOfTen
in interface javax.money.MonetaryAmount
public boolean isZero()
isZero
in interface javax.money.MonetaryAmount
public boolean isPositive()
isPositive
in interface javax.money.MonetaryAmount
public boolean isPositiveOrZero()
isPositiveOrZero
in interface javax.money.MonetaryAmount
public boolean isNegative()
isNegative
in interface javax.money.MonetaryAmount
public boolean isNegativeOrZero()
isNegativeOrZero
in interface javax.money.MonetaryAmount
public int getScale()
public int getPrecision()
public int signum()
signum
in interface javax.money.MonetaryAmount
public boolean isLessThan(javax.money.MonetaryAmount amount)
isLessThan
in interface javax.money.MonetaryAmount
public boolean isLessThan(Number number)
public boolean isLessThanOrEqualTo(javax.money.MonetaryAmount amount)
isLessThanOrEqualTo
in interface javax.money.MonetaryAmount
public boolean isLessThanOrEqualTo(Number number)
public boolean isGreaterThan(javax.money.MonetaryAmount amount)
isGreaterThan
in interface javax.money.MonetaryAmount
public boolean isGreaterThan(Number number)
public boolean isGreaterThanOrEqualTo(javax.money.MonetaryAmount amount)
isGreaterThanOrEqualTo
in interface javax.money.MonetaryAmount
public boolean isGreaterThanOrEqualTo(Number number)
public boolean isEqualTo(javax.money.MonetaryAmount amount)
isEqualTo
in interface javax.money.MonetaryAmount
public boolean hasSameNumberAs(Number number)
public javax.money.NumberValue getNumber()
getNumber
in interface javax.money.NumberSupplier
Number
representation matching best.public FastMoney with(javax.money.MonetaryOperator operator)
with
in interface javax.money.MonetaryAmount
public <R> R query(javax.money.MonetaryQuery<R> query)
query
in interface javax.money.MonetaryAmount
public static FastMoney parse(CharSequence text)
text
- the text to parse not nullNullPointerException
NumberFormatException
javax.money.UnknownCurrencyException
public 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.MonetaryAmount
public FastMoney divide(long divisor)
divide
in interface javax.money.MonetaryAmount
public FastMoney divide(double divisor)
divide
in interface javax.money.MonetaryAmount
public FastMoney remainder(long divisor)
remainder
in interface javax.money.MonetaryAmount
public FastMoney remainder(double divisor)
remainder
in interface javax.money.MonetaryAmount
public FastMoney[] divideAndRemainder(long divisor)
divideAndRemainder
in interface javax.money.MonetaryAmount
public FastMoney[] divideAndRemainder(double divisor)
divideAndRemainder
in interface javax.money.MonetaryAmount
public FastMoney stripTrailingZeros()
stripTrailingZeros
in interface javax.money.MonetaryAmount
public FastMoney multiply(long multiplicand)
multiply
in interface javax.money.MonetaryAmount
public FastMoney divideToIntegralValue(long divisor)
divideToIntegralValue
in interface javax.money.MonetaryAmount
public FastMoney divideToIntegralValue(double divisor)
divideToIntegralValue
in interface javax.money.MonetaryAmount
public javax.money.MonetaryAmountFactory<FastMoney> getFactory()
getFactory
in interface javax.money.MonetaryAmount
Copyright © 2012-2015 JavaMoney. All Rights Reserved.