Interface ScenarioArray<T>
-
- Type Parameters:
T
- the type of each individual value
- All Known Implementing Classes:
CurrencyScenarioArray
,DoubleScenarioArray
,FxRateScenarioArray
,MultiCurrencyScenarioArray
,QuoteScenarioArray
public interface ScenarioArray<T>
An array of values, one for each scenario.Implementations of this interface provide scenario-specific values.
In the simplest case, this might be a list of values, one for each scenario. This is handled by this factory methods on this interface.
There are two obvious reasons for creating implementations of this interface with special handling for certain types of value:
- Reducing memory usage
- Improving performance
When dealing with primitive data it is likely be more efficient to store the scenario values in a primitive array instead of using a list. This removes the need for boxing and reduces memory footprint. Also, if a function calculates values for all scenarios at the same time, it is likely to be more efficient if the data is stored in arrays as the values will be stored in a contiguous block of memory.
The generic type parameter is the type of the single value associated with each scenario. For example, in the case of optimized curve storage, the single value is a curve.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description T
get(int scenarioIndex)
Gets the value at the specified scenario index.int
getScenarioCount()
Gets the number of scenarios.static <T> ScenarioArray<T>
of(int scenarioCount, IntFunction<T> valueFunction)
Obtains an instance using a function to create the entries.static <T> ScenarioArray<T>
of(List<T> values)
Obtains an instance from the specified list of values.static <T> ScenarioArray<T>
of(T... values)
Obtains an instance from the specified array of values.static <T> ScenarioArray<T>
ofSingleValue(int scenarioCount, T value)
Obtains an instance from a single value where the value applies to all scenarios.default Stream<T>
stream()
Returns a stream of the values.
-
-
-
Method Detail
-
of
@SafeVarargs static <T> ScenarioArray<T> of(T... values)
Obtains an instance from the specified array of values.- Type Parameters:
T
- the type of the value- Parameters:
values
- the values, one value for each scenario- Returns:
- an instance with the specified values
-
of
static <T> ScenarioArray<T> of(List<T> values)
Obtains an instance from the specified list of values.- Type Parameters:
T
- the type of the value- Parameters:
values
- the values, one value for each scenario- Returns:
- an instance with the specified values
-
of
static <T> ScenarioArray<T> of(int scenarioCount, IntFunction<T> valueFunction)
Obtains an instance using a function to create the entries.The function is passed the scenario index and returns the value for that index.
- Type Parameters:
T
- the type of the value- Parameters:
scenarioCount
- the number of scenariosvalueFunction
- the function used to obtain each value- Returns:
- an instance initialized using the function
- Throws:
IllegalArgumentException
- is size is zero or less
-
ofSingleValue
static <T> ScenarioArray<T> ofSingleValue(int scenarioCount, T value)
Obtains an instance from a single value where the value applies to all scenarios.- Type Parameters:
T
- the type of the value- Parameters:
scenarioCount
- the nnumber of scenariosvalue
- the single value, used for all scenarios- Returns:
- an instance with the specified values
-
getScenarioCount
int getScenarioCount()
Gets the number of scenarios.- Returns:
- the number of scenarios
-
get
T get(int scenarioIndex)
Gets the value at the specified scenario index.- Parameters:
scenarioIndex
- the zero-based index of the scenario- Returns:
- the value at the specified index
- Throws:
IndexOutOfBoundsException
- if the index is invalid
-
-