Interface ImmutableMultimap<K,V>
- Type Parameters:
K- the type of keys maintained by this multimapV- the type of values that can be associated with the keys
- All Known Subinterfaces:
Multimap<K,V>
- All Known Implementing Classes:
ArtifactMultimap,ImmutableListMultimap,ImmutableSetMultimap,LinkedSetMultimap,ListMultimap,SetMultimap,TreeMultimap
public interface ImmutableMultimap<K,V>
ImmutableMultimap is an implementation of a multimap that does not allow modification after its creation.
This class provides a way to safely share multimap instances without worrying about changes to the underlying data.
It supports read-only operations from the Multimap interface.
- Since:
- 10.0
-
Method Summary
Modifier and TypeMethodDescriptionMap<K,Collection<V>> asMap()Returns a view of the mappings contained in this multimap as a map from each key to its corresponding values.booleancontainsKey(K key) Returnstrueif this multimap contains one or more keys to the specified value.copy()Creates a deep copy of this multimap.entries()Returns a collection view of all key-value pairs contained in this multimap.Retrieves the collection of values associated with the specified key in this multimap.inverse()Creates an inverse view of this multimap.booleanisEmpty()Returnstrueif this multimap contains no key-value mappings.keySet()Returns the set of keys contained in this multimap.intsize()Returns the total number of key-value pairs in the multimap.values()Returns a collection view of all values associated with keys in this multimap.
-
Method Details
-
get
Retrieves the collection of values associated with the specified key in this multimap.- Parameters:
key- the key whose associated values are to be returned- Returns:
- the collection of values associated with the specified key, or an empty collection if no values are associated with the key
-
keySet
Returns the set of keys contained in this multimap.- Returns:
- the set of keys contained in this multimap
-
containsKey
Returnstrueif this multimap contains one or more keys to the specified value.- Parameters:
key- key whose presence in this multimap is to be tested- Returns:
trueif this multimap contains a mapping for the specified key
-
values
Collection<V> values()Returns a collection view of all values associated with keys in this multimap.- Returns:
- a collection view of all values contained in this multimap
-
isEmpty
boolean isEmpty()Returnstrueif this multimap contains no key-value mappings.- Returns:
trueif this multimap contains no key-value mappings
-
asMap
Map<K,Collection<V>> asMap()Returns a view of the mappings contained in this multimap as a map from each key to its corresponding values.- Returns:
- a map view of the mappings contained in this multimap
-
entries
Collection<Map.Entry<K,V>> entries()Returns a collection view of all key-value pairs contained in this multimap. Each key-value pair is represented as a Map.Entry. If the multimap allows duplicate values, a separate Map.Entry will be included for each duplicate value.- Returns:
- a collection view of all key-value pairs contained in this multimap
-
size
int size()Returns the total number of key-value pairs in the multimap.- Returns:
- the total number of key-value pairs
-
copy
ImmutableMultimap<K,V> copy()Creates a deep copy of this multimap.- Returns:
- a new multimap instance containing the same key-value mappings as this multimap
-
inverse
ImmutableMultimap<V,K> inverse()Creates an inverse view of this multimap. In the inverse multimap, each value in the original multimap becomes a key in the new multimap, and each key in the original becomes part of the set of values associated with the new key. The inverse multimap is also immutable.- Returns:
- a new ImmutableMultimap instance where the roles of keys and values are swapped
-