Class MultiCurrencyScenarioArray
- java.lang.Object
-
- com.opengamma.strata.data.scenario.MultiCurrencyScenarioArray
-
- All Implemented Interfaces:
ScenarioArray<MultiCurrencyAmount>
,ScenarioFxConvertible<CurrencyScenarioArray>
,Serializable
,org.joda.beans.Bean
,org.joda.beans.ImmutableBean
public final class MultiCurrencyScenarioArray extends Object implements ScenarioArray<MultiCurrencyAmount>, ScenarioFxConvertible<CurrencyScenarioArray>, org.joda.beans.ImmutableBean, Serializable
A currency-convertible scenario array for multi-currency amounts, holding one amount for each scenario.This contains a list of amounts in a multiple currencies, one amount for each scenario. The calculation runner is able to convert the currency of the values if required.
This class uses less memory than an instance based on a list of
MultiCurrencyAmount
instances. Internally, it stores the data using a map of currency toDoubleArray
.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MultiCurrencyScenarioArray.Meta
The meta-bean forMultiCurrencyScenarioArray
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CurrencyScenarioArray
convertedTo(Currency reportingCurrency, ScenarioFxRateProvider fxRateProvider)
Converts this instance to an equivalent amount in the specified currency.boolean
equals(Object obj)
MultiCurrencyAmount
get(int index)
Returns aMultiCurrencyAmount
at the specified index.MultiCurrencyAmountArray
getAmounts()
Gets the multi-currency amounts, one per scenario.Set<Currency>
getCurrencies()
Returns the set of currencies for which this object contains values.int
getScenarioCount()
Returns the number of currency values for each currency.DoubleArray
getValues(Currency currency)
Returns the values for the specified currency, throws an exception if there are no values for the currency.int
hashCode()
static MultiCurrencyScenarioArray.Meta
meta()
The meta-bean forMultiCurrencyScenarioArray
.MultiCurrencyScenarioArray.Meta
metaBean()
static MultiCurrencyScenarioArray
of(int size, IntFunction<MultiCurrencyAmount> amountFunction)
Obtains an instance using a function to create the entries.static MultiCurrencyScenarioArray
of(MultiCurrencyAmount... amounts)
Returns an instance containing the values from the amounts.static MultiCurrencyScenarioArray
of(MultiCurrencyAmountArray amounts)
Obtains an instance from the specified currency and array of values.static MultiCurrencyScenarioArray
of(List<MultiCurrencyAmount> amounts)
Returns an instance containing the values from the list of amounts.static MultiCurrencyScenarioArray
of(Map<Currency,DoubleArray> values)
Returns an instance containing the values from a map of amounts with the same number of elements in each array.Stream<MultiCurrencyAmount>
stream()
Returns a stream ofMultiCurrencyAmount
instances containing the values from this object.static Collector<CurrencyScenarioArray,?,MultiCurrencyScenarioArray>
toMultiCurrencyScenarioArray()
Returns a collector which creates a multi currency scenario array by combining a stream of currency scenario arrays.String
toString()
static MultiCurrencyScenarioArray
total(Iterable<CurrencyScenarioArray> arrays)
Returns a multi currency scenario array representing the total of the input arrays.
-
-
-
Method Detail
-
of
public static MultiCurrencyScenarioArray of(MultiCurrencyAmountArray amounts)
Obtains an instance from the specified currency and array of values.- Parameters:
amounts
- the amounts, one for each scenario- Returns:
- an instance with the specified currency and values
-
of
public static MultiCurrencyScenarioArray of(MultiCurrencyAmount... amounts)
Returns an instance containing the values from the amounts.- Parameters:
amounts
- the amounts, one for each scenario- Returns:
- an instance containing the values from the list of amounts
-
of
public static MultiCurrencyScenarioArray of(List<MultiCurrencyAmount> amounts)
Returns an instance containing the values from the list of amounts.- Parameters:
amounts
- the amounts, one for each scenario- Returns:
- an instance containing the values from the list of amounts
-
of
public static MultiCurrencyScenarioArray of(int size, IntFunction<MultiCurrencyAmount> amountFunction)
Obtains an instance using a function to create the entries.The function is passed the scenario index and returns the value for that index.
- Parameters:
size
- the number of elementsamountFunction
- the function used to obtain each amount- Returns:
- an instance initialized using the function
- Throws:
IllegalArgumentException
- is size is zero or less
-
of
public static MultiCurrencyScenarioArray of(Map<Currency,DoubleArray> values)
Returns an instance containing the values from a map of amounts with the same number of elements in each array.- Parameters:
values
- map of currencies to values- Returns:
- an instance containing the values from the map
-
getCurrencies
public Set<Currency> getCurrencies()
Returns 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)
Returns 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
-
getScenarioCount
public int getScenarioCount()
Returns the number of currency values for each currency.- Specified by:
getScenarioCount
in interfaceScenarioArray<MultiCurrencyAmount>
- Returns:
- the number of currency values for each currency
-
get
public MultiCurrencyAmount get(int index)
Returns aMultiCurrencyAmount
at the specified index.This method is not very efficient for large sizes as a new object must be created at each index. Consider using
getValues(Currency)
instead.- Specified by:
get
in interfaceScenarioArray<MultiCurrencyAmount>
- Parameters:
index
- the index that should be returned- Returns:
- a multi currency amount containing the currency values at the specified index
- Throws:
IndexOutOfBoundsException
- if the index is invalid
-
stream
public Stream<MultiCurrencyAmount> stream()
Returns a stream ofMultiCurrencyAmount
instances containing the values from this object.This method is not very efficient for large sizes as a new object must be created for each value. Consider using
getValues(Currency)
instead.- Specified by:
stream
in interfaceScenarioArray<MultiCurrencyAmount>
- Returns:
- a stream of multi currency amounts containing the currency values from this object
-
convertedTo
public CurrencyScenarioArray convertedTo(Currency reportingCurrency, ScenarioFxRateProvider fxRateProvider)
Description copied from interface:ScenarioFxConvertible
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.
Any object that is not a currency amount will be left unchanged. The number of scenarios of this instance must match the number of scenarios of the specified provider.
- Specified by:
convertedTo
in interfaceScenarioFxConvertible<CurrencyScenarioArray>
- Parameters:
reportingCurrency
- the currency of the resultfxRateProvider
- the multi-scenario provider of FX rates- Returns:
- the converted instance, which should be expressed in the specified currency
-
total
public static MultiCurrencyScenarioArray total(Iterable<CurrencyScenarioArray> arrays)
Returns a multi currency scenario 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
-
toMultiCurrencyScenarioArray
public static Collector<CurrencyScenarioArray,?,MultiCurrencyScenarioArray> toMultiCurrencyScenarioArray()
Returns a collector which creates a multi currency scenario array by combining a stream of currency scenario arrays.The arrays in the stream must all have the same length.
- Returns:
- the collector
-
meta
public static MultiCurrencyScenarioArray.Meta meta()
The meta-bean forMultiCurrencyScenarioArray
.- Returns:
- the meta-bean, not null
-
metaBean
public MultiCurrencyScenarioArray.Meta metaBean()
- Specified by:
metaBean
in interfaceorg.joda.beans.Bean
-
getAmounts
public MultiCurrencyAmountArray getAmounts()
Gets the multi-currency amounts, one per scenario.- Returns:
- the value of the property, not null
-
-