Multinomial implements Sampler<T>, Iterable<T> { public void add(T value, double w) { Preconditions.checkNotNull(value); Preconditions.checkArgument(!items.containsKey(value)); int n = this.weight.size(); if (n == 1) { weight.add(w); values.add(value); items.put(value, 1); } else { weight.add(weight.get(n / 2)); values.add(values.get(n / 2)); items.put(values.get(n / 2), n); n++; items.put(value, n); this.weight.add(w); values.add(value); while (n > 1) { n /= 2; this.weight.set(n, this.weight.get(n) + w); } } } Multinomial();  Multinomial(Multiset<T> counts);  Multinomial(Iterable<WeightedThing<T>> things); void add(T value, double w); double getWeight(T value); double getProbability(T value); double getWeight(); void delete(T value); void set(T value, double newP); @Override T sample(); T sample(double u); @Override Iterator<T> iterator();  }
@Test(expected=NullPointerException.class) public void testNoNullValuesAllowed() { Multinomial<Integer> table = new Multinomial<Integer>(); table.add(null, 1); }
@Test(expected=NullPointerException.class) public void testNoNullValuesAllowed() { Multinomial<Integer> table = new Multinomial<>(); table.add(null, 1); }