Count how many times each element appears in the Collection. @param c a collection of values @return a map of the unique values in c to the count of those values.
(Collection<T> c)
| 590 | * @return a map of the unique values in c to the count of those values. |
| 591 | */ |
| 592 | public static <T> Map<T, Integer> multiset(Collection<T> c) { |
| 593 | Map<T, Integer> ret = new HashMap<T, Integer>(); |
| 594 | for (T t : c) { |
| 595 | Integer i = ret.get(t); |
| 596 | if (i == null) { |
| 597 | i = new Integer(0); |
| 598 | } |
| 599 | i += 1; |
| 600 | ret.put(t, i); |
| 601 | } |
| 602 | return ret; |
| 603 | } |
| 604 | |
| 605 | private static void printRec(Object o, String prefix) { |
| 606 | if (o instanceof Collection) { |
no test coverage detected