public class BigMoney extends Object implements FxConvertible<BigMoney>, Comparable<BigMoney>, Serializable
This class is similar to Money, but permits any number of decimal places.
The amount will always have at least the number of decimal places of the currency.
Trailing zeroes are stripped.
This class is immutable and thread-safe.
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(BigMoney other)
Compares this money to another.
|
BigMoney |
convertedTo(Currency resultCurrency,
BigDecimal fxRate)
Converts this amount to an equivalent amount the specified currency.
|
BigMoney |
convertedTo(Currency resultCurrency,
Decimal fxRate)
Converts this amount to an equivalent amount the specified currency.
|
BigMoney |
convertedTo(Currency resultCurrency,
FxRateProvider rateProvider)
Converts this amount to an equivalent amount in the specified currency.
|
boolean |
equals(Object obj)
Checks if this money equals another.
|
BigDecimal |
getAmount()
Deprecated.
Use
getValue() |
Currency |
getCurrency()
Gets the currency.
|
Decimal |
getValue()
Gets the numeric amount of the money.
|
int |
hashCode()
Returns a suitable hash code for the currency.
|
boolean |
isGreaterThan(BigMoney otherAmount)
Checks if this amount is greater than the other amount.
|
boolean |
isGreaterThanEqualTo(BigMoney otherAmount)
Checks if this amount is greater than or equal to the other amount.
|
boolean |
isLessThan(BigMoney otherAmount)
Checks if this amount is less than the other amount.
|
boolean |
isLessThanEqualTo(BigMoney otherAmount)
Checks if this amount is less than or equal to the other amount.
|
boolean |
isNegative()
Checks if the amount is negative.
|
boolean |
isPositive()
Checks if the amount is positive.
|
boolean |
isZero()
Checks if the amount is zero.
|
BigMoney |
map(UnaryOperator<Decimal> mapper)
Applies an operation to the amount.
|
BigMoney |
mapAmount(UnaryOperator<BigDecimal> mapper)
Deprecated.
Use
map(UnaryOperator), potentially using a lambda decimal -> decimal.mapAsBigDecimal(mapper) |
BigMoney |
minus(BigMoney amountToSubtract)
Returns a copy of this
BigMoney with the specified amount subtracted. |
BigMoney |
multipliedBy(long valueToMultiplyBy)
Returns a copy of this
BigMoney with the amount multiplied. |
BigMoney |
negated()
Returns a copy of this
BigMoney with the amount negated. |
BigMoney |
negative()
Returns a copy of this
BigMoney with a negative amount. |
static BigMoney |
of(CurrencyAmount currencyAmount)
Obtains an instance of
BigMoney for the specified CurrencyAmount. |
static BigMoney |
of(Currency currency,
BigDecimal amount)
Obtains an instance of
BigMoney for the specified currency and amount. |
static BigMoney |
of(Currency currency,
Decimal amount)
Obtains an instance of
BigMoney for the specified currency and amount. |
static BigMoney |
of(Currency currency,
double amount)
Obtains an instance of
BigMoney for the specified currency and amount. |
static BigMoney |
of(Money money)
Obtains an instance of
BigMoney for the specified Money. |
static BigMoney |
parse(String amountStr)
Parses the string to produce a
BigMoney. |
BigMoney |
plus(BigMoney amountToAdd)
Returns a copy of this
BigMoney with the specified amount added. |
BigMoney |
positive()
Returns a copy of this
BigMoney with a positive amount. |
BigMoney |
roundToScale(int desiredScale,
RoundingMode roundingMode)
Returns a copy of this
BigMoney with the amount rounded to the specified scale. |
CurrencyAmount |
toCurrencyAmount()
Converts this monetary amount to the equivalent
CurrencyAmount. |
Money |
toMoney()
Converts this monetary amount to the equivalent
Money. |
String |
toString()
Gets the amount as a string.
|
static BigMoney |
zero(Currency currency)
Obtains a zero amount instance of
BigMoney for the specified currency. |
public static BigMoney zero(Currency currency)
BigMoney for the specified currency.currency - the currency the amount is inpublic static BigMoney of(CurrencyAmount currencyAmount)
BigMoney for the specified CurrencyAmount.currencyAmount - the instance of CurrencyAmount wrapping the currency and amount.public static BigMoney of(Money money)
BigMoney for the specified Money.money - the instance of Money wrapping the currency and amount.public static BigMoney of(Currency currency, double amount)
BigMoney for the specified currency and amount.currency - the currency the amount is inamount - the amount of the currency to representpublic static BigMoney of(Currency currency, BigDecimal amount)
BigMoney for the specified currency and amount.currency - the currency the amount is inamount - the amount of the currency to represent, as an instance of BigDecimalpublic static BigMoney of(Currency currency, Decimal amount)
BigMoney for the specified currency and amount.currency - the currency the amount is inamount - the amount of the currency to represent, as an instance of Decimalpublic static BigMoney parse(String amountStr)
BigMoney.
This parses the toString format of '${currency} ${amount}'.
amountStr - the amount stringIllegalArgumentException - if the amount cannot be parsedpublic Currency getCurrency()
For example, in the value 'GBP 12.34' the currency is 'GBP'.
@Deprecated public BigDecimal getAmount()
getValue()BigDecimal.
For example, in the amount 'GBP 12.345' the decimal value returned is '12.345'.
public Decimal getValue()
For example, in the amount 'GBP 12.345' the decimal value returned is '12.345'.
public BigMoney plus(BigMoney amountToAdd)
BigMoney with the specified amount added.
This adds the specified amount to this monetary amount, returning a new object.
This instance is immutable and unaffected by this method.
amountToAdd - the amount to add, in the same currencyIllegalArgumentException - if the currencies are not equalpublic BigMoney minus(BigMoney amountToSubtract)
BigMoney with the specified amount subtracted.
This subtracts the specified amount to this monetary amount, returning a new object.
This instance is immutable and unaffected by this method.
amountToSubtract - the amount to subtract, in the same currencyIllegalArgumentException - if the currencies are not equalpublic BigMoney multipliedBy(long valueToMultiplyBy)
BigMoney with the amount multiplied.
This takes this amount and multiplies it by the specified value.
This instance is immutable and unaffected by this method.
valueToMultiplyBy - the scalar amount to multiply bypublic BigMoney map(UnaryOperator<Decimal> mapper)
This is generally used to apply a mathematical operation to the amount. For example, the operator could multiply the amount by a constant, or take the inverse.
abs = base.mapAmount(value -> value.abs());
mapper - the operator to be applied to the amount@Deprecated public BigMoney mapAmount(UnaryOperator<BigDecimal> mapper)
map(UnaryOperator), potentially using a lambda decimal -> decimal.mapAsBigDecimal(mapper)This is generally used to apply a mathematical operation to the amount. For example, the operator could multiply the amount by a constant, or take the inverse.
abs = base.mapAmount(value -> value.abs());
mapper - the operator to be applied to the amountpublic boolean isGreaterThan(BigMoney otherAmount)
otherAmount - the other amountIllegalArgumentException - if the currencies are not equalpublic boolean isGreaterThanEqualTo(BigMoney otherAmount)
otherAmount - the other amountIllegalArgumentException - if the currencies are not equalpublic boolean isLessThan(BigMoney otherAmount)
otherAmount - the other amountIllegalArgumentException - if the currencies are not equalpublic boolean isLessThanEqualTo(BigMoney otherAmount)
otherAmount - the other amountIllegalArgumentException - if the currencies are not equalpublic BigMoney roundToScale(int desiredScale, RoundingMode roundingMode)
BigMoney with the amount rounded to the specified scale.
The underlying amount will be rounded using Decimal.roundToScale(int, RoundingMode)
This instance is immutable and unaffected by this method.
desiredScale - the scale, positive for decimal places, negative to round the integer-partroundingMode - the rounding modeIllegalArgumentException - if the scale is -18 or lesspublic boolean isZero()
public boolean isPositive()
Zero and negative amounts return false.
public boolean isNegative()
Zero and positive amounts return false.
public BigMoney negated()
BigMoney with the amount negated.
This takes this amount and negates it.
This instance is immutable and unaffected by this method.
public BigMoney positive()
BigMoney with a positive amount.
The result of this method will always be positive, where the amount is equal to abs(amount).
This instance is immutable and unaffected by this method.
public BigMoney negative()
BigMoney with a negative amount.
The result of this method will always be negative, equal to -.abs(amount).
This instance is immutable and unaffected by this method.
public CurrencyAmount toCurrencyAmount()
CurrencyAmount.CurrencyAmountpublic Money toMoney()
Money.Moneypublic BigMoney convertedTo(Currency resultCurrency, BigDecimal fxRate)
The result will be expressed in terms of the given currency, converting using the specified FX rate.
For example, if this represents 'GBP 100' and this method is called with
arguments (USD, 1.6) then the result will be 'USD 160'.
resultCurrency - the currency of the resultfxRate - the FX rate from this currency to the result currencyIllegalArgumentException - if the FX is not 1 when no conversion is requiredpublic BigMoney convertedTo(Currency resultCurrency, Decimal fxRate)
The result will be expressed in terms of the given currency, converting using the specified FX rate.
For example, if this represents 'GBP 100' and this method is called with
arguments (USD, 1.6) then the result will be 'USD 160'.
resultCurrency - the currency of the resultfxRate - the FX rate from this currency to the result currencyIllegalArgumentException - if the FX is not 1 when no conversion is requiredpublic BigMoney convertedTo(Currency resultCurrency, FxRateProvider rateProvider)
The result will be expressed in terms of the given currency. If conversion is needed, the provider will be used to supply the FX rate.
convertedTo in interface FxConvertible<BigMoney>resultCurrency - the currency of the resultrateProvider - the provider of FX ratesRuntimeException - if no FX rate could be foundpublic int compareTo(BigMoney other)
This compares currencies alphabetically, then by amount.
compareTo in interface Comparable<BigMoney>other - the other amountpublic boolean equals(Object obj)
public int hashCode()
Copyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.