public final class FastMoney extends Object implements javax.money.MonetaryAmount, Comparable<FastMoney>, Serializable
MonetaryAmount
. This class
internally uses a single long number as numeric reporesentation, which
basically is interpreted as minor units.Money
, which interally uses BigDecimal
. Nevertheless this
comes with a price of less precision. As an example performing the following
calulcation one milltion 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 mixxing up types my drastically change the performance behaviour. 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.
Modifier and Type | Method and Description |
---|---|
FastMoney |
abs() |
FastMoney |
add(javax.money.MonetaryAmount amount) |
Number |
asNumber()
Gets the number representation of the numeric value of this item.
|
<T> T |
asType(Class<T> type) |
void |
checkNumber(Number number)
Internal method to check for correct number parameter.
|
int |
compareTo(FastMoney o) |
FastMoney |
divide(javax.money.MonetaryAmount divisor) |
FastMoney |
divide(Number divisor) |
FastMoney[] |
divideAndRemainder(javax.money.MonetaryAmount divisor) |
FastMoney[] |
divideAndRemainder(Number divisor) |
FastMoney |
divideToIntegralValue(javax.money.MonetaryAmount divisor) |
FastMoney |
divideToIntegralValue(Number divisor) |
double |
doubleValue() |
boolean |
equals(Object obj) |
static FastMoney |
from(javax.money.MonetaryAmount amount) |
long |
getAmountFractionDenominator() |
long |
getAmountFractionNumerator() |
long |
getAmountWhole() |
javax.money.CurrencyUnit |
getCurrency() |
static Class<?> |
getNumberClass()
Get the number represnetation type, E.g.
|
Class<?> |
getNumberType() |
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() |
long |
longValue() |
long |
longValueExact() |
FastMoney |
multiply(javax.money.MonetaryAmount multiplicand) |
FastMoney |
multiply(Number multiplicand) |
FastMoney |
negate() |
static FastMoney |
of(javax.money.CurrencyUnit currency,
BigDecimal number)
Translates a
BigDecimal value and a CurrencyUnit currency
into a Money . |
static FastMoney |
of(javax.money.CurrencyUnit currency,
Number number)
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() |
FastMoney |
pow(int n) |
<R> R |
query(javax.money.MonetaryQuery<R> query) |
FastMoney |
remainder(javax.money.MonetaryAmount divisor) |
FastMoney |
remainder(Number divisor) |
FastMoney |
scaleByPowerOfTen(int n) |
int |
signum() |
FastMoney |
subtract(javax.money.MonetaryAmount subtrahend) |
String |
toEngineeringString() |
String |
toPlainString() |
String |
toString() |
FastMoney |
ulp() |
javax.money.MonetaryAmount |
with(javax.money.MonetaryAdjuster adjuster) |
FastMoney |
with(Number number) |
static javax.money.MonetaryAmount |
zero(javax.money.CurrencyUnit currency)
Facory method creating a zero instance with the given {@code currency);
|
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 static javax.money.MonetaryAmount zero(javax.money.CurrencyUnit currency)
currency
- the target currency of the amount being created.public static Class<?> getNumberClass()
java.math.BigDecimal
.public int compareTo(FastMoney o)
compareTo
in interface Comparable<FastMoney>
public javax.money.CurrencyUnit getCurrency()
getCurrency
in interface javax.money.MonetaryAmount
public FastMoney[] divideAndRemainder(javax.money.MonetaryAmount divisor)
public FastMoney[] divideAndRemainder(Number divisor)
public FastMoney divideToIntegralValue(javax.money.MonetaryAmount divisor)
public FastMoney divideToIntegralValue(Number divisor)
public FastMoney scaleByPowerOfTen(int n)
public boolean isZero()
public boolean isPositive()
public boolean isPositiveOrZero()
public boolean isNegative()
public boolean isNegativeOrZero()
public int getScale()
public int getPrecision()
public long longValue()
public long longValueExact()
public double doubleValue()
public int signum()
public String toEngineeringString()
public String toPlainString()
public boolean isLessThan(javax.money.MonetaryAmount amount)
public boolean isLessThan(Number number)
public boolean isLessThanOrEqualTo(javax.money.MonetaryAmount amount)
public boolean isLessThanOrEqualTo(Number number)
public boolean isGreaterThan(javax.money.MonetaryAmount amount)
public boolean isGreaterThan(Number number)
public boolean isGreaterThanOrEqualTo(javax.money.MonetaryAmount amount)
public boolean isGreaterThanOrEqualTo(Number number)
public boolean isEqualTo(javax.money.MonetaryAmount amount)
public boolean hasSameNumberAs(Number number)
public boolean isNotEqualTo(javax.money.MonetaryAmount amount)
public boolean isNotEqualTo(Number number)
public Class<?> getNumberType()
public Number asNumber()
Number
represention matching best.public static FastMoney of(javax.money.CurrencyUnit currency, BigDecimal number)
BigDecimal
value and a CurrencyUnit
currency
into a Money
.number
- numeric value of the Money
.currency
- currency unit of the Money
.Money
combining the numeric value and currency unit.public void checkNumber(Number number)
number
- IllegalArgumentException
- If the number is nullpublic javax.money.MonetaryAmount with(javax.money.MonetaryAdjuster adjuster)
with
in interface javax.money.MonetaryAmount
public <R> R query(javax.money.MonetaryQuery<R> query)
query
in interface javax.money.MonetaryAmount
public long getAmountWhole()
getAmountWhole
in interface javax.money.MonetaryAmount
public long getAmountFractionNumerator()
getAmountFractionNumerator
in interface javax.money.MonetaryAmount
public long getAmountFractionDenominator()
getAmountFractionDenominator
in interface javax.money.MonetaryAmount
Copyright © 2012–2013 JSR 354 - Expert Group. All rights reserved.