Multimap interface. This class represents a multimap as a map
that associates each key with a collection of values. All methods of Multimap are
supported, including those specified as optional in the interface.
To implement a multimap, a subclass must define the method createCollection(), which
creates an empty collection of values for a key.
The multimap constructor takes a map that has a single entry for each distinct key. When you
insert a key-value pair with a key that isn't already in the multimap, AbstractMapBasedMultimap calls createCollection() to create the collection of values
for that key. The subclass should not call createCollection() directly, and a new
instance should be created every time the method is called.
For example, the subclass could pass a java. during construction, and
createCollection() could return a java., in which case the
multimap's iterators would propagate through the keys and values in sorted order.
Keys and values may be null, as long as the underlying collection classes support null elements.
The collections created by createCollection() may or may not allow duplicates. If the
collection, such as a Set, does not support duplicates, an added key-value pair will
replace an existing pair with the same key and value, if such a pair is present. With collections
like List that allow duplicates, the collection will keep the existing key-value pairs
while adding a new pair.
This class is not threadsafe when any concurrent operations update the multimap, even if the
underlying map and createCollection() method return threadsafe classes. Concurrent read
operations will work correctly. To allow concurrent update operations, wrap your multimap with a
call to Multimaps#synchronizedMultimap.
For serialization to work, the subclass must specify explicit readObject and writeObject methods.
| Modifier and Type | Class and Description |
|---|---|
| private class | |
| private abstract class | |
| private class | |
| private class | |
| private class | |
| private class | AbstractMapBasedMultimap.
List decorator that stays in sync with the multimap values for a key and supports rapid random access. |
| private class | |
| private class | |
| pack-priv class | AbstractMapBasedMultimap.
Collection decorator that stays in sync with the multimap values for a key. |
| pack-priv class | AbstractMapBasedMultimap.
List decorator that stays in sync with the multimap values for a key. |
| pack-priv class | |
| pack-priv class | AbstractMapBasedMultimap.
Set decorator that stays in sync with the multimap values for a key. |
| pack-priv class | AbstractMapBasedMultimap.
SortedSet decorator that stays in sync with the multimap values for a key. |
| Modifier and Type | Field and Description |
|---|---|
| private transient Map | |
| private static final long | |
| private transient int |
| Access | Constructor and Description |
|---|---|
| protected | AbstractMapBasedMultimap(Map<K, Collection<V>>
place to store the mapping from each key to its corresponding values map)Creates a new multimap that uses the provided map. |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv Map | |
| public void | clear()
Implements com. |
| public boolean | containsKey(Object key)
Implements com. true if this multimap contains at least one key-value pair with the key key.
|
| pack-priv Map | |
| pack-priv abstract Collection | Returns: an empty collection of valuesCreates the collection of values for a single key. |
| pack-priv Collection | Returns: an empty collection of valueskey to associate with values in the collection key)Creates the collection of values for an explicitly provided key. |
| pack-priv Collection | |
| pack-priv Multiset | |
| pack-priv Set | |
| pack-priv final Map | |
| pack-priv final Set | |
| pack-priv Collection | |
| pack-priv Collection | |
| public Collection | entries()
Overrides com. Implements com. Entry
instances.
|
| pack-priv Iterator | Returns: an iterator across map entriesImplements abstract com. entries().iterator() and
values().iterator().
|
| pack-priv Spliterator | |
| public void | forEach(BiConsumer<? super K, ? super V> action)
Overrides default com. |
| public Collection | get(K key)
Implements com. key in this multimap, if any.
|
| private Collection | |
| private static <E extends @Nullable Object> Iterator | |
| public boolean | put(K key, V value)
Overrides com. Implements com. |
| public Collection | removeAll(Object key)
Implements com. key.
|
| private void | |
| public Collection | replaceValues(K key, Iterable<? extends V> values)
Overrides com. Implements com. |
| pack-priv final void | |
| public int | size()
Implements com. |
| pack-priv <E extends @Nullable Object> Collection | |
| pack-priv Iterator | |
| public Collection | values()
Overrides com. Implements com. values().size() == size()).
|
| pack-priv Spliterator | |
| pack-priv Collection | wrapCollection(K key, Collection<V> collection)
Generates a decorated collection that remains consistent with the values in the multimap for the provided key. |
| pack-priv final List |