Interface MultiMap<K,V>
-
- Type Parameters:
K
- the type of keys maintained by this multimapV
- the type of mapped values
public interface MultiMap<K,V>
A MultiMap is like aMap
except that a key can be bound to multiple values. It is similar toMap<K,Collection<V>>
, but not identical because in a multimap, each key and value is stored as an individual entry. This means that the iteration order andsize()
will be different. If you actually need theMap<K,Collection<V>>
semantics, then call themap()
method.- Author:
- cdivilly
- See Also:
size()
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default boolean
containsKey(java.lang.Object key)
Test if this object contains the specified key.java.util.Collection<java.util.Map.Entry<K,V>>
entries()
Get each key value pair in this multi-map.default V
get(java.lang.Object key)
Get the first value associated with the specified key.default boolean
isEmpty()
Returns true if thisMultiMap
contains no key-value mappings.default java.util.Set<K>
keySet()
The set of keys in this objectjava.util.Map<K,java.util.Collection<V>>
map()
Represent thisMultiMap
as aMap<K,Collection<V>>
data structure, where values are grouped by key.default int
size()
The number of entries in thisMultiMap
.java.util.Collection<V>
values(java.lang.Object key)
Get all the values associated with the specified key.
-
-
-
Method Detail
-
containsKey
default boolean containsKey(java.lang.Object key)
Test if this object contains the specified key.- Parameters:
key
- The key to search for- Returns:
- true if the key exists, false otherwise
-
entries
java.util.Collection<java.util.Map.Entry<K,V>> entries()
Get each key value pair in this multi-map.- Returns:
Collection
of allMap.Entry
s in this multi map.
-
get
default V get(java.lang.Object key)
Get the first value associated with the specified key.- Parameters:
key
- The key to search for- Returns:
- The first value associated with the key, or null if no values are associated with the key
-
isEmpty
default boolean isEmpty()
Returns true if thisMultiMap
contains no key-value mappings.- Returns:
- true if this
MultiMap
contains no key-value mappings
-
keySet
default java.util.Set<K> keySet()
The set of keys in this object- Returns:
- The key set
-
map
java.util.Map<K,java.util.Collection<V>> map()
Represent thisMultiMap
as aMap<K,Collection<V>>
data structure, where values are grouped by key.- Returns:
Map
instance
-
size
default int size()
The number of entries in thisMultiMap
. Note that this method returns the number of entries, not the number of keys as aMap
would. Consider the followingMultiMap
{ a = b, c = d, a = e }
Thesize()
of thisMultiMap
is3
. Note that theMap.size()
value returned by theMap
instance returned from themap()
method would be2
, because there are only two distinct keys.- Returns:
- the number of values in the multimap
-
-