/** * Adds the value to the collection given by map.get(key). A new collection is created using the * supplied CollectionFactory. */ public static <K, V, C extends Collection<V>> void putIntoValueCollection( Map<K, C> map, K key, V value, CollectionFactory<V> cf) { C c = map.get(key); if (c == null) { c = ErasureUtils.<C>uncheckedCast(cf.newCollection()); map.put(key, c); } c.add(value); }