@SuppressWarnings({ "unchecked", "rawtypes" }) private static <T> List<WeightedValuePair<T>> unwrapWeightPairs(List<WeightPair<T>> pairs) { List<WeightedValuePair<T>> result = new ArrayList<>(); for (WeightPair pair : pairs) { result.add(new WeightedValuePair<>(pair.value, pair.weight)); } return result; }
/** * Constructs discrete weighted value with specified <code>values</code> and <code>weights</code>. * * @param weightedValuePairs List of values with their corresponding weights. */ public WeightedValue(List<WeightedValuePair<T>> weightedValuePairs) { if (weightedValuePairs == null || weightedValuePairs.isEmpty()) { throw new IllegalArgumentException("List of weighted values cannot be null nor empty."); } this.enumeratedDistribution = new EnumeratedDistribution<>(mapToPairList(weightedValuePairs)); this.values = weightedValuePairs.stream().map(x -> x.getValue()).collect(Collectors.toList()); }
/** * Weighted value pair definition. * * @return Weighted value pair definition rule. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public Rule weightedValuePair() { return Sequence(function(Sequence(value(), comma(), numberLiteral())), push(new WeightedValuePair((Value) pop(1), ((Number) pop()).doubleValue()))); }
/** * Weighted value pair definition. * * @return Weighted value pair definition rule. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public Rule weightedValuePair() { return Sequence(function(Sequence(value(), comma(), numberLiteral())), push(new WeightedValuePair((Value) pop(1), ((Number) pop()).doubleValue()))); }
@SuppressWarnings({ "unchecked", "rawtypes" }) private static <T> List<WeightedValuePair<T>> unwrapWeightPairs(List<WeightPair<T>> pairs) { List<WeightedValuePair<T>> result = new ArrayList<>(); for (WeightPair pair : pairs) { result.add(new WeightedValuePair<>(pair.value, pair.weight)); } return result; }
/** * Constructs discrete weighted value with specified <code>values</code> and <code>weights</code>. * * @param weightedValuePairs List of values with their corresponding weights. */ public WeightedValue(List<WeightedValuePair<T>> weightedValuePairs) { if (weightedValuePairs == null || weightedValuePairs.isEmpty()) { throw new IllegalArgumentException("List of weighted values cannot be null nor empty."); } this.enumeratedDistribution = new EnumeratedDistribution<>(mapToPairList(weightedValuePairs)); this.values = weightedValuePairs.stream().map(x -> x.getValue()).collect(Collectors.toList()); }