Class MultiCurrencyAmountArray
- java.lang.Object
-
- com.opengamma.strata.basics.currency.MultiCurrencyAmountArray
-
- All Implemented Interfaces:
FxConvertible<CurrencyAmountArray>
,Serializable
,org.joda.beans.Bean
,org.joda.beans.ImmutableBean
public final class MultiCurrencyAmountArray extends Object implements FxConvertible<CurrencyAmountArray>, org.joda.beans.ImmutableBean, Serializable
An array of multi-currency amounts.This represents an array of
MultiCurrencyAmount
. Internally, it stores the data using a map ofCurrency
toDoubleArray
, which uses less memory than aList<MultiCurrencyAmount>
.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MultiCurrencyAmountArray.Meta
The meta-bean forMultiCurrencyAmountArray
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CurrencyAmountArray
convertedTo(Currency resultCurrency, FxRateProvider fxRateProvider)
Converts this instance to an equivalent amount in the specified currency.boolean
equals(Object obj)
MultiCurrencyAmount
get(int index)
Gets the amount at the specified index.Set<Currency>
getCurrencies()
Gets the set of currencies for which this object contains values.int
getSize()
Gets the size of this array.ImmutableSortedMap<Currency,DoubleArray>
getValues()
Gets the currency values, keyed by currency.DoubleArray
getValues(Currency currency)
Gets the values for the specified currency, throws an exception if there are no values for the currency.int
hashCode()
static MultiCurrencyAmountArray.Meta
meta()
The meta-bean forMultiCurrencyAmountArray
.MultiCurrencyAmountArray.Meta
metaBean()
MultiCurrencyAmountArray
minus(MultiCurrencyAmount amount)
Returns a new array containing the values from this array with the values from the amount subtracted.MultiCurrencyAmountArray
minus(MultiCurrencyAmountArray other)
Returns a new array containing the values from this array with the values from the other array subtracted.static MultiCurrencyAmountArray
of(int size, IntFunction<MultiCurrencyAmount> valueFunction)
Obtains an instance using a function to create the entries.static MultiCurrencyAmountArray
of(MultiCurrencyAmount... amounts)
Obtains an instance from the specified multi-currency amounts.static MultiCurrencyAmountArray
of(List<MultiCurrencyAmount> amounts)
Obtains an instance from the specified multi-currency amounts.static MultiCurrencyAmountArray
of(Map<Currency,DoubleArray> values)
Obtains an instance from a map of amounts.MultiCurrencyAmountArray
plus(MultiCurrencyAmount amount)
Returns a new array containing the values from this array with the values from the amount added.MultiCurrencyAmountArray
plus(MultiCurrencyAmountArray other)
Returns a new array containing the values from this array added to the values in the other array.int
size()
Gets the size of the array.Stream<MultiCurrencyAmount>
stream()
Returns a stream of the amounts.static Collector<CurrencyAmountArray,?,MultiCurrencyAmountArray>
toMultiCurrencyAmountArray()
Returns a collector which creates a multi currency amount array by combining a stream of currency amount arrays.String
toString()
static MultiCurrencyAmountArray
total(Iterable<CurrencyAmountArray> arrays)
Returns a multi currency amount array representing the total of the input arrays.
-
-
-
Method Detail
-
of
public static MultiCurrencyAmountArray of(MultiCurrencyAmount... amounts)
Obtains an instance from the specified multi-currency amounts.- Parameters:
amounts
- the amounts- Returns:
- an instance with the specified amounts
-
of
public static MultiCurrencyAmountArray of(List<MultiCurrencyAmount> amounts)
Obtains an instance from the specified multi-currency amounts.- Parameters:
amounts
- the amounts- Returns:
- an instance with the specified amounts
-
of
public static MultiCurrencyAmountArray of(int size, IntFunction<MultiCurrencyAmount> valueFunction)
Obtains an instance using a function to create the entries.The function is passed the index and returns the
MultiCurrencyAmount
for that index.- Parameters:
size
- the number of elements, at least size onevalueFunction
- the function used to obtain each value- Returns:
- an instance initialized using the function
- Throws:
IllegalArgumentException
- is size is zero or less
-
of
public static MultiCurrencyAmountArray of(Map<Currency,DoubleArray> values)
Obtains an instance from a map of amounts.Each currency is associated with an array of amounts. All the arrays must have the same number of elements.
If the map is empty the returned array will have a size of zero. To create an empty array with a non-zero size use one of the other
of
methods.- Parameters:
values
- map of currencies to values- Returns:
- an instance containing the values from the map
-
getCurrencies
public Set<Currency> getCurrencies()
Gets the set of currencies for which this object contains values.- Returns:
- the set of currencies for which this object contains values
-
getValues
public DoubleArray getValues(Currency currency)
Gets the values for the specified currency, throws an exception if there are no values for the currency.- Parameters:
currency
- the currency for which values are required- Returns:
- the values for the specified currency, throws an exception if there are none
- Throws:
IllegalArgumentException
- if there are no values for the currency
-
size
public int size()
Gets the size of the array.- Returns:
- the array size
-
get
public MultiCurrencyAmount get(int index)
Gets the amount at the specified index.- Parameters:
index
- the zero-based index to retrieve- Returns:
- the amount at the specified index
-
stream
public Stream<MultiCurrencyAmount> stream()
Returns a stream of the amounts.- Returns:
- a stream of the amounts
-
convertedTo
public CurrencyAmountArray convertedTo(Currency resultCurrency, FxRateProvider fxRateProvider)
Description copied from interface:FxConvertible
Converts this instance to an equivalent amount in the specified currency.The result, which may be of a different type, will be expressed in terms of the given currency. Any FX conversion that is required will use rates from the provider.
- Specified by:
convertedTo
in interfaceFxConvertible<CurrencyAmountArray>
- Parameters:
resultCurrency
- the currency of the resultfxRateProvider
- the provider of FX rates- Returns:
- the converted instance, which should be expressed in the specified currency
-
plus
public MultiCurrencyAmountArray plus(MultiCurrencyAmountArray other)
Returns a new array containing the values from this array added to the values in the other array.The amounts are added to the matching element in this array. The arrays must have the same size.
- Parameters:
other
- another array of multiple currency values.- Returns:
- a new array containing the values from this array added to the values in the other array
- Throws:
IllegalArgumentException
- if the arrays have different sizes
-
plus
public MultiCurrencyAmountArray plus(MultiCurrencyAmount amount)
Returns a new array containing the values from this array with the values from the amount added.The amount is added to each element in this array.
- Parameters:
amount
- the amount to add- Returns:
- a new array containing the values from this array added to the values in the other array
-
minus
public MultiCurrencyAmountArray minus(MultiCurrencyAmountArray other)
Returns a new array containing the values from this array with the values from the other array subtracted.The amounts are subtracted from the matching element in this array. The arrays must have the same size.
- Parameters:
other
- another array of multiple currency values.- Returns:
- a new array containing the values from this array added with the values from the other array subtracted
- Throws:
IllegalArgumentException
- if the arrays have different sizes
-
minus
public MultiCurrencyAmountArray minus(MultiCurrencyAmount amount)
Returns a new array containing the values from this array with the values from the amount subtracted.The amount is subtracted from each element in this array.
- Parameters:
amount
- the amount to subtract- Returns:
- a new array containing the values from this array with the values from the amount subtracted
-
total
public static MultiCurrencyAmountArray total(Iterable<CurrencyAmountArray> arrays)
Returns a multi currency amount array representing the total of the input arrays.If the input contains the same currency more than once, the amounts are added together.
- Parameters:
arrays
- the amount arrays- Returns:
- the total amounts
-
toMultiCurrencyAmountArray
public static Collector<CurrencyAmountArray,?,MultiCurrencyAmountArray> toMultiCurrencyAmountArray()
Returns a collector which creates a multi currency amount array by combining a stream of currency amount arrays.The arrays in the stream must all have the same length.
- Returns:
- the collector
-
meta
public static MultiCurrencyAmountArray.Meta meta()
The meta-bean forMultiCurrencyAmountArray
.- Returns:
- the meta-bean, not null
-
metaBean
public MultiCurrencyAmountArray.Meta metaBean()
- Specified by:
metaBean
in interfaceorg.joda.beans.Bean
-
getSize
public int getSize()
Gets the size of this array.- Returns:
- the value of the property
-
getValues
public ImmutableSortedMap<Currency,DoubleArray> getValues()
Gets the currency values, keyed by currency.- Returns:
- the value of the property, not null
-
-