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 newListMultimap
that 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 newListMultimap
that uses the provided map and factory. It can generate a multimap based on arbitraryMap
andList
classes.The
factory
-generated andmap
classes determine the multimap iteration order. They also specify the behavior of theequals
,hashCode
, andtoString
methods for the multimap and its returned views. The multimap'sget
,removeAll
, andreplaceValues
methods returnRandomAccess
lists if the factory does. However, the multimap'sget
method 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
map
and the instances generated byfactory
are. 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
map
and 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
- ifmap
is not empty
-