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

public Class ImmutableListMultimap<K, V>

extends ImmutableMultimap<K, V>
implements ListMultimap<K, V>
Class Inheritance
All Implemented Interfaces
com.google.common.collect.ListMultimap, com.google.common.collect.Multimap
Known Direct Subclasses
com.google.common.collect.EmptyImmutableListMultimap
Annotations
@GwtCompatible
serializable:true
emulated:true
@ElementTypesAreNonnullByDefault
Imports
com.google.common.annotations.GwtCompatible, .GwtIncompatible, .J2ktIncompatible, com.google.errorprone.annotations.CanIgnoreReturnValue, .DoNotCall, com.google.errorprone.annotations.concurrent.LazyInit, com.google.j2objc.annotations.RetainedWith, java.io.IOException, .InvalidObjectException, .ObjectInputStream, .ObjectOutputStream, java.util.Collection, .Comparator, .Map, .Map.Entry, java.util.function.Function, java.util.stream.Collector, .Stream, javax.annotation.CheckForNull, org.checkerframework.checker.nullness.qual.Nullable

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

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
ImmutableListMultimap.Builder<K, V>

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

Field Summary

Modifier and TypeField and Description
private transient ImmutableListMultimap<V, K>
private static final long
Inherited from com.google.common.collect.ImmutableMultimap:
mapsize

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public static <K, V> ImmutableListMultimap.Builder<K, V>
public static <K, V> ImmutableListMultimap<K, V>
copyOf(Multimap<? extends K, ? extends V> multimap)

Hides com.google.common.collect.ImmutableMultimap.copyOf.

Returns an immutable multimap containing the same mappings as multimap.
public static <K, V> ImmutableListMultimap<K, V>
copyOf(Iterable<? extends Map.Entry<? extends K, ? extends V>> entries)

Hides com.google.common.collect.ImmutableMultimap.copyOf.

Returns an immutable multimap containing the specified entries.
public static <T extends @Nullable Object, K, V> Collector<T, ?, ImmutableListMultimap<K, V>>
flatteningToImmutableListMultimap(Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends Stream<? extends V>> valuesFunction)

Returns a Collector accumulating entries into an ImmutableListMultimap.

pack-priv static <K, V> ImmutableListMultimap<K, V>
fromMapEntries(Collection<? extends Map.Entry<? extends K, ? extends Collection<? extends V>>> mapEntries, Comparator<? super V> valueComparator)

Creates an ImmutableListMultimap from an asMap.entrySet.

public ImmutableList<V>
get(K key)

Implements abstract com.google.common.collect.ImmutableMultimap.get.

Implements com.google.common.collect.ListMultimap.get, com.google.common.collect.Multimap.get.

Returns an immutable list of the values for the given key.
public ImmutableListMultimap<V, K>
inverse()

Implements abstract com.google.common.collect.ImmutableMultimap.inverse.

Returns an immutable multimap which is the inverse of this one.
private ImmutableListMultimap<V, K>
public static <K, V> ImmutableListMultimap<K, V>
of()

Hides com.google.common.collect.ImmutableMultimap.of.

Returns the empty multimap.
public static <K, V> ImmutableListMultimap<K, V>
of(K k1, V v1)

Hides com.google.common.collect.ImmutableMultimap.of.

Returns an immutable multimap containing a single entry.
public static <K, V> ImmutableListMultimap<K, V>
of(K k1, V v1, K k2, V v2)

Hides com.google.common.collect.ImmutableMultimap.of.

Returns an immutable multimap containing the given entries, in order.
public static <K, V> ImmutableListMultimap<K, V>
of(K k1, V v1, K k2, V v2, K k3, V v3)

Hides com.google.common.collect.ImmutableMultimap.of.

Returns an immutable multimap containing the given entries, in order.
public static <K, V> ImmutableListMultimap<K, V>
of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)

Hides com.google.common.collect.ImmutableMultimap.of.

Returns an immutable multimap containing the given entries, in order.
public static <K, V> ImmutableListMultimap<K, V>
of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)

Hides com.google.common.collect.ImmutableMultimap.of.

