@Test public void testUniformGeneratesUniformDistribution() { final double uniformWeight = 10.0D; WeightedElement<String> first = new WeightedElement<>("first", uniformWeight); WeightedElement<String> second = new WeightedElement<>("second", uniformWeight); WeightedElement<String> third = new WeightedElement<>("third", uniformWeight); List<WeightedElement<String>> weightedElements = Arrays.asList(first, second, third); DistributedList<String> manualSet = new DistributedList<>(weightedElements); List<String> elements = Arrays.asList("first", "second", "third"); DistributedList<String> uniformSet = DistributedList.uniform(elements); assertEquals(manualSet, uniformSet); }
public static <T> DistributedList<T> uniform(final Collection<T> underlyingSet) { return new DistributedList<>( underlyingSet.stream() .map(WeightedElement::withDefaultWeight) .collect(Collectors.toList())); }
DistributedList { public static <T> DistributedList<T> uniform(final Collection<T> underlyingSet) { return new DistributedList<>( underlyingSet.stream() .map(WeightedElement::withDefaultWeight) .collect(Collectors.toList())); } }
DistributedList { public static <T> DistributedList<T> uniform(final Collection<T> underlyingSet) { return new DistributedList<>( underlyingSet.stream() .map(WeightedElement::withDefaultWeight) .collect(Collectors.toList())); } DistributedList(final List<WeightedElement<T>> underlyingWeights); }
DistributedList { public static <T> DistributedList<T> uniform(final Collection<T> underlyingSet) { return new DistributedList<>( underlyingSet.stream() .map(WeightedElement::withDefaultWeight) .collect(Collectors.toList())); } DistributedList(final List<WeightedElement<T>> underlyingWeights); static DistributedList<T> singleton(final T element); static DistributedList<T> weightedOrDefault(final Collection<T> underlyingSet); static DistributedList<T> uniform(final Collection<T> underlyingSet); @SuppressWarnings("unchecked") static DistributedList<T> empty(); List<WeightedElement<T>> distributedList(); T pickRandomly(RandomNumberGenerator random); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); Stream<T> stream(); List<T> list(); boolean isEmpty(); }
DistributedList { public static <T> DistributedList<T> uniform(final Collection<T> underlyingSet) { return new DistributedList<>( underlyingSet.stream() .map(WeightedElement::withDefaultWeight) .collect(Collectors.toList())); } DistributedList(final List<WeightedElement<T>> underlyingWeights); static DistributedList<T> singleton(final T element); static DistributedList<T> weightedOrDefault(final Collection<T> underlyingSet); static DistributedList<T> uniform(final Collection<T> underlyingSet); @SuppressWarnings("unchecked") static DistributedList<T> empty(); List<WeightedElement<T>> distributedList(); T pickRandomly(RandomNumberGenerator random); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); Stream<T> stream(); List<T> list(); boolean isEmpty();  }