@Override protected void eval() { int index = sample(); val = values.get(index).get(); currentNumberOfValues.set(index, currentNumberOfValues.get(index) + 1L); if (currentNumberOfValues.get(index).equals(counts.get(index))) { removeValue(index); } }
/** * Creates an instance of {@link ObjectGenerator} which generates each value exactly specified number of times. * Values are generated using weighted distribution until depleted. When all values are generated specified number * of times and {@link ObjectGenerator#next()} is invoked, * {@link io.smartcat.ranger.core.ExactWeightedValue.ExactWeightedValueDepletedException * ExactWeightedValueDepletedException} is thrown. * * @param pairs List of values with corresponding counts. * @param <T> Type instance of {@link ObjectGenerator} will generate. * @return An instance of {@link ObjectGenerator} which generates each value exactly specified number of times. */ public static <T> ObjectGenerator<T> exactly(List<CountPair<T>> pairs) { return wrap(new ExactWeightedValue<>(unwrapCountPairs(pairs))); }
/** * Creates an instance of {@link ObjectGenerator} which generates each value exactly specified number of times. * Values are generated using weighted distribution until depleted. When all values are generated specified number * of times and {@link ObjectGenerator#next()} is invoked, * {@link io.smartcat.ranger.core.ExactWeightedValue.ExactWeightedValueDepletedException * ExactWeightedValueDepletedException} is thrown. * * @param pairs List of values with corresponding counts. * @param <T> Type instance of {@link ObjectGenerator} will generate. * @return An instance of {@link ObjectGenerator} which generates each value exactly specified number of times. */ public static <T> ObjectGenerator<T> exactly(List<CountPair<T>> pairs) { return wrap(new ExactWeightedValue<>(unwrapCountPairs(pairs))); }
@Override protected void eval() { int index = sample(); val = values.get(index).get(); currentNumberOfValues.set(index, currentNumberOfValues.get(index) + 1L); if (currentNumberOfValues.get(index).equals(counts.get(index))) { removeValue(index); } }
/** * Exact weighted value definition. * * @return Weighted value definition rule. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public Rule exactWeightedValue() { return Sequence(function("exactly", bracketList(countValuePair())), push(new ExactWeightedValue<>((List) pop()))); }
/** * Exact weighted value definition. * * @return Weighted value definition rule. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public Rule exactWeightedValue() { return Sequence(function("exactly", bracketList(countValuePair())), push(new ExactWeightedValue<>((List) pop()))); }