/** * Returns a stream of the values. * <p> * The stream will return the value for each scenario. * * @return a stream of the values */ public default Stream<T> stream() { return IntStream.range(0, getScenarioCount()).mapToObj(i -> get(i)); }
@Override public Class<?> getMarketDataType() { return value.get(0).getClass(); }
@Override public T getValue(int scenarioIndex) { ArgChecker.inRange(scenarioIndex, 0, value.getScenarioCount(), "scenarioIndex"); return value.get(scenarioIndex); }
@Override public <R> MarketDataBox<R> map(Function<T, R> fn) { return applyToScenarios(i -> fn.apply(value.get(i))); }
private <R, U> MarketDataBox<R> combineWithMultiple(MarketDataBox<U> other, BiFunction<T, U, R> fn) { ScenarioArray<U> otherValue = other.getScenarioValue(); if (otherValue.getScenarioCount() != value.getScenarioCount()) { String message = Messages.format( "Scenario values must have the same number of scenarios. {} has {} scenarios, {} has {}", value, value.getScenarioCount(), otherValue, otherValue.getScenarioCount()); throw new IllegalArgumentException(message); } return applyToScenarios(i -> fn.apply(value.get(i), otherValue.get(i))); }
private <U, R> MarketDataBox<R> combineWithSingle(MarketDataBox<U> other, BiFunction<T, U, R> fn) { U otherValue = other.getSingleValue(); return applyToScenarios(i -> fn.apply(value.get(i), otherValue)); }
public void getScenarioValue() { MarketDataBox<Integer> box = MarketDataBox.ofScenarioValues(27, 28, 29); ScenarioArray<Integer> scenarioValue = box.getScenarioValue(); assertThat(scenarioValue.getScenarioCount()).isEqualTo(3); assertThat(scenarioValue.get(0)).isEqualTo(27); assertThat(scenarioValue.get(1)).isEqualTo(28); assertThat(scenarioValue.get(2)).isEqualTo(29); }