Returns an immutable multimap containing the given entries, in order.
private void
public final ImmutableList<V>
removeAll(Object key)

Overrides com.google.common.collect.ImmutableMultimap.removeAll.

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

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

Overrides com.google.common.collect.ImmutableMultimap.replaceValues.

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

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the multimap unmodified.
public static <T extends @Nullable Object, K, V> Collector<T, ?, ImmutableListMultimap<K, V>>
toImmutableListMultimap(Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction)

Returns a Collector that accumulates elements into an ImmutableListMultimap whose keys and values are the result of applying the provided mapping functions to the input elements.

private void
Inherited from com.google.common.collect.ImmutableMultimap:
asMapclearcontainsKeycontainsValuecreateAsMapcreateEntriescreateKeyscreateKeySetcreateValuesentriesentryIteratorentrySpliteratorforEachisPartialViewkeyskeySetputputAllputAllremovesizevalueIteratorvalues

Field Detail

inverseback to summary
private transient ImmutableListMultimap<V, K> inverse
Annotations
@LazyInit
@RetainedWith
@CheckForNull
serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.google.common.collect.ImmutableMultimap.serialVersionUID.

Annotations
@GwtIncompatible
@J2ktIncompatible

Constructor Detail

ImmutableListMultimapback to summary
pack-priv ImmutableListMultimap(ImmutableMap<K, ImmutableList<V>> map, int size)

Method Detail

builderback to summary
public static <K, V> ImmutableListMultimap.Builder<K, V> builder()

Hides com.google.common.collect.ImmutableMultimap.builder.

Returns a new builder. The generated builder is equivalent to the builder created by the Builder constructor.

copyOfback to summary
public static <K, V> ImmutableListMultimap<K, V> copyOf(Multimap<? extends K, ? extends V> multimap)

Hides com.google.common.collect.ImmutableMultimap.copyOf.

Returns an immutable multimap containing the same mappings as multimap. The generated multimap's key and value orderings correspond to the iteration ordering of the multimap.asMap() view.

Despite the method name, this method attempts to avoid actually copying the data when it is safe to do so. The exact circumstances under which a copy will or will not be performed are undocumented and subject to change.

Exceptions
NullPointerException:
if any key or value in multimap is null
copyOfback to summary
public static <K, V> ImmutableListMultimap<K, V> copyOf(Iterable<? extends Map.Entry<? extends K, ? extends V>> entries)

Hides com.google.common.collect.ImmutableMultimap.copyOf.

Returns an immutable multimap containing the specified entries. The returned multimap iterates over keys in the order they were first encountered in the input, and the values for each key are iterated in the order they were encountered.

Exceptions
NullPointerException:
if any key, value, or entry is null
Since
19.0
flatteningToImmutableListMultimapback to summary
public static <T extends @Nullable Object, K, V> Collector<T, ?, ImmutableListMultimap<K, V>> flatteningToImmutableListMultimap(Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends Stream<? extends V>> valuesFunction)

Returns a Collector accumulating entries into an ImmutableListMultimap. Each input element is mapped to a key and a stream of values, each of which are put into the resulting Multimap, in the encounter order of the stream and the encounter order of the streams of values.

Example:

static final ImmutableListMultimap<Character, Character> FIRST_LETTER_MULTIMAP =
    Stream.of("banana", "apple", "carrot", "asparagus", "cherry")
        .collect(
            flatteningToImmutableListMultimap(
                 str -> str.charAt(0),
                 str -> str.substring(1).chars().mapToObj(c -> (char) c));

// is equivalent to

static final ImmutableListMultimap<Character, Character> FIRST_LETTER_MULTIMAP =
    ImmutableListMultimap.<Character, Character>builder()
        .putAll('b', Arrays.asList('a', 'n', 'a', 'n', 'a'))
        .putAll('a', Arrays.asList('p', 'p', 'l', 'e'))
        .putAll('c', Arrays.asList('a', 'r', 'r', 'o', 't'))
        .putAll('a', Arrays.asList('s', 'p', 'a', 'r', 'a', 'g', 'u', 's'))
        .putAll('c', Arrays.asList('h', 'e', 'r', 'r', 'y'))
        .build();

}
Since
21.0
fromMapEntriesback to summary
pack-priv static <K, V> ImmutableListMultimap<K, V> fromMapEntries(Collection<? extends Map.Entry<? extends K, ? extends Collection<? extends V>>> mapEntries, Comparator<? super V> valueComparator)

