Top Description Inners Constructors Methods
com.google.common.collect

public final Class Multimaps

extends Object
Class Inheritance
Annotations
@GwtCompatible
emulated:true
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkNotNull, com.google.common.collect.CollectPreconditions.checkNonnegative, .CollectPreconditions.checkRemove, .NullnessCasts.uncheckedCastNullableTToT, java.util.Objects.requireNonNull

Provides static methods acting on or generating a Multimap.

See the Guava User Guide article on Multimaps.

Authors
Jared Levy, Robert Konigsberg, Mike Bostock, Louis Wasserman
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
Multimaps.AsMap<K extends @Nullable Object, V extends @Nullable Object>

A skeleton implementation of Multimap#asMap().

private static class
private static class
private static class
private static class
pack-priv abstract static class
Multimaps.Entries<K extends @Nullable Object, V extends @Nullable Object>

A skeleton implementation of Multimap#entries().

pack-priv static class
private static class
private static class
private static class
private static class
private static class
private static class
private static class

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <K extends @Nullable Object, V extends @Nullable Object> Map<K, List<V>>
asMap(ListMultimap<K, V> multimap)

Returns multimap.asMap(), with its type corrected from Map<K, Collection<V>> to Map<K, List<V>>.

public static <K extends @Nullable Object, V extends @Nullable Object> Map<K, Set<V>>
asMap(SetMultimap<K, V> multimap)

Returns multimap.asMap(), with its type corrected from Map<K, Collection<V>> to Map<K, Set<V>>.

public static <K extends @Nullable Object, V extends @Nullable Object> Map<K, SortedSet<V>>
asMap(SortedSetMultimap<K, V> multimap)

Returns multimap.asMap(), with its type corrected from Map<K, Collection<V>> to Map<K, SortedSet<V>>.

public static <K extends @Nullable Object, V extends @Nullable Object> Map<K, Collection<V>>
asMap(Multimap<K, V> multimap)

Returns multimap.asMap().

pack-priv static boolean
equalsImpl(Multimap<?, ?> multimap, Object object)

public static <K extends @Nullable Object, V extends @Nullable Object> Multimap<K, V>
filterEntries(Multimap<K, V> unfiltered, Predicate<? super Map.Entry<K, V>> entryPredicate)

Returns a multimap containing the mappings in unfiltered that satisfy a predicate.

public static <K extends @Nullable Object, V extends @Nullable Object> SetMultimap<K, V>
filterEntries(SetMultimap<K, V> unfiltered, Predicate<? super Map.Entry<K, V>> entryPredicate)

Returns a multimap containing the mappings in unfiltered that satisfy a predicate.

private static <K extends @Nullable Object, V extends @Nullable Object> Multimap<K, V>
filterFiltered(FilteredMultimap<K, V> multimap, Predicate<? super Map.Entry<K, V>> entryPredicate)

Support removal operations when filtering a filtered multimap.

private static <K extends @Nullable Object, V extends @Nullable Object> SetMultimap<K, V>
filterFiltered(FilteredSetMultimap<K, V> multimap, Predicate<? super Map.Entry<K, V>> entryPredicate)

Support removal operations when filtering a filtered multimap.

public static <K extends @Nullable Object, V extends @Nullable Object> Multimap<K, V>
filterKeys(Multimap<K, V> unfiltered, final Predicate<? super K> keyPredicate)

Returns a multimap containing the mappings in unfiltered whose keys satisfy a predicate.

public static <K extends @Nullable Object, V extends @Nullable Object> SetMultimap<K, V>
filterKeys(SetMultimap<K, V> unfiltered, final Predicate<? super K> keyPredicate)

Returns a multimap containing the mappings in unfiltered whose keys satisfy a predicate.

public static <K extends @Nullable Object, V extends @Nullable Object> ListMultimap<K, V>
filterKeys(ListMultimap<K, V> unfiltered, final Predicate<? super K> keyPredicate)

Returns a multimap containing the mappings in unfiltered whose keys satisfy a predicate.

public static <K extends @Nullable Object, V extends @Nullable Object> Multimap<K, V>
filterValues(Multimap<K, V> unfiltered, final Predicate<? super V> valuePredicate)

Returns a multimap containing the mappings in unfiltered whose values satisfy a predicate.

public static <K extends @Nullable Object, V extends @Nullable Object> SetMultimap<K, V>
filterValues(SetMultimap<K, V> unfiltered, final Predicate<? super V> valuePredicate)

