Package com.gengoai.collection.multimap
Interface Multimap<K,V>
-
- Type Parameters:
K
- the key type parameterV
- the value type parameter
- All Known Implementing Classes:
ArrayListMultimap
,BaseMultimap
,HashSetMultimap
,LinkedHashSetMultimap
,LinkedListMultimap
,ListMultimap
,SetMultimap
,TreeSetMultimap
public interface Multimap<K,V>
Maps keys to multiple values. Acts as aMap<K, Collection<V>
where individual implementations specify the type of collection, e.g. List, Set, etc.- Author:
- David B. Bracewell
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Map<K,Collection<V>>
asMap()
A map representation of the multimap where the values are represented in a Collection.default void
clear()
Clears all items in the multimapdefault boolean
contains(Object key, Object value)
Checks if the given key and value exist in the multimapdefault boolean
containsKey(Object key)
Checks if the key is contained in the multimapdefault boolean
containsValue(Object value)
Checks if the value exists in the multimapdefault Set<Map.Entry<K,V>>
entries()
A set of the entries in the multimapCollection<V>
get(Object key)
Gets the values mapped to by the given key.default boolean
isEmpty()
Checks if the multimap is empty, i.e.default Set<K>
keySet()
Gets the set of keys in the multimapdefault boolean
put(K key, V value)
Puts the key-value pair mapping in the multimapdefault void
putAll(@NonNull Multimap<? extends K,? extends V> multimap)
Put all key-value pairs in the multimapdefault void
putAll(@NonNull Map<? extends K,? extends Collection<? extends V>> map)
Put all key-value pairs in the multimapdefault void
putAll(K key, Iterable<? extends V> values)
Puts all values for a given keydefault boolean
remove(Object key, Object value)
Removes the given key-value pair from the multimapCollection<V>
removeAll(Object key)
Removes all values for the given key.void
replace(K key, Iterable<? extends V> values)
Replaces the values for a given key with the given new valuesdefault int
size()
The number of key-value mappings in the multimapdefault Collection<V>
values()
Provides a view of the values in the multimap
-
-
-
Method Detail
-
asMap
Map<K,Collection<V>> asMap()
A map representation of the multimap where the values are represented in a Collection.- Returns:
- the map
-
clear
default void clear()
Clears all items in the multimap
-
contains
default boolean contains(Object key, Object value)
Checks if the given key and value exist in the multimap- Parameters:
key
- the keyvalue
- the value- Returns:
- True if the key is mapped to value, false otherwise
-
containsKey
default boolean containsKey(Object key)
Checks if the key is contained in the multimap- Parameters:
key
- the key- Returns:
- True if the key is mapped to one or more values in the multimap
-
containsValue
default boolean containsValue(Object value)
Checks if the value exists in the multimap- Parameters:
value
- the value- Returns:
- True if there exists a key that is mapped to the value, false otherwise
-
entries
default Set<Map.Entry<K,V>> entries()
A set of the entries in the multimap- Returns:
- the set of key-value pairs in the multimap
-
get
Collection<V> get(Object key)
Gets the values mapped to by the given key. A new collection is created if the key does not exist in the multimap.- Parameters:
key
- the key- Returns:
- the collection of values.
-
isEmpty
default boolean isEmpty()
Checks if the multimap is empty, i.e. has no valid mappings.- Returns:
- True if it is empty
-
keySet
default Set<K> keySet()
Gets the set of keys in the multimap- Returns:
- the set of keys in the multimap
-
put
default boolean put(K key, V value)
Puts the key-value pair mapping in the multimap- Parameters:
key
- the keyvalue
- the value- Returns:
- true if the key-value pair was successfully added.
-
putAll
default void putAll(@NonNull @NonNull Map<? extends K,? extends Collection<? extends V>> map)
Put all key-value pairs in the multimap- Parameters:
map
- the map of key value pairs to add
-
putAll
default void putAll(@NonNull @NonNull Multimap<? extends K,? extends V> multimap)
Put all key-value pairs in the multimap- Parameters:
multimap
- the map of key value pairs to add
-
putAll
default void putAll(K key, Iterable<? extends V> values)
Puts all values for a given key- Parameters:
key
- the keyvalues
- the values
-
remove
default boolean remove(Object key, Object value)
Removes the given key-value pair from the multimap- Parameters:
key
- the keyvalue
- the value- Returns:
- true the key-value pair was successfully removed
-
removeAll
Collection<V> removeAll(Object key)
Removes all values for the given key.- Parameters:
key
- the key- Returns:
- the collection of values associated with the key
-
replace
void replace(K key, Iterable<? extends V> values)
Replaces the values for a given key with the given new values- Parameters:
key
- the keyvalues
- the values
-
size
default int size()
The number of key-value mappings in the multimap- Returns:
- the number of key-value mappings
-
values
default Collection<V> values()
Provides a view of the values in the multimap- Returns:
- the collection
-
-