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
A simple multi-valued map that wraps a
LinkedHashMap with LinkedList to store multiple values.
This class is NOT thread-safe.-
Nested Class Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a value to the list of values under the given key.voidAdd 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) deepCopy()Clone thisMultimapusing a deep copy, including each stored value list.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.booleanisEmpty()keySet()voidvoidSet a value under the given key, replacing any existing single or multiple values.voidSet 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, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
Multimap
public Multimap()Create an empty Multimap. -
Multimap
public Multimap(int initialCapacity) Create an empty Multimap with a given initial capacity.- Parameters:
initialCapacity- the initial capacity
-
-
Method Details
-
add
Add a value to the list of values under the given key.- Parameters:
key- the keyvalue- the value to add
-
addAll
Add multiple values to the list of values under the given key.- Parameters:
key- the keyvalues- the values to add
-
addAll
Add all values from the givenMultimapto the current ones.- Parameters:
values- the values to add
-
set
Set a value under the given key, replacing any existing single or multiple values.- Parameters:
key- the keyvalue- the value to set
-
setAll
Set multiple values under the given key, replacing any existing single or multiple values.- Parameters:
values- the values to set
-
deepCopy
Clone thisMultimapusing a deep copy, including each stored value list.- Returns:
- a deep copy of this
Multimap
-
forEachElement
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
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKeyin interfaceMap<K,V>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V>
-
get
-
put
-
remove
-
putAll
-
clear
public void clear() -
keySet
-
values
-
entrySet
-