Returns a multimap containing the mappings in unfiltered whose values satisfy a predicate.

public static <T extends @Nullable Object, K extends @Nullable Object, V extends @Nullable Object, M extends Multimap<K, V>> Collector<T, ?, M>
flatteningToMultimap(Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends Stream<? extends V>> valueFunction, Supplier<M> multimapSupplier)

Returns a Collector accumulating entries into a Multimap generated from the specified supplier.

public static <K extends @Nullable Object, V extends @Nullable Object> SetMultimap<K, V>
forMap(Map<K, V>
the backing map for the returned multimap view
map
)

Returns a multimap view of the specified map.

public static <K, V> ImmutableListMultimap<K, V>

Returns:

ImmutableListMultimap mapping the result of evaluating the function keyFunction on each value in the input collection to that value
index
(Iterable<V>
the values to use when constructing the ImmutableListMultimap
values
,
Function<? super V, K>
the function used to produce the key for each value
keyFunction
)

Creates an index ImmutableListMultimap that contains the results of applying a specified function to each item in an Iterable of values.

public static <K, V> ImmutableListMultimap<K, V>

Returns:

ImmutableListMultimap mapping the result of evaluating the function keyFunction on each value in the input collection to that value
index
(Iterator<V>
the values to use when constructing the ImmutableListMultimap
values
,
Function<? super V, K>
the function used to produce the key for each value
keyFunction
)

Creates an index ImmutableListMultimap that contains the results of applying a specified function to each item in an Iterator of values.

public static <K extends @Nullable Object, V extends @Nullable Object, M extends Multimap<K, V>> M

Returns:

dest
invertFrom
(Multimap<? extends V, ? extends K>
any multimap
source
,
M
the multimap to copy into; usually empty
dest
)

Copies each key-value mapping in source into dest, with its key and value reversed.

public static <K extends @Nullable Object, V extends @Nullable Object> ListMultimap<K, V>
newListMultimap(Map<K, Collection<V>>
place to store the mapping from each key to its corresponding values
map
,
final Supplier<? extends List<V>>
supplier of new, empty lists that will each hold all values for a given key
factory
)

Creates a new ListMultimap that uses the provided map and factory.

public static <K extends @Nullable Object, V extends @Nullable Object> Multimap<K, V>
newMultimap(Map<K, Collection<V>>
place to store the mapping from each key to its corresponding values
map
,
final Supplier<? extends Collection<V>>
supplier of new, empty collections that will each hold all values for a given key
factory
)

Creates a new Multimap backed by map, whose internal value collections are generated by factory.

public static <K extends @Nullable Object, V extends @Nullable Object> SetMultimap<K, V>
newSetMultimap(Map<K, Collection<V>>
place to store the mapping from each key to its corresponding values
map
,
final Supplier<? extends Set<V>>
supplier of new, empty sets that will each hold all values for a given key
factory
)

Creates a new SetMultimap that uses the provided map and factory.

public static <K extends @Nullable Object, V extends @Nullable Object> SortedSetMultimap<K, V>
newSortedSetMultimap(Map<K, Collection<V>>
place to store the mapping from each key to its corresponding values
map
,
final Supplier<? extends SortedSet<V>>
supplier of new, empty sorted sets that will each hold all values for a given key
factory
)

Creates a new SortedSetMultimap that uses the provided map and factory.

public static <K extends @Nullable Object, V extends @Nullable Object> ListMultimap<K, V>

Returns:

a synchronized view of the specified multimap
synchronizedListMultimap
(ListMultimap<K, V>
the multimap to be wrapped
multimap
)

Returns a synchronized (thread-safe) ListMultimap backed by the specified multimap.

public static <K extends @Nullable Object, V extends @Nullable Object> Multimap<K, V>

Returns:

a synchronized view of the specified multimap
synchronizedMultimap
(Multimap<K, V>
the multimap to be wrapped in a synchronized view
multimap
)

Returns a synchronized (thread-safe) multimap backed by the specified multimap.

public static <K extends @Nullable Object, V extends @Nullable Object> SetMultimap<K, V>

Returns:

a synchronized view of the specified multimap
synchronizedSetMultimap
(SetMultimap<K, V>
the multimap to be wrapped
multimap
)

Returns a synchronized (thread-safe) SetMultimap backed by the specified multimap.