Creates an ImmutableListMultimap from an asMap.entrySet.

getback to summary
public ImmutableList<V> get(K key)

Implements abstract com.google.common.collect.ImmutableMultimap.get.

Implements com.google.common.collect.ListMultimap.get, com.google.common.collect.Multimap.get.

Returns an immutable list of the values for the given key. If no mappings in the multimap have the provided key, an empty immutable list is returned. The values are in the same order as the parameters used to build this multimap.

Annotations
@Override
inverseback to summary
public ImmutableListMultimap<V, K> inverse()

Implements abstract com.google.common.collect.ImmutableMultimap.inverse.

Doc from com.google.common.collect.ImmutableMultimap.inverse.

Returns an immutable multimap which is the inverse of this one. For every key-value mapping in the original, the result will have a mapping with key and value reversed.

Because an inverse of a list multimap can contain multiple pairs with the same key and value, this method returns an ImmutableListMultimap rather than the ImmutableMultimap specified in the ImmutableMultimap class.

Annotations
@Override
Since
11.0
invertback to summary
private ImmutableListMultimap<V, K> invert()
ofback to summary
public static <K, V> ImmutableListMultimap<K, V> of()

Hides com.google.common.collect.ImmutableMultimap.of.

Returns the empty multimap.

Performance note: the instance returned is a singleton.

Annotations
@SuppressWarnings:unchecked
ofback to summary
public static <K, V> ImmutableListMultimap<K, V> of(K k1, V v1)

Hides com.google.common.collect.ImmutableMultimap.of.

Returns an immutable multimap containing a single entry.

ofback to summary
public static <K, V> ImmutableListMultimap<K, V> of(K k1, V v1, K k2, V v2)

Hides com.google.common.collect.ImmutableMultimap.of.

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

ofback to summary
public static <K, V> ImmutableListMultimap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3)

Hides com.google.common.collect.ImmutableMultimap.of.

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

ofback to summary
public static <K, V> ImmutableListMultimap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)

Hides com.google.common.collect.ImmutableMultimap.of.

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

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

Hides com.google.common.collect.ImmutableMultimap.of.

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

readObjectback to summary
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException
Annotations
@GwtIncompatible
@J2ktIncompatible
removeAllback to summary
public final ImmutableList<V> removeAll(Object key)

Overrides com.google.common.collect.ImmutableMultimap.removeAll.

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

Deprecated

Unsupported operation.

Guaranteed to throw an exception and leave the multimap unmodified.

Returns:ImmutableList<V>

Doc from com.google.common.collect.Multimap.removeAll.

the values that were removed (possibly empty). The returned collection may be modifiable, but updating it will have no effect on the multimap.

Annotations
@CanIgnoreReturnValue
@Deprecated
@Override
@DoNotCall:Always throws UnsupportedOperationException
Exceptions
UnsupportedOperationException:
always
replaceValuesback to summary
public final ImmutableList<V> replaceValues(K key, Iterable<? extends V> values)

Overrides com.google.common.collect.ImmutableMultimap.replaceValues.

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

Deprecated

Unsupported operation.

Guaranteed to throw an exception and leave the multimap unmodified.

Returns:ImmutableList<V>

Doc from com.google.common.collect.Multimap.replaceValues.

the collection of replaced values, or an empty collection if no values were previously associated with the key. The collection may be modifiable, but updating it will have no effect on the multimap.

Annotations
@CanIgnoreReturnValue
@Deprecated
@Override
@DoNotCall:Always throws UnsupportedOperationException
Exceptions
UnsupportedOperationException:
always
toImmutableListMultimapback to summary
public static <T extends @Nullable Object, K, V> Collector<T, ?, ImmutableListMultimap<K, V>> toImmutableListMultimap(Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction)

