private void checkAndUpdateScenarioCount(MarketDataBox<?> value) { if (value.isScenarioValue()) { if (scenarioCount == -1) { scenarioCount = value.getScenarioCount(); } else if (value.getScenarioCount() != scenarioCount) { throw new IllegalArgumentException(Messages.format( "All values must have the same number of scenarios, expecting {} but received {}", scenarioCount, value.getScenarioCount())); } } }
public void isSingleOrScenarioValue() { MarketDataBox<Integer> box = MarketDataBox.ofScenarioValues(27, 28, 29); assertThat(box.isSingleValue()).isFalse(); assertThat(box.isScenarioValue()).isTrue(); }
public void isSingleOrScenarioValue() { MarketDataBox<Integer> box = MarketDataBox.ofSingleValue(27); assertThat(box.isSingleValue()).isTrue(); assertThat(box.isScenarioValue()).isFalse(); }
static void checkType(MarketDataId<?> id, MarketDataBox<?> box, int scenarioCount) { if (box == null) { throw new IllegalArgumentException(Messages.format( "Value for identifier '{}' must not be null", id)); } if (box.isScenarioValue() && box.getScenarioCount() != scenarioCount) { throw new IllegalArgumentException(Messages.format( "Value for identifier '{}' should have had {} scenarios but had {}", id, scenarioCount, box.getScenarioCount())); } if (box.getScenarioCount() > 0 && !id.getMarketDataType().isInstance(box.getValue(0))) { throw new ClassCastException(Messages.format( "Value for identifier '{}' does not implement expected type '{}': '{}'", id, id.getMarketDataType().getSimpleName(), box)); } }
@ImmutableValidator private void validate() { if (value.isScenarioValue() && value.getScenarioCount() != underlying.getScenarioCount()) { throw new IllegalArgumentException(Messages.format( "Scenario count mismatch: value has {} scenarios but this market data has {}", value.getScenarioCount(), underlying.getScenarioCount())); } }
/** * Tests that applying a function multiple times to the value creates a box of scenario values. */ public void mapWithIndex() { MarketDataBox<Integer> box = MarketDataBox.ofScenarioValues(27, 28, 29); MarketDataBox<Integer> scenarioBox = box.mapWithIndex(3, (v, idx) -> v + idx); assertThat(scenarioBox.isScenarioValue()).isTrue(); assertThat(scenarioBox.getScenarioCount()).isEqualTo(3); assertThat(scenarioBox.getValue(0)).isEqualTo(27); assertThat(scenarioBox.getValue(1)).isEqualTo(29); assertThat(scenarioBox.getValue(2)).isEqualTo(31); }
/** * Tests that applying a function multiple times to the value creates a box of scenario values. */ public void mapWithIndex() { MarketDataBox<Integer> box = MarketDataBox.ofSingleValue(27); MarketDataBox<Integer> scenarioBox = box.mapWithIndex(3, (v, idx) -> v + idx); assertThat(scenarioBox.isScenarioValue()).isTrue(); assertThat(scenarioBox.getScenarioCount()).isEqualTo(3); assertThat(scenarioBox.getValue(0)).isEqualTo(27); assertThat(scenarioBox.getValue(1)).isEqualTo(28); assertThat(scenarioBox.getValue(2)).isEqualTo(29); }
public void combineWithSingleBox() { MarketDataBox<Integer> box = MarketDataBox.ofScenarioValues(27, 28, 29); MarketDataBox<Integer> otherBox = MarketDataBox.ofSingleValue(15); MarketDataBox<Integer> resultBox = box.combineWith(otherBox, (v1, v2) -> v1 + v2); assertThat(resultBox.isScenarioValue()).isTrue(); assertThat(resultBox.getScenarioCount()).isEqualTo(3); assertThat(resultBox.getValue(0)).isEqualTo(42); assertThat(resultBox.getValue(1)).isEqualTo(43); assertThat(resultBox.getValue(2)).isEqualTo(44); }
public void combineWithScenarioBox() { MarketDataBox<Integer> box = MarketDataBox.ofSingleValue(27); MarketDataBox<Integer> otherBox = MarketDataBox.ofScenarioValues(15, 16, 17); MarketDataBox<Integer> resultBox = box.combineWith(otherBox, (v1, v2) -> v1 + v2); assertThat(resultBox.isScenarioValue()).isTrue(); assertThat(resultBox.getScenarioCount()).isEqualTo(3); assertThat(resultBox.getValue(0)).isEqualTo(42); assertThat(resultBox.getValue(1)).isEqualTo(43); assertThat(resultBox.getValue(2)).isEqualTo(44); }
public void combineWithScenarioBox() { MarketDataBox<Integer> box = MarketDataBox.ofScenarioValues(27, 28, 29); MarketDataBox<Integer> otherBox = MarketDataBox.ofScenarioValues(15, 16, 17); MarketDataBox<Integer> resultBox = box.combineWith(otherBox, (v1, v2) -> v1 + v2); assertThat(resultBox.isScenarioValue()).isTrue(); assertThat(resultBox.getScenarioCount()).isEqualTo(3); assertThat(resultBox.getValue(0)).isEqualTo(42); assertThat(resultBox.getValue(1)).isEqualTo(44); assertThat(resultBox.getValue(2)).isEqualTo(46); }