@SuppressWarnings({ "unchecked", "rawtypes" }) private static <T> List<CountValuePair<T>> unwrapCountPairs(List<CountPair<T>> pairs) { List<CountValuePair<T>> result = new ArrayList<>(); for (CountPair pair : pairs) { result.add(new CountValuePair<>(pair.value, pair.count)); } return result; }
/** * Constructs discrete weighted value with specified <code>values</code> and <code>weights</code>. * * @param countValuePairs List of values with their corresponding weights. */ public ExactWeightedValue(List<CountValuePair<T>> countValuePairs) { if (countValuePairs == null || countValuePairs.isEmpty()) { throw new IllegalArgumentException("List of count value pairs cannot be null nor empty."); } this.distribution = new UniformDistribution(); this.counts = new ArrayList<>(); this.currentNumberOfValues = new ArrayList<>(); this.values = new ArrayList<>(); this.currentTotalCount = 0; for (CountValuePair<T> pair : countValuePairs) { currentTotalCount += pair.getCount(); counts.add(pair.getCount()); currentNumberOfValues.add(0L); values.add(pair.getValue()); } this.totalCount = currentTotalCount; }
/** * Constructs discrete weighted value with specified <code>values</code> and <code>weights</code>. * * @param countValuePairs List of values with their corresponding weights. */ public ExactWeightedValue(List<CountValuePair<T>> countValuePairs) { if (countValuePairs == null || countValuePairs.isEmpty()) { throw new IllegalArgumentException("List of count value pairs cannot be null nor empty."); } this.distribution = new UniformDistribution(); this.counts = new ArrayList<>(); this.currentNumberOfValues = new ArrayList<>(); this.values = new ArrayList<>(); this.currentTotalCount = 0; for (CountValuePair<T> pair : countValuePairs) { currentTotalCount += pair.getCount(); counts.add(pair.getCount()); currentNumberOfValues.add(0L); values.add(pair.getValue()); } this.totalCount = currentTotalCount; }
/** * Count value pair definition. * * @return Count value pair definition rule. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public Rule countValuePair() { return Sequence(function(Sequence(value(), comma(), longLiteral())), push(new CountValuePair((Value) pop(1), (Long) pop()))); }
@SuppressWarnings({ "unchecked", "rawtypes" }) private static <T> List<CountValuePair<T>> unwrapCountPairs(List<CountPair<T>> pairs) { List<CountValuePair<T>> result = new ArrayList<>(); for (CountPair pair : pairs) { result.add(new CountValuePair<>(pair.value, pair.count)); } return result; }
/** * Count value pair definition. * * @return Count value pair definition rule. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public Rule countValuePair() { return Sequence(function(Sequence(value(), comma(), longLiteral())), push(new CountValuePair((Value) pop(1), (Long) pop()))); }