Class Multimaps

java.lang.Object
org.glassfish.jersey.internal.guava.Multimaps

public final class Multimaps extends Object
Provides static methods acting on or generating a 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 Details

    • newListMultimap

      public static <K, V> ListMultimap<K,V> newListMultimap(Map<K,Collection<V>> map, Supplier<? extends List<V>> factory)
      Creates a new ListMultimap that uses the provided map and factory. It can generate a multimap based on arbitrary Map and List classes.

      The factory-generated and map classes determine the multimap iteration order. They also specify the behavior of the equals, hashCode, and toString methods for the multimap and its returned views. The multimap's get, removeAll, and replaceValues methods return RandomAccess lists if the factory does. However, the multimap's get method returns instances of a different class than does factory.get().

      The multimap is serializable if map, factory, the lists generated by factory, 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 by factory 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() and LinkedListMultimap#create() won't suffice.

      Note: the multimap assumes complete ownership over of map and the lists returned by factory. 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 values
      factory - supplier of new, empty lists that will each hold all values for a given key
      Throws:
      IllegalArgumentException - if map is not empty