Returns a Collector that accumulates elements into an ImmutableListMultimap whose keys and values are the result of applying the provided mapping functions to the input elements.

For streams with defined encounter order (as defined in the Ordering section of the java.util.stream Javadoc), that order is preserved, but entries are grouped by key.

Example:

static final Multimap<Character, String> FIRST_LETTER_MULTIMAP =
    Stream.of("banana", "apple", "carrot", "asparagus", "cherry")
        .collect(toImmutableListMultimap(str -> str.charAt(0), str -> str.substring(1)));

// is equivalent to

static final Multimap<Character, String> FIRST_LETTER_MULTIMAP =
    new ImmutableListMultimap.Builder<Character, String>()
        .put('b', "anana")
        .putAll('a', "pple", "sparagus")
        .putAll('c', "arrot", "herry")
        .build();
Since
21.0
writeObjectback to summary
private void writeObject(ObjectOutputStream stream) throws IOException
Annotations
@GwtIncompatible
@J2ktIncompatible
Serial data
number of distinct keys, and then for each distinct key: the key, the number of values for that key, and the key's values
com.google.common.collect back to summary

public final Class ImmutableListMultimap.Builder<K, V>

extends ImmutableMultimap.Builder<K, V>
Class Inheritance

A builder for creating immutable ListMultimap instances, especially public static final multimaps ("constant multimaps"). Example:
static final Multimap<String, Integer> STRING_TO_INTEGER_MULTIMAP =
    new ImmutableListMultimap.Builder<String, Integer>()
        .put("one", 1)
        .putAll("several", 1, 2, 3)
        .putAll("many", 1, 2, 3, 4, 5)
        .build();

Builder instances can be reused; it is safe to call build multiple times to build multiple multimaps in series. Each multimap contains the key-value mappings in the previously created multimaps.

Since
2.0

Field Summary

Inherited from com.google.common.collect.ImmutableMultimap.Builder:
builderMapkeyComparatorvalueComparator

Constructor Summary

AccessConstructor and Description
public
Builder()

Creates a new builder.

Method Summary

Modifier and TypeMethod and Description
public ImmutableListMultimap<K, V>
build()

Overrides com.google.common.collect.ImmutableMultimap.Builder.build.

Returns a newly-created immutable list multimap.
pack-priv ImmutableListMultimap.Builder<K, V>
public ImmutableListMultimap.Builder<K, V>
orderKeysBy(Comparator<? super K> keyComparator)

Overrides com.google.common.collect.ImmutableMultimap.Builder.orderKeysBy.

Specifies the ordering of the generated multimap's keys.
public ImmutableListMultimap.Builder<K, V>
orderValuesBy(Comparator<? super V> valueComparator)

Overrides com.google.common.collect.ImmutableMultimap.Builder.orderValuesBy.

Specifies the ordering of the generated multimap's values for each key.
public ImmutableListMultimap.Builder<K, V>
put(K key, V value)

Overrides com.google.common.collect.ImmutableMultimap.Builder.put.

Adds a key-value mapping to the built multimap.
public ImmutableListMultimap.Builder<K, V>
put(Map.Entry<? extends K, ? extends V> entry)

Overrides com.google.common.collect.ImmutableMultimap.Builder.put.

Adds an entry to the built multimap.
public ImmutableListMultimap.Builder<K, V>
putAll(Iterable<? extends Map.Entry<? extends K, ? extends V>> entries)

Overrides com.google.common.collect.ImmutableMultimap.Builder.putAll.

Adds entries to the built multimap.
public ImmutableListMultimap.Builder<K, V>
putAll(K key, Iterable<? extends V> values)

Overrides com.google.common.collect.ImmutableMultimap.Builder.putAll.

Stores a collection of values with the same key in the built multimap.
public ImmutableListMultimap.Builder<K, V>
putAll(K key, V... values)

Overrides com.google.common.collect.ImmutableMultimap.Builder.putAll.

Stores an array of values with the same key in the built multimap.
public ImmutableListMultimap.Builder<K, V>
putAll(Multimap<? extends K, ? extends V> multimap)

Overrides com.google.common.collect.ImmutableMultimap.Builder.putAll.

