/** * 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()); }
/** * 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()); }
private List<Pair<Value<T>, Double>> mapToPairList(List<WeightedValuePair<T>> weightedValuePairs) { return weightedValuePairs.stream().map(x -> new Pair<Value<T>, Double>(x.getValue(), x.getWeight())) .collect(Collectors.toList()); }
private List<Pair<Value<T>, Double>> mapToPairList(List<WeightedValuePair<T>> weightedValuePairs) { return weightedValuePairs.stream().map(x -> new Pair<Value<T>, Double>(x.getValue(), x.getWeight())) .collect(Collectors.toList()); }