public final class MultiCurrencyAmount extends Object implements FxConvertible<CurrencyAmount>, org.joda.beans.ImmutableBean, Serializable
This is a container holding multiple CurrencyAmount instances.
The amounts do not necessarily have the same worth or value in each currency.
This class is immutable and thread-safe.
| Modifier and Type | Class and Description |
|---|---|
static class |
MultiCurrencyAmount.Meta
The meta-bean for
MultiCurrencyAmount. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(Currency currency)
Checks if this multi-amount contains an amount for the specified currency.
|
CurrencyAmount |
convertedTo(Currency resultCurrency,
FxRateProvider rateProvider)
Converts this amount to an equivalent amount the specified currency.
|
static MultiCurrencyAmount |
empty()
Obtains an empty
MultiCurrencyAmount. |
boolean |
equals(Object obj) |
CurrencyAmount |
getAmount(Currency currency)
Gets the
CurrencyAmount for the specified currency, throwing an exception if not found. |
CurrencyAmount |
getAmountOrZero(Currency currency)
Gets the
CurrencyAmount for the specified currency, returning zero if not found. |
ImmutableSortedSet<CurrencyAmount> |
getAmounts()
Gets the set of currency amounts.
|
ImmutableSet<Currency> |
getCurrencies()
Gets the set of stored currencies.
|
int |
hashCode() |
MultiCurrencyAmount |
mapAmounts(DoubleUnaryOperator mapper)
Applies an operation to the amounts.
|
MultiCurrencyAmount |
mapCurrencyAmounts(UnaryOperator<CurrencyAmount> operator)
Applies an operation to the currency amounts.
|
static MultiCurrencyAmount.Meta |
meta()
The meta-bean for
MultiCurrencyAmount. |
MultiCurrencyAmount.Meta |
metaBean() |
MultiCurrencyAmount |
minus(CurrencyAmount amountToSubtract)
Returns a copy of this
MultiCurrencyAmount with the specified amount subtracted. |
MultiCurrencyAmount |
minus(Currency currency,
double amountToAdd)
Returns a copy of this
MultiCurrencyAmount with the specified amount subtracted. |
MultiCurrencyAmount |
minus(MultiCurrencyAmount amountToSubtract)
Returns a copy of this
MultiCurrencyAmount with the specified amount subtracted. |
MultiCurrencyAmount |
multipliedBy(double factor)
Returns a copy of this
MultiCurrencyAmount with all the amounts multiplied by the factor. |
MultiCurrencyAmount |
negated()
Returns a copy of this
CurrencyAmount with the amount negated. |
static MultiCurrencyAmount |
of(CurrencyAmount... amounts)
Obtains an instance from an array of
CurrencyAmount objects. |
static MultiCurrencyAmount |
of(Currency currency,
double amount)
Obtains an instance from a currency and amount.
|
static MultiCurrencyAmount |
of(Iterable<CurrencyAmount> amounts)
Obtains an instance from a list of
CurrencyAmount objects. |
static MultiCurrencyAmount |
of(Map<Currency,Double> map)
Obtains an instance from a map of currency to amount.
|
MultiCurrencyAmount |
plus(CurrencyAmount amountToAdd)
Returns a copy of this
MultiCurrencyAmount with the specified amount added. |
MultiCurrencyAmount |
plus(Currency currency,
double amountToAdd)
Returns a copy of this
MultiCurrencyAmount with the specified amount added. |
MultiCurrencyAmount |
plus(MultiCurrencyAmount amountToAdd)
Returns a copy of this
MultiCurrencyAmount with the specified amount added. |
int |
size()
Gets the number of stored amounts.
|
Stream<CurrencyAmount> |
stream()
Returns a stream over the currency amounts.
|
ImmutableSortedMap<Currency,Double> |
toMap()
Converts this
MultiCurrencyAmount to a map keyed by currency. |
static Collector<CurrencyAmount,?,MultiCurrencyAmount> |
toMultiCurrencyAmount()
Returns a collector that can be used to create a multi-currency amount from a stream of amounts.
|
String |
toString()
Gets the amount as a string.
|
static MultiCurrencyAmount |
total(Iterable<CurrencyAmount> amounts)
Obtains an instance from the total of a list of
CurrencyAmount objects. |
public static MultiCurrencyAmount empty()
MultiCurrencyAmount.public static MultiCurrencyAmount of(Currency currency, double amount)
currency - the currencyamount - the amountpublic static MultiCurrencyAmount of(CurrencyAmount... amounts)
CurrencyAmount objects.
It is an error for the input to contain the same currency twice.
amounts - the amountspublic static MultiCurrencyAmount of(Iterable<CurrencyAmount> amounts)
CurrencyAmount objects.
It is an error for the input to contain the same currency twice.
amounts - the amountspublic static MultiCurrencyAmount of(Map<Currency,Double> map)
map - the map of currency to amountpublic static MultiCurrencyAmount total(Iterable<CurrencyAmount> amounts)
CurrencyAmount objects.
If the input contains the same currency more than once, the amounts are added together. For example, an input of (EUR 100, EUR 200, CAD 100) would result in (EUR 300, CAD 100).
amounts - the amountspublic static Collector<CurrencyAmount,?,MultiCurrencyAmount> toMultiCurrencyAmount()
If the input contains the same currency more than once, the amounts are added together. For example, an input of (EUR 100, EUR 200, CAD 100) would result in (EUR 300, CAD 100).
public ImmutableSet<Currency> getCurrencies()
public int size()
public boolean contains(Currency currency)
currency - the currency to findpublic CurrencyAmount getAmount(Currency currency)
CurrencyAmount for the specified currency, throwing an exception if not found.currency - the currency to find an amount forIllegalArgumentException - if the currency is not foundpublic CurrencyAmount getAmountOrZero(Currency currency)
CurrencyAmount for the specified currency, returning zero if not found.currency - the currency to find an amount forpublic MultiCurrencyAmount plus(Currency currency, double amountToAdd)
MultiCurrencyAmount with the specified amount added.
This adds the specified amount to this monetary amount, returning a new object.
If the currency is already present, the amount is added to the existing amount.
If the currency is not yet present, the currency-amount is added to the map.
The addition uses standard double arithmetic.
This instance is immutable and unaffected by this method.
currency - the currency to add toamountToAdd - the amount to addpublic MultiCurrencyAmount plus(CurrencyAmount amountToAdd)
MultiCurrencyAmount with the specified amount added.
This adds the specified amount to this monetary amount, returning a new object.
If the currency is already present, the amount is added to the existing amount.
If the currency is not yet present, the currency-amount is added to the map.
The addition uses standard double arithmetic.
This instance is immutable and unaffected by this method.
amountToAdd - the amount to addpublic MultiCurrencyAmount plus(MultiCurrencyAmount amountToAdd)
MultiCurrencyAmount with the specified amount added.
This adds the specified amount to this monetary amount, returning a new object.
If the currency is already present, the amount is added to the existing amount.
If the currency is not yet present, the currency-amount is added to the map.
The addition uses standard double arithmetic.
This instance is immutable and unaffected by this method.
amountToAdd - the amount to addpublic MultiCurrencyAmount minus(Currency currency, double amountToAdd)
MultiCurrencyAmount with the specified amount subtracted.
This subtracts the specified amount from this monetary amount, returning a new object.
If the currency is already present, the amount is subtracted from the existing amount.
If the currency is not yet present, the negated amount is included.
The subtraction uses standard double arithmetic.
This instance is immutable and unaffected by this method.
currency - the currency to subtract fromamountToAdd - the amount to subtractpublic MultiCurrencyAmount minus(CurrencyAmount amountToSubtract)
MultiCurrencyAmount with the specified amount subtracted.
This subtracts the specified amount from this monetary amount, returning a new object.
If the currency is already present, the amount is subtracted from the existing amount.
If the currency is not yet present, the negated amount is included.
The subtraction uses standard double arithmetic.
This instance is immutable and unaffected by this method.
amountToSubtract - the amount to subtractpublic MultiCurrencyAmount minus(MultiCurrencyAmount amountToSubtract)
MultiCurrencyAmount with the specified amount subtracted.
This subtracts the specified amount from this monetary amount, returning a new object.
If the currency is already present, the amount is subtracted from the existing amount.
If the currency is not yet present, the negated amount is included.
The subtraction uses standard double arithmetic.
This instance is immutable and unaffected by this method.
amountToSubtract - the amount to subtractpublic MultiCurrencyAmount multipliedBy(double factor)
MultiCurrencyAmount with all the amounts multiplied by the factor.
This instance is immutable and unaffected by this method.
factor - the multiplicative factorpublic MultiCurrencyAmount negated()
CurrencyAmount with the amount negated.
This takes this amount and negates it. If any amount is 0.0 or -0.0 the negated amount is 0.0.
This instance is immutable and unaffected by this method.
public Stream<CurrencyAmount> stream()
This provides access to the entire set of amounts.
public MultiCurrencyAmount mapAmounts(DoubleUnaryOperator mapper)
This is generally used to apply a mathematical operation to the amounts. For example, the operator could multiply the amounts by a constant, or take the inverse.
multiplied = base.mapAmount(value -> value * 3);
mapper - the operator to be applied to the amountspublic MultiCurrencyAmount mapCurrencyAmounts(UnaryOperator<CurrencyAmount> operator)
The operator is called once for each currency in this amount. The operator may return an amount with a different currency. The result will be the total of the altered amounts.
operator - the operator to be applied to the amountspublic CurrencyAmount 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<CurrencyAmount>resultCurrency - the currency of the resultrateProvider - the provider of FX ratesRuntimeException - if no FX rate could be foundpublic ImmutableSortedMap<Currency,Double> toMap()
MultiCurrencyAmount to a map keyed by currency.public String toString()
The format includes each currency-amount.
public static MultiCurrencyAmount.Meta meta()
MultiCurrencyAmount.public MultiCurrencyAmount.Meta metaBean()
metaBean in interface org.joda.beans.Beanpublic ImmutableSortedSet<CurrencyAmount> getAmounts()
Copyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.