Stores another multimap's entries in the built multimap.
Inherited from com.google.common.collect.ImmutableMultimap.Builder:
newMutableValueCollection

Constructor Detail

Builderback to summary
public Builder()

Creates a new builder. The returned builder is equivalent to the builder generated by ImmutableListMultimap#builder.

Method Detail

buildback to summary
public ImmutableListMultimap<K, V> build()

Overrides com.google.common.collect.ImmutableMultimap.Builder.build.

Returns a newly-created immutable list multimap.

Annotations
@Override
combineback to summary
pack-priv ImmutableListMultimap.Builder<K, V> combine(ImmutableMultimap.Builder<K, V> other)

Overrides com.google.common.collect.ImmutableMultimap.Builder.combine.

Annotations
@CanIgnoreReturnValue
@Override
orderKeysByback to summary
public ImmutableListMultimap.Builder<K, V> orderKeysBy(Comparator<? super K> keyComparator)

Overrides com.google.common.collect.ImmutableMultimap.Builder.orderKeysBy.

Doc from com.google.common.collect.ImmutableMultimap.Builder.orderKeysBy.

Specifies the ordering of the generated multimap's keys.

Annotations
@CanIgnoreReturnValue
@Override
Since
8.0
orderValuesByback to summary
public ImmutableListMultimap.Builder<K, V> orderValuesBy(Comparator<? super V> valueComparator)

Overrides com.google.common.collect.ImmutableMultimap.Builder.orderValuesBy.

Doc from com.google.common.collect.ImmutableMultimap.Builder.orderValuesBy.

Specifies the ordering of the generated multimap's values for each key.

Annotations
@CanIgnoreReturnValue
@Override
Since
8.0
putback to summary
public ImmutableListMultimap.Builder<K, V> put(K key, V value)

Overrides com.google.common.collect.ImmutableMultimap.Builder.put.

Doc from com.google.common.collect.ImmutableMultimap.Builder.put.

Adds a key-value mapping to the built multimap.

Annotations
@CanIgnoreReturnValue
@Override
putback to summary
public ImmutableListMultimap.Builder<K, V> put(Map.Entry<? extends K, ? extends V> entry)

Overrides com.google.common.collect.ImmutableMultimap.Builder.put.

Doc from com.google.common.collect.ImmutableMultimap.Builder.put.

Adds an entry to the built multimap.

Annotations
@CanIgnoreReturnValue
@Override
Since
11.0
putAllback to summary
public ImmutableListMultimap.Builder<K, V> putAll(Iterable<? extends Map.Entry<? extends K, ? extends V>> entries)

Overrides com.google.common.collect.ImmutableMultimap.Builder.putAll.

Doc from com.google.common.collect.ImmutableMultimap.Builder.putAll.

Adds entries to the built multimap.

Annotations
@CanIgnoreReturnValue
@Override
Since
19.0
putAllback to summary
public ImmutableListMultimap.Builder<K, V> putAll(K key, Iterable<? extends V> values)

Overrides com.google.common.collect.ImmutableMultimap.Builder.putAll.

Doc from com.google.common.collect.ImmutableMultimap.Builder.putAll.

Stores a collection of values with the same key in the built multimap.

Annotations
@CanIgnoreReturnValue
@Override
putAllback to summary
public ImmutableListMultimap.Builder<K, V> putAll(K key, V... values)

Overrides com.google.common.collect.ImmutableMultimap.Builder.putAll.

Doc from com.google.common.collect.ImmutableMultimap.Builder.putAll.

Stores an array of values with the same key in the built multimap.

Annotations
@CanIgnoreReturnValue
@Override
putAllback to summary
public ImmutableListMultimap.Builder<K, V> putAll(Multimap<? extends K, ? extends V> multimap)

Overrides com.google.common.collect.ImmutableMultimap.Builder.putAll.

Doc from com.google.common.collect.ImmutableMultimap.Builder.putAll.

Stores another multimap's entries in the built multimap. The generated multimap's key and value orderings correspond to the iteration ordering of the multimap.asMap() view, with new keys and values following any existing keys and values.

Annotations
@CanIgnoreReturnValue
@Override