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

public abstract Class ImmutableMultimap<K, V>

extends BaseImmutableMultimap<K, V>
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
com.google.common.collect.ImmutableSetMultimap, com.google.common.collect.ImmutableListMultimap
Annotations
@GwtCompatible
emulated:true
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkNotNull, com.google.common.collect.CollectPreconditions.checkEntryNotNull, .Maps.immutableEntry, java.util.Objects.requireNonNull

A Multimap whose contents will never change, with many other important properties detailed at ImmutableCollection.

Warning

avoid direct usage of ImmutableMultimap as a type (as with Multimap itself). Prefer subtypes such as ImmutableSetMultimap or ImmutableListMultimap, which have well-defined equals semantics, thus avoiding a common source of bugs and confusion.

Note

every ImmutableMultimap offers an inverse view, so there is no need for a distinct ImmutableBiMultimap type.

Key-grouped iteration. All view collections follow the same iteration order. In all current implementations, the iteration order always keeps multiple entries with the same key together. Any creation method that would customarily respect insertion order (such as copyOf(Multimap)) instead preserves key-grouped order by inserting entries for an existing key immediately after the last entry having that key.

See the Guava User Guide article on immutable collections.

Author
Jared Levy
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ImmutableMultimap.Builder<K, V>

A builder for creating immutable multimap instances, especially public static final multimaps ("constant multimaps").

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

Field Summary

Modifier and TypeField and Description
pack-priv final transient ImmutableMap<K, ? extends ImmutableCollection<V>>
private static final long
pack-priv final transient int

Constructor Summary

AccessConstructor and Description
pack-priv
ImmutableMultimap(ImmutableMap<K, ? extends ImmutableCollection<V>> map, int size)

Method Summary

Modifier and TypeMethod and Description
public ImmutableMap<K, Collection<V>>
asMap()

Overrides com.google.common.collect.AbstractMultimap.asMap.

Implements com.google.common.collect.Multimap.asMap.

Returns an immutable map that associates each key with its corresponding values in the multimap.
public static <K, V> ImmutableMultimap.Builder<K, V>
builder()

Returns a new builder.

public final void
clear()

Implements com.google.common.collect.Multimap.clear.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the multimap unmodified.
public boolean
containsKey(Object key)

Implements com.google.common.collect.Multimap.containsKey.

Returns true if this multimap contains at least one key-value pair with the key key.
public boolean
containsValue(Object value)

Overrides com.google.common.collect.AbstractMultimap.containsValue.

Implements com.google.common.collect.Multimap.containsValue.

Returns true if this multimap contains at least one key-value pair with the value value.
public static <K, V> ImmutableMultimap<K, V>
copyOf(Multimap<? extends K, ? extends V> multimap)

Returns an immutable multimap containing the same mappings as multimap, in the "key-grouped" iteration order described in the class documentation.

public static <K, V> ImmutableMultimap<K, V>
copyOf(Iterable<? extends Map.Entry<? extends K, ? extends V>> entries)

Returns an immutable multimap containing the specified entries.

pack-priv Map<K, Collection<V>>
pack-priv ImmutableCollection<Map.Entry<K, V>>
pack-priv ImmutableMultiset<K>
pack-priv Set<K>
pack-priv ImmutableCollection<V>
public ImmutableCollection<Map.Entry<K, V>>
entries()

Overrides com.google.common.collect.AbstractMultimap.entries.

Implements com.google.common.collect.Multimap.entries.

Returns an immutable collection of all key-value pairs in the multimap.
pack-priv UnmodifiableIterator<Map.Entry<K, V>>
pack-priv Spliterator<Map.Entry<K, V>>
public void
forEach(BiConsumer<? super K, ? super V> action)

Overrides default com.google.common.collect.Multimap.forEach.

Performs the given action for all key-value pairs contained in this multimap.
public abstract ImmutableCollection<V>
get(K key)

Redeclares com.google.common.collect.Multimap.get.

Returns an immutable collection of the values for the given key.
public abstract ImmutableMultimap<V, K>
inverse()

Returns an immutable multimap which is the inverse of this one.

pack-priv boolean
isPartialView()

Returns true if this immutable multimap's implementation contains references to user-created objects that aren't accessible via this multimap's methods.

public ImmutableMultiset<K>
keys()

Overrides com.google.common.collect.AbstractMultimap.keys.

Implements com.google.common.collect.Multimap.keys.

Returns an immutable multiset containing all the keys in this multimap, in the same order and with the same frequencies as they appear in this multimap; to get only a single occurrence of each key, use keySet.
public ImmutableSet<K>
keySet()

Overrides com.google.common.collect.AbstractMultimap.keySet.

Implements com.google.common.collect.Multimap.keySet.

Returns an immutable set of the distinct keys in this multimap, in the same order as they appear in this multimap.
public static <K, V> ImmutableMultimap<K, V>
of()

Returns an empty multimap.

public static <K, V> ImmutableMultimap<K, V>
of(K k1, V v1)

Returns an immutable multimap containing a single entry.

public static <K, V> ImmutableMultimap<K, V>
of(K k1, V v1, K k2, V v2)

Returns an immutable multimap containing the given entries, in order.

public static <K, V> ImmutableMultimap<K, V>
of(K k1, V v1, K k2, V v2, K k3, V v3)

Returns an immutable multimap containing the given entries, in the "key-grouped" insertion order described in the class documentation.

public static <K, V> ImmutableMultimap<K, V>
of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)

Returns an immutable multimap containing the given entries, in the "key-grouped" insertion order described in the class documentation.

public static <K, V> ImmutableMultimap<K, V>
of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)

Returns an immutable multimap containing the given entries, in the "key-grouped" insertion order described in the class documentation.

public final boolean
put(K key, V value)

Overrides com.google.common.collect.AbstractMultimap.put.

Implements com.google.common.collect.Multimap.put.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the multimap unmodified.
public final boolean
putAll(K key, Iterable<? extends V> values)

Overrides com.google.common.collect.AbstractMultimap.putAll.

Implements com.google.common.collect.Multimap.putAll.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the multimap unmodified.
public final boolean
putAll(Multimap<? extends K, ? extends V> multimap)

Overrides com.google.common.collect.AbstractMultimap.putAll.

Implements com.google.common.collect.Multimap.putAll.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the multimap unmodified.
public final boolean
remove(Object key, Object value)

Overrides com.google.common.collect.AbstractMultimap.remove.

Implements com.google.common.collect.Multimap.remove.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the multimap unmodified.
public ImmutableCollection<V>
removeAll(Object key)

Implements com.google.common.collect.Multimap.removeAll.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the multimap unmodified.
public ImmutableCollection<V>
replaceValues(K key, Iterable<? extends V> values)

Overrides com.google.common.collect.AbstractMultimap.replaceValues.

Implements com.google.common.collect.Multimap.replaceValues.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the multimap unmodified.
public int
size()

Implements com.google.common.collect.Multimap.size.

Returns the number of key-value pairs in this multimap.
pack-priv UnmodifiableIterator<V>
public ImmutableCollection<V>
values()

Overrides com.google.common.collect.AbstractMultimap.values.

Implements com.google.common.collect.Multimap.values.

Returns an immutable collection of the values in this multimap.