@Override public int getScenarioCount() { return value.getScenarioCount(); }
/** * 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)); }
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 <R> MarketDataBox<R> applyToScenarios(Function<Integer, R> fn) { List<R> results = IntStream.range(0, value.getScenarioCount()) .mapToObj(fn::apply) .collect(toImmutableList()); return MarketDataBox.ofScenarioValues(results); }
private <U, R> MarketDataBox<R> combineWithMultiple(MarketDataBox<U> other, BiFunction<T, U, R> fn) { ScenarioArray<U> otherValue = other.getScenarioValue(); int scenarioCount = otherValue.getScenarioCount(); List<R> values = IntStream.range(0, scenarioCount) .mapToObj(i -> fn.apply(value, other.getValue(i))) .collect(toImmutableList()); return MarketDataBox.ofScenarioValues(values); }
@Override public T getValue(int scenarioIndex) { ArgChecker.inRange(scenarioIndex, 0, value.getScenarioCount(), "scenarioIndex"); return value.get(scenarioIndex); }
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); }