public static <K extends @Nullable Object, V extends @Nullable Object> SortedSetMultimap<K, V>

Returns:

a synchronized view of the specified multimap
synchronizedSortedSetMultimap
(SortedSetMultimap<K, V>
the multimap to be wrapped
multimap
)

Returns a synchronized (thread-safe) SortedSetMultimap backed by the specified multimap.

public static <T extends @Nullable Object, K extends @Nullable Object, V extends @Nullable Object, M extends Multimap<K, V>> Collector<T, ?, M>
toMultimap(Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction, Supplier<M> multimapSupplier)

Returns a Collector accumulating entries into a Multimap generated from the specified supplier.

public static <K extends @Nullable Object, V1 extends @Nullable Object, V2 extends @Nullable Object> Multimap<K, V2>
transformEntries(Multimap<K, V1> fromMap, Maps.EntryTransformer<? super K, ? super V1, V2> transformer)

Returns a view of a multimap whose values are derived from the original multimap's entries.

public static <K extends @Nullable Object, V1 extends @Nullable Object, V2 extends @Nullable Object> ListMultimap<K, V2>
transformEntries(ListMultimap<K, V1> fromMap, Maps.EntryTransformer<? super K, ? super V1, V2> transformer)

Returns a view of a ListMultimap whose values are derived from the original multimap's entries.

public static <K extends @Nullable Object, V1 extends @Nullable Object, V2 extends @Nullable Object> Multimap<K, V2>
transformValues(Multimap<K, V1> fromMultimap, final Function<? super V1, V2> function)

Returns a view of a multimap where each value is transformed by a function.

public static <K extends @Nullable Object, V1 extends @Nullable Object, V2 extends @Nullable Object> ListMultimap<K, V2>
transformValues(ListMultimap<K, V1> fromMultimap, final Function<? super V1, V2> function)

Returns a view of a ListMultimap where each value is transformed by a function.

private static <K extends @Nullable Object, V extends @Nullable Object> Collection<Map.Entry<K, V>>

Returns:

an unmodifiable view of the entries
unmodifiableEntries
(Collection<Map.Entry<K, V>>
the entries for which to return an unmodifiable view
entries
)

Returns an unmodifiable view of the specified collection of entries.

public static <K extends @Nullable Object, V extends @Nullable Object> ListMultimap<K, V>

Returns:

an unmodifiable view of the specified multimap
unmodifiableListMultimap
(ListMultimap<K, V>
the multimap for which an unmodifiable view is to be returned
delegate
)

Returns an unmodifiable view of the specified ListMultimap.

public static <K, V> ListMultimap<K, V>
unmodifiableListMultimap(ImmutableListMultimap<K, V> delegate)

Deprecated no need to use this
Simply returns its argument.
public static <K extends @Nullable Object, V extends @Nullable Object> Multimap<K, V>

Returns:

an unmodifiable view of the specified multimap
unmodifiableMultimap
(Multimap<K, V>
the multimap for which an unmodifiable view is to be returned
delegate
)

Returns an unmodifiable view of the specified multimap.

public static <K, V> Multimap<K, V>
unmodifiableMultimap(ImmutableMultimap<K, V> delegate)

Deprecated no need to use this
Simply returns its argument.
public static <K extends @Nullable Object, V extends @Nullable Object> SetMultimap<K, V>

Returns:

an unmodifiable view of the specified multimap
unmodifiableSetMultimap
(SetMultimap<K, V>
the multimap for which an unmodifiable view is to be returned
delegate
)

Returns an unmodifiable view of the specified SetMultimap.

public static <K, V> SetMultimap<K, V>
unmodifiableSetMultimap(ImmutableSetMultimap<K, V> delegate)

Deprecated no need to use this
Simply returns its argument.
public static <K extends @Nullable Object, V extends @Nullable Object> SortedSetMultimap<K, V>

Returns:

an unmodifiable view of the specified multimap
unmodifiableSortedSetMultimap
(SortedSetMultimap<K, V>
the multimap for which an unmodifiable view is to be returned
delegate
)

Returns an unmodifiable view of the specified SortedSetMultimap.

private static <V extends @Nullable Object> Collection<V>

Returns:

an unmodifiable view of the collection
unmodifiableValueCollection
(Collection<V>
the collection for which to return an unmodifiable view
collection
)

Returns an unmodifiable view of the specified collection, preserving the interface for instances of SortedSet, Set, List and Collection, in that order of preference.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait