@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -823812830: // values return ((DoubleScenarioArray) bean).getValues(); } return super.propertyGet(bean, propertyName, quiet); }
@Override public DoubleScenarioArray build() { return new DoubleScenarioArray( values); }
public void create_fromList() { List<Double> values = ImmutableList.of(1d, 2d, 3d); DoubleScenarioArray test = DoubleScenarioArray.of(values); assertThat(test.getValues()).isEqualTo(DoubleArray.of(1d, 2d, 3d)); assertThat(test.getScenarioCount()).isEqualTo(3); assertThat(test.get(0)).isEqualTo(1d); assertThat(test.get(1)).isEqualTo(2d); assertThat(test.get(2)).isEqualTo(3); assertThat(test.stream().collect(toList())).containsExactly(1d, 2d, 3d); }
public void create() { DoubleArray values = DoubleArray.of(1, 2, 3); DoubleScenarioArray test = DoubleScenarioArray.of(values); assertThat(test.getValues()).isEqualTo(values); assertThat(test.getScenarioCount()).isEqualTo(3); assertThat(test.get(0)).isEqualTo(1d); assertThat(test.get(1)).isEqualTo(2d); assertThat(test.get(2)).isEqualTo(3); assertThat(test.stream().collect(toList())).containsExactly(1d, 2d, 3d); }
public void create_fromFunction() { List<Double> values = ImmutableList.of(1d, 2d, 3d); DoubleScenarioArray test = DoubleScenarioArray.of(3, i -> values.get(i)); assertThat(test.getValues()).isEqualTo(DoubleArray.of(1d, 2d, 3d)); assertThat(test.getScenarioCount()).isEqualTo(3); assertThat(test.get(0)).isEqualTo(1d); assertThat(test.get(1)).isEqualTo(2d); assertThat(test.get(2)).isEqualTo(3); assertThat(test.stream().collect(toList())).containsExactly(1d, 2d, 3d); }
/** * Obtains an instance from the specified array of values. * * @param values the values, one value for each scenario * @return an instance with the specified values */ public static DoubleScenarioArray of(DoubleArray values) { return new DoubleScenarioArray(values); }
/** * Obtains an instance from the specified list of values. * * @param values the values, one value for each scenario * @return an instance with the specified values */ public static DoubleScenarioArray of(List<Double> values) { return new DoubleScenarioArray(DoubleArray.copyOf(values)); }
/** * Obtains an instance using a function to create the entries. * <p> * The function is passed the scenario index and returns the value for that index. * * @param size the number of elements * @param valueFunction the function used to obtain each value * @return an instance initialized using the function * @throws IllegalArgumentException is size is zero or less */ public static DoubleScenarioArray of(int size, IntToDoubleFunction valueFunction) { ArgChecker.notNegativeOrZero(size, "size"); return new DoubleScenarioArray(DoubleArray.of(size, valueFunction)); }