Class Multimaps
Multimap.
See the Guava User Guide article on
Multimaps.
- Since:
- 2.0 (imported from Google Collections Library)
- Author:
- Jared Levy, Robert Konigsberg, Mike Bostock, Louis Wasserman
-
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> ListMultimap<K, V> newListMultimap(Map<K, Collection<V>> map, Supplier<? extends List<V>> factory) Creates a newListMultimapthat uses the provided map and factory.
-
Method Details
-
newListMultimap
public static <K,V> ListMultimap<K,V> newListMultimap(Map<K, Collection<V>> map, Supplier<? extends List<V>> factory) Creates a newListMultimapthat uses the provided map and factory. It can generate a multimap based on arbitraryMapandListclasses.The
factory-generated andmapclasses determine the multimap iteration order. They also specify the behavior of theequals,hashCode, andtoStringmethods for the multimap and its returned views. The multimap'sget,removeAll, andreplaceValuesmethods returnRandomAccesslists if the factory does. However, the multimap'sgetmethod returns instances of a different class than doesfactory.get().The multimap is serializable if
map,factory, the lists generated byfactory, and the multimap contents are all serializable.The multimap is not threadsafe when any concurrent operations update the multimap, even if
mapand the instances generated byfactoryare. Concurrent read operations will work correctly. To allow concurrent update operations, wrap the multimap with a call to#synchronizedListMultimap.Call this method only when the simpler methods
ArrayListMultimap#create()andLinkedListMultimap#create()won't suffice.Note: the multimap assumes complete ownership over of
mapand the lists returned byfactory. Those objects should not be manually updated, they should be empty when provided, and they should not use soft, weak, or phantom references.- Parameters:
map- place to store the mapping from each key to its corresponding valuesfactory- supplier of new, empty lists that will each hold all values for a given key- Throws:
IllegalArgumentException- ifmapis not empty
-