### Question:
WeightedBalancer implements Balancer<I> { public static <T> void normalize(List<? extends Weight<T>> items){ double sumWeight = items.stream() .filter(item -> !Double.isNaN(item.getWeight())) .mapToDouble(Weight::getWeight) .map(weight -> Math.max(0.0D, weight)) .sum(); if (sumWeight < Double.MIN_NORMAL * 1E+9) { items.forEach(item -> item.setWeight(1.0 / items.size())); } else if (Double.isInfinite(sumWeight)) { long infiniteCount = items.stream() .filter(item -> item.getWeight() == Double.POSITIVE_INFINITY) .count(); for (Weight<T> item : items) { if (item.getWeight() == Double.POSITIVE_INFINITY) { item.setWeight(1.0D / infiniteCount); } else { item.setWeight(0); } } } else { for (Weight<T> item : items) { if (Double.isNaN(item.getWeight())) { item.setWeight(0); } else { item.setWeight(Math.max(0.0D, item.getWeight()) / sumWeight); } } } } WeightedBalancer(List<I> items, ToDoubleFunction<I> weightGetter);  WeightedBalancer(List<I> items, ToDoubleFunction<I> weightGetter, DoubleSupplier randomSupplier); static void normalize(List<? extends Weight<T>> items); @Override final void reBalance(); @Override final Optional<I> get(); @Override final Stream<I> nodes();  }### Answer:
@Test(groups = "unit") public void normalize(){ WeightedBalancer.Weight<String> weight1 = new WeightedBalancer.Weight<>(""); WeightedBalancer.Weight<String> weight2 = new WeightedBalancer.Weight<>(""); WeightedBalancer.Weight<String> weight3 = new WeightedBalancer.Weight<>(""); List<WeightedBalancer.Weight<String>> items = Arrays.asList(weight1, weight2, weight3); weight1.setWeight(1); weight2.setWeight(1); weight3.setWeight(0); WeightedBalancer.normalize(items); assertEquals(weight1.getWeight(), 0.5, 0.000001); assertEquals(weight2.getWeight(), 0.5, 0.000001); assertEquals(weight3.getWeight(), 0.0, 0.000001); weight1.setWeight(3); weight2.setWeight(1); weight3.setWeight(1); WeightedBalancer.normalize(items); assertEquals(weight1.getWeight(), 0.6, 0.000001); assertEquals(weight2.getWeight(), 0.2, 0.000001); assertEquals(weight3.getWeight(), 0.2, 0.000001); weight1.setWeight(3); weight2.setWeight(2); weight3.setWeight(Double.NaN); WeightedBalancer.normalize(items); assertEquals(weight1.getWeight(), 0.6, 0.000001); assertEquals(weight2.getWeight(), 0.4, 0.000001); assertEquals(weight3.getWeight(), 0.0, 0.000001); weight1.setWeight(Double.POSITIVE_INFINITY); weight2.setWeight(Double.POSITIVE_INFINITY); weight3.setWeight(Double.NaN); WeightedBalancer.normalize(items); assertEquals(weight1.getWeight(), 0.5, 0.000001); assertEquals(weight2.getWeight(), 0.5, 0.000001); assertEquals(weight3.getWeight(), 0.0, 0.000001); }