/** * Obtains an instance from the specified list of values. * * @param <T> the type of the value * @param values the values, one value for each scenario * @return an instance with the specified values */ public static <T> DefaultScenarioArray<T> of(List<T> values) { return new DefaultScenarioArray<>(values); }
@Override public DefaultScenarioArray<T> build() { return new DefaultScenarioArray<>( values); }
/** * Obtains an instance from the specified array of values. * * @param <T> the type of the value * @param values the values, one value for each scenario * @return an instance with the specified values */ @SafeVarargs public static <T> DefaultScenarioArray<T> of(T... values) { return new DefaultScenarioArray<>(ImmutableList.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 <T> the type of the value * @param scenarioCount the number of scenarios * @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 <T> DefaultScenarioArray<T> of(int scenarioCount, IntFunction<T> valueFunction) { ArgChecker.notNegativeOrZero(scenarioCount, "scenarioCount"); ImmutableList.Builder<T> builder = ImmutableList.builder(); for (int i = 0; i < scenarioCount; i++) { builder.add(valueFunction.apply(i)); } return new DefaultScenarioArray<>(builder.build()); }