Class CurrencyScenarioArray
- java.lang.Object
-
- com.opengamma.strata.data.scenario.CurrencyScenarioArray
-
- All Implemented Interfaces:
ScenarioArray<CurrencyAmount>,ScenarioFxConvertible<CurrencyScenarioArray>,Serializable,org.joda.beans.Bean,org.joda.beans.ImmutableBean
public final class CurrencyScenarioArray extends Object implements ScenarioArray<CurrencyAmount>, ScenarioFxConvertible<CurrencyScenarioArray>, org.joda.beans.ImmutableBean, Serializable
A currency-convertible scenario array for a single currency, holding one amount for each scenario.This contains a list of amounts in a single currency, 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
CurrencyAmountinstances. Internally, it stores the data using a single currency and aDoubleArray.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCurrencyScenarioArray.MetaThe meta-bean forCurrencyScenarioArray.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CurrencyScenarioArrayconvertedTo(Currency reportingCurrency, ScenarioFxRateProvider fxRateProvider)Converts this instance to an equivalent amount in the specified currency.booleanequals(Object obj)CurrencyAmountget(int index)Gets the value at the specified scenario index.CurrencyAmountArraygetAmounts()Gets the currency amounts, one per scenario.CurrencygetCurrency()Gets the currency.intgetScenarioCount()Gets the number of scenarios.inthashCode()static CurrencyScenarioArray.Metameta()The meta-bean forCurrencyScenarioArray.CurrencyScenarioArray.MetametaBean()CurrencyScenarioArrayminus(CurrencyAmount amount)Returns a new array containing the values from this array with the specified amount subtracted.CurrencyScenarioArrayminus(CurrencyScenarioArray other)Returns a new array containing the values from this array with the values from the other array subtracted.static CurrencyScenarioArrayof(int size, IntFunction<CurrencyAmount> amountFunction)Obtains an instance using a function to create the entries.static CurrencyScenarioArrayof(CurrencyAmountArray amounts)Obtains an instance from the specified currency and array of values.static CurrencyScenarioArrayof(Currency currency, DoubleArray values)Obtains an instance from the specified currency and array of values.static CurrencyScenarioArrayof(List<CurrencyAmount> amounts)Obtains an instance from the specified list of amounts.CurrencyScenarioArrayplus(CurrencyAmount amount)Returns a new array containing the values from this array with the specified amount added.CurrencyScenarioArrayplus(CurrencyScenarioArray other)Returns a new array containing the values from this array added to the values in the other array.Stream<CurrencyAmount>stream()Returns a stream of the values.StringtoString()
-
-
-
Method Detail
-
of
public static CurrencyScenarioArray of(CurrencyAmountArray 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 CurrencyScenarioArray of(Currency currency, DoubleArray values)
Obtains an instance from the specified currency and array of values.- Parameters:
currency- the currency of the valuesvalues- the values, one for each scenario- Returns:
- an instance with the specified currency and values
-
of
public static CurrencyScenarioArray of(List<CurrencyAmount> amounts)
Obtains an instance from the specified list of amounts.All amounts must have the same currency.
- Parameters:
amounts- the amounts, one for each scenario- Returns:
- an instance with the specified amounts
- Throws:
IllegalArgumentException- if multiple currencies are found
-
of
public static CurrencyScenarioArray of(int size, IntFunction<CurrencyAmount> amountFunction)
Obtains an instance using a function to create the entries.The function is passed the scenario index and returns the
CurrencyAmountfor that index.In some cases it may be possible to specify the currency with a function providing a
double. To do this, useDoubleArray.of(int, java.util.function.IntToDoubleFunction)and then callof(Currency, DoubleArray).- Parameters:
size- the number of elements, at least size oneamountFunction- the function used to obtain each amount- Returns:
- an instance initialized using the function
- Throws:
IllegalArgumentException- is size is zero or less
-
getCurrency
public Currency getCurrency()
Gets the currency.- Returns:
- the currency
-
getScenarioCount
public int getScenarioCount()
Description copied from interface:ScenarioArrayGets the number of scenarios.- Specified by:
getScenarioCountin interfaceScenarioArray<CurrencyAmount>- Returns:
- the number of scenarios
-
get
public CurrencyAmount get(int index)
Description copied from interface:ScenarioArrayGets the value at the specified scenario index.- Specified by:
getin interfaceScenarioArray<CurrencyAmount>- Parameters:
index- the zero-based index of the scenario- Returns:
- the value at the specified index
-
stream
public Stream<CurrencyAmount> stream()
Description copied from interface:ScenarioArrayReturns a stream of the values.The stream will return the value for each scenario.
- Specified by:
streamin interfaceScenarioArray<CurrencyAmount>- Returns:
- a stream of the values
-
convertedTo
public CurrencyScenarioArray convertedTo(Currency reportingCurrency, ScenarioFxRateProvider fxRateProvider)
Description copied from interface:ScenarioFxConvertibleConverts 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:
convertedToin 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
-
plus
public CurrencyScenarioArray plus(CurrencyScenarioArray 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 currency must be the same as the currency of 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 or different currencies
-
plus
public CurrencyScenarioArray plus(CurrencyAmount amount)
Returns a new array containing the values from this array with the specified amount added.The amount is added to each element in this array. The currency must be the same as the currency of this array.
- Parameters:
amount- the amount to add- Returns:
- a new array containing the values from this array with the specified amount added
- Throws:
IllegalArgumentException- if the array and the amount have different currencies
-
minus
public CurrencyScenarioArray minus(CurrencyScenarioArray 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 currency must be the same as the currency of 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 with the values from the other array subtracted
- Throws:
IllegalArgumentException- if the arrays have different sizes or different currencies
-
minus
public CurrencyScenarioArray minus(CurrencyAmount amount)
Returns a new array containing the values from this array with the specified amount subtracted.The amount is subtracted from each element in this array. The currency must be the same as the currency of this array.
- Parameters:
amount- the amount to subtract- Returns:
- a new array containing the values from this array with the specified amount subtracted
- Throws:
IllegalArgumentException- if the array and the amount have different currencies
-
meta
public static CurrencyScenarioArray.Meta meta()
The meta-bean forCurrencyScenarioArray.- Returns:
- the meta-bean, not null
-
metaBean
public CurrencyScenarioArray.Meta metaBean()
- Specified by:
metaBeanin interfaceorg.joda.beans.Bean
-
getAmounts
public CurrencyAmountArray getAmounts()
Gets the currency amounts, one per scenario.- Returns:
- the value of the property, not null
-
-