Class Results
- java.lang.Object
-
- com.opengamma.strata.calc.Results
-
- All Implemented Interfaces:
org.joda.beans.Bean
,org.joda.beans.ImmutableBean
public final class Results extends Object implements org.joda.beans.ImmutableBean
Calculation results of performing calculations for a set of targets and columns.This defines a grid of results where the grid contains a row for each target and a column for each measure. Each result may be a single value or a multi-scenario value. A multi-scenario value will implement
ScenarioArray
unless it has been aggregated.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Results.Meta
The meta-bean forResults
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
columnIndexByName(ColumnName columnName)
Gets the column index by name.<T> Stream<Result<?>>
columnResults(int columnIndex)
Returns a stream of results for a single column by column index.<T> Stream<Result<T>>
columnResults(int columnIndex, Class<T> type)
Returns a stream of results for a single column by column index.<C> Stream<Result<ScenarioArray<C>>>
columnResultsScenarios(int columnIndex, Class<C> componentType)
Returns a stream of multi-scenario results for a single column by column index.boolean
equals(Object obj)
Result<?>
get(int rowIndex, int columnIndex)
Returns the results for a target and column index.<T> Result<T>
get(int rowIndex, int columnIndex, Class<T> type)
Returns the results for a target and column index, casting the result to a known type.Result<?>
get(int rowIndex, ColumnName columnName)
Returns the results for a target and column name.<T> Result<T>
get(int rowIndex, ColumnName columnName, Class<T> type)
Returns the results for a target and column name, casting the result to a known type.ImmutableList<Result<?>>
getCells()
Gets the grid of results, stored as a flat list.int
getColumnCount()
Gets the number of columns in the results.ImmutableList<ColumnHeader>
getColumns()
Gets the column headers.int
getRowCount()
Gets the number of rows in the results.<C> Result<ScenarioArray<C>>
getScenarios(int rowIndex, int columnIndex, Class<C> componentType)
Returns multi-scenario results for a target and column index, casting the result to a known type.<C> Result<ScenarioArray<C>>
getScenarios(int rowIndex, ColumnName columnName, Class<C> componentType)
Returns multi-scenario results for a target and column name, casting the result to a known type.int
hashCode()
static Results.Meta
meta()
The meta-bean forResults
.Results.Meta
metaBean()
static Results
of(List<ColumnHeader> columns, List<? extends Result<?>> cells)
Obtains an instance containing the results of the calculation for each cell.String
toString()
-
-
-
Method Detail
-
of
public static Results of(List<ColumnHeader> columns, List<? extends Result<?>> cells)
Obtains an instance containing the results of the calculation for each cell.The number of cells must be exactly divisible by the number of columns.
- Parameters:
columns
- the names of each columncells
- the calculated results, one for each cell- Returns:
- a set of results for the calculations
-
getRowCount
public int getRowCount()
Gets the number of rows in the results.The number of rows equals the number of targets input to the calculation.
- Returns:
- the number of rows
-
getColumnCount
public int getColumnCount()
Gets the number of columns in the results.- Returns:
- the number of columns
-
get
public Result<?> get(int rowIndex, int columnIndex)
Returns the results for a target and column index.The result may be a single value or a multi-scenario value. A multi-scenario value will implement
ScenarioArray
unless it has been aggregated.If the calculation did not complete successfully, a failure result will be returned explaining the problem. Callers must check whether the result is a success or failure before examining the result value.
- Parameters:
rowIndex
- the index of the row containing the results for a targetcolumnIndex
- the index of the column- Returns:
- the result for the specified row and column for a set of scenarios
- Throws:
IllegalArgumentException
- if the row or column index is invalid
-
get
public <T> Result<T> get(int rowIndex, int columnIndex, Class<T> type)
Returns the results for a target and column index, casting the result to a known type.The result may be a single value or a multi-scenario value. A multi-scenario value will implement
ScenarioArray
unless it has been aggregated.If the calculation did not complete successfully, a failure result will be returned explaining the problem. Callers must check whether the result is a success or failure before examining the result value.
- Type Parameters:
T
- the result type- Parameters:
rowIndex
- the index of the row containing the results for a targetcolumnIndex
- the index of the columntype
- the result type- Returns:
- the result for the specified row and column for a set of scenarios, cast to the specified type
- Throws:
IllegalArgumentException
- if the row or column index is invalidClassCastException
- if the result is not of the specified type
-
get
public Result<?> get(int rowIndex, ColumnName columnName)
Returns the results for a target and column name.The result may be a single value or a multi-scenario value. A multi-scenario value will implement
ScenarioArray
unless it has been aggregated.If the calculation did not complete successfully, a failure result will be returned explaining the problem. Callers must check whether the result is a success or failure before examining the result value.
- Parameters:
rowIndex
- the index of the row containing the results for a targetcolumnName
- the name of the column- Returns:
- the result for the specified row and column for a set of scenarios
- Throws:
IllegalArgumentException
- if the row index or column name is invalid
-
columnIndexByName
public int columnIndexByName(ColumnName columnName)
Gets the column index by name.- Parameters:
columnName
- the column name- Returns:
- the column index
- Throws:
IllegalArgumentException
- if the column name is invalid
-
get
public <T> Result<T> get(int rowIndex, ColumnName columnName, Class<T> type)
Returns the results for a target and column name, casting the result to a known type.The result may be a single value or a multi-scenario value. A multi-scenario value will implement
ScenarioArray
unless it has been aggregated.If the calculation did not complete successfully, a failure result will be returned explaining the problem. Callers must check whether the result is a success or failure before examining the result value.
- Type Parameters:
T
- the result type- Parameters:
rowIndex
- the index of the row containing the results for a targetcolumnName
- the name of the columntype
- the result type- Returns:
- the result for the specified row and column for a set of scenarios, cast to the specified type
- Throws:
IllegalArgumentException
- if the row index or column name is invalidClassCastException
- if the result is not of the specified type
-
getScenarios
public <C> Result<ScenarioArray<C>> getScenarios(int rowIndex, int columnIndex, Class<C> componentType)
Returns multi-scenario results for a target and column index, casting the result to a known type.The result is a multi-scenario
ScenarioArray
. Typed subclasses ofScenarioArray
can also be obtained usingget(int, int, Class)
.If the calculation did not complete successfully, a failure result will be returned explaining the problem. Callers must check whether the result is a success or failure before examining the result value.
- Type Parameters:
C
- the type parameter ofScenarioArray
- Parameters:
rowIndex
- the index of the row containing the results for a targetcolumnIndex
- the index of the columncomponentType
- the type parameter ofScenarioArray
- Returns:
- the result for the specified row and column for a set of scenarios, cast to the specified type
- Throws:
IllegalArgumentException
- if the row or column index is invalidClassCastException
- if the result is not of the specified type
-
getScenarios
public <C> Result<ScenarioArray<C>> getScenarios(int rowIndex, ColumnName columnName, Class<C> componentType)
Returns multi-scenario results for a target and column name, casting the result to a known type.The result is a multi-scenario
ScenarioArray
. Typed subclasses ofScenarioArray
can also be obtained usingget(int, ColumnName, Class)
.If the calculation did not complete successfully, a failure result will be returned explaining the problem. Callers must check whether the result is a success or failure before examining the result value.
- Type Parameters:
C
- the type parameter ofScenarioArray
- Parameters:
rowIndex
- the index of the row containing the results for a targetcolumnName
- the name of the columncomponentType
- the type parameter ofScenarioArray
- Returns:
- the result for the specified row and column for a set of scenarios, cast to the specified type
- Throws:
IllegalArgumentException
- if the row or column index is invalidClassCastException
- if the result is not of the specified type
-
columnResults
public <T> Stream<Result<?>> columnResults(int columnIndex)
Returns a stream of results for a single column by column index.The result may be a single value or a multi-scenario value. A multi-scenario value will implement
ScenarioArray
unless it has been aggregated.If the calculation did not complete successfully, a failure result will be returned explaining the problem. Callers must check whether the result is a success or failure before examining the result value.
Large streams can be processed in parallel via
BaseStream.parallel()
. SeeGuavate.zipWithIndex(Stream)
if the row index is required.- Type Parameters:
T
- the result type- Parameters:
columnIndex
- the index of the column- Returns:
- the stream of results for the specified column
- Throws:
IllegalArgumentException
- if the column index is invalid
-
columnResults
public <T> Stream<Result<T>> columnResults(int columnIndex, Class<T> type)
Returns a stream of results for a single column by column index.The result may be a single value or a multi-scenario value. A multi-scenario value will implement
ScenarioArray
unless it has been aggregated.If the calculation did not complete successfully, a failure result will be returned explaining the problem. Callers must check whether the result is a success or failure before examining the result value.
Large streams can be processed in parallel via
BaseStream.parallel()
. SeeGuavate.zipWithIndex(Stream)
if the row index is required. The stream will throwClassCastException
if the result is not of the specified type.- Type Parameters:
T
- the result type- Parameters:
columnIndex
- the index of the columntype
- the result type- Returns:
- the stream of results for the specified column, cast to the specified type
- Throws:
IllegalArgumentException
- if the column index is invalid
-
columnResultsScenarios
public <C> Stream<Result<ScenarioArray<C>>> columnResultsScenarios(int columnIndex, Class<C> componentType)
Returns a stream of multi-scenario results for a single column by column index.The result is a multi-scenario
ScenarioArray
. Typed subclasses ofScenarioArray
can also be obtained usingcolumnResults(int)
.If the calculation did not complete successfully, a failure result will be returned explaining the problem. Callers must check whether the result is a success or failure before examining the result value.
Large streams can be processed in parallel via
BaseStream.parallel()
. SeeGuavate.zipWithIndex(Stream)
if the row index is required. The stream will throwClassCastException
if the result is not of the specified type.- Type Parameters:
C
- the type parameter ofScenarioArray
- Parameters:
columnIndex
- the index of the columncomponentType
- the type parameter ofScenarioArray
- Returns:
- the stream of results for the specified column, cast to the specified type
- Throws:
IllegalArgumentException
- if the column index is invalid
-
meta
public static Results.Meta meta()
The meta-bean forResults
.- Returns:
- the meta-bean, not null
-
metaBean
public Results.Meta metaBean()
- Specified by:
metaBean
in interfaceorg.joda.beans.Bean
-
getColumns
public ImmutableList<ColumnHeader> getColumns()
Gets the column headers.Each column in the results is defined by a header consisting of the name and measure. The size of this list defines the number of columns, which is needed to interpret the list of cells.
- Returns:
- the value of the property, not null
-
getCells
public ImmutableList<Result<?>> getCells()
Gets the grid of results, stored as a flat list.This list contains the calculated result for each cell in the grid. The cells are grouped by target, then column. Thus, the index of a given cell is
(targetRowIndex * columnCount) + columnIndex
.For example, given a set of results with two targets, t1 and t2, and three columns c1, c2, and c3, the results will be:
[t1c1, t1c2, t1c3, t2c1, t2c2, t2c3]
- Returns:
- the value of the property, not null
-
-