Counter implements Serializable { public Counter() { reset(); } Counter(); void reset(); void incrementCount(T object, double increment); void incrementCount(T object); void decrementCount(T object, double decrement); void decrementCount(T object); double getCount(T object); double mean(); double std(); @SuppressWarnings("unchecked") Pair<T, Double> getMax(); @SuppressWarnings("unchecked") Pair<T, Double> getMin(); Set<T> items(); boolean contains(T item); int size(); Set<T> keySet(); double getTotal(); @SuppressWarnings("unchecked") List<T> getSortedItems(); List<T> getSortedItemsHighestFirst(); Counter<T> copy();  }
@Test public void testCounter() { Counter<String> cnt = new Counter<>(); cnt.incrementCount("a"); cnt.incrementCount("a"); cnt.incrementCount("z"); cnt.incrementCount("a"); cnt.incrementCount("a"); cnt.incrementCount("a"); cnt.incrementCount("c"); cnt.incrementCount("c"); cnt.incrementCount("c"); cnt.incrementCount("c"); assertEquals("a", cnt.getMax().getFirst()); assertEquals("z", cnt.getMin().getFirst()); assertEquals("z", cnt.getSortedItems().get(0)); assertEquals("a", cnt.getSortedItemsHighestFirst().get(0)); }