Package discord4j.rest.util
Class Multimap<K,V>
- java.lang.Object
-
- discord4j.rest.util.Multimap<K,V>
-
- Type Parameters:
K- the key typeV- the value type
public class Multimap<K,V> extends Object implements Map<K,List<V>>
A simple multi-valued map that wraps aLinkedHashMapwithLinkedListto store multiple values. This class is NOT thread-safe.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(K key, V value)Add a value to the list of values under the given key.voidaddAll(Multimap<K,V> values)Add all values from the givenMultimapto the current ones.voidaddAll(K key, Collection<? extends V> values)Add multiple values to the list of values under the given key.voidclear()booleancontainsKey(Object key)booleancontainsValue(Object value)Multimap<K,V>deepCopy()Clone thisMultimapusing a deep copy, including each stored value list.Set<Map.Entry<K,List<V>>>entrySet()voidforEachElement(BiConsumer<? super K,? super V> action)Performs the given action for each element, meaning once per each K-V entry in this Multimap, until all entries have been processed or the action throws an exception.List<V>get(Object key)booleanisEmpty()Set<K>keySet()List<V>put(K key, List<V> value)voidputAll(Map<? extends K,? extends List<V>> m)List<V>remove(Object key)voidset(K key, V value)Set a value under the given key, replacing any existing single or multiple values.voidsetAll(Map<K,V> values)Set multiple values under the given key, replacing any existing single or multiple values.intsize()Collection<List<V>>values()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Method Detail
-
add
public void add(K key, V value)
Add a value to the list of values under the given key.- Parameters:
key- the keyvalue- the value to add
-
addAll
public void addAll(K key, Collection<? extends V> values)
Add multiple values to the list of values under the given key.- Parameters:
key- the keyvalues- the values to add
-
addAll
public void addAll(Multimap<K,V> values)
Add all values from the givenMultimapto the current ones.- Parameters:
values- the values to add
-
set
public void set(K key, V value)
Set a value under the given key, replacing any existing single or multiple values.- Parameters:
key- the keyvalue- the value to set
-
setAll
public void setAll(Map<K,V> values)
Set multiple values under the given key, replacing any existing single or multiple values.- Parameters:
values- the values to set
-
deepCopy
public Multimap<K,V> deepCopy()
Clone thisMultimapusing a deep copy, including each stored value list.- Returns:
- a deep copy of this
Multimap
-
forEachElement
public void forEachElement(BiConsumer<? super K,? super V> action)
Performs the given action for each element, meaning once per each K-V entry in this Multimap, until all entries have been processed or the action throws an exception.- Parameters:
action- The action to be performed for each entry- Throws:
NullPointerException- if the specified action is nullConcurrentModificationException- if an entry is found to be removed during iteration- Since:
- 3.1.1
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKeyin interfaceMap<K,V>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValuein interfaceMap<K,V>
-
-