Interface SetMultiMap<K,V>
public interface SetMultiMap<K,V>
A thread-safe multimap that associates each key with a
Set of values, ensuring uniqueness.
for example
SetMultiMap<Integer, String> map = SetMultiMap.of();
map.put(1, "a");
map.put(1, "a");
map.put(1, "b");
map.size(); // size == 1
map.sizeValue(); // sizeValue == 2
Set<String> set2 = map.get(2); // is null
Set<String> set2 = map.of(2); // is empty set
set2.add("2 - a");
set2.add("2 - a");
map.sizeValue(); // sizeValue == 3
map.containsValue("a"); // true
map.containsValue("b"); // true
var collection = map.clearAll(1);
collection.isEmpty(); // true
map.size(); // size == 2
Set<Integer> keySet = this.map.keySet();
- Author:
- 渔民小镇
- date:
- 2023-12-07
-
Method Summary
Modifier and TypeMethodDescriptionasMap()default voidclear()Remove all key-collection mappings from this multimap.default Collection<V> Clear all elements within the collection corresponding to the key.default booleancontainsKey(K key) Check whether this multimap contains a mapping for the specified key.default booleancontainsValue(V value) Check whether any collection in this multimap contains the specified value.static <K,V> SetMultiMap <K, V> create()Create a SetMultiMap (framework internal implementation).entrySet()Return a set view of the key-set mappings contained in this multimap.default booleanisEmpty()Check whether this multimap contains no key-collection mappings.keySet()Return the set of keys that have at least one associated value.static <K,V> SetMultiMap <K, V> of()Create a SetMultiMap (framework internal implementation)ofIfAbsent(K key, Consumer<Set<V>> consumer) Get an element collection by key, creating the collection if it does not exist.default booleanAdd an element to the collection associated with the specified key.default intsize()The number of key-collection mappings in the mapdefault intThe total number of all values across all collections in the map.
-
Method Details
-
asMap
-
ofIfAbsent
Get an element collection by key, creating the collection if it does not exist.The returned element collection is guaranteed to be non-null; a new one will be created if absent. The first time the collection for a key is created, the consumer will be called with the newly created collection. Developers can use the consumer for any necessary initialization.
- Parameters:
key- keyconsumer- consumer- Returns:
- the collection
-
of
-
get
-
entrySet
-
create
Create a SetMultiMap (framework internal implementation). Please useof()instead.- Type Parameters:
K- kV- v- Returns:
- SetMultiMap
-
of
Create a SetMultiMap (framework internal implementation)- Type Parameters:
K- kV- v- Returns:
- SetMultiMap
-
clearAll
Clear all elements within the collection corresponding to the key.- Parameters:
key- key- Returns:
- the collection after clearing, guaranteed to be non-null
-
size
default int size()The number of key-collection mappings in the map- Returns:
- size
-
sizeValue
default int sizeValue()The total number of all values across all collections in the map.- Returns:
- value size
-
put
-
isEmpty
default boolean isEmpty()Check whether this multimap contains no key-collection mappings.- Returns:
trueif this multimap contains no mappings
-
containsKey
Check whether this multimap contains a mapping for the specified key.- Parameters:
key- the key to look up- Returns:
trueif this multimap contains at least one mapping for the key
-
containsValue
Check whether any collection in this multimap contains the specified value.- Parameters:
value- the value to search for across all collections- Returns:
trueif the value is found in any collection
-
clear
default void clear()Remove all key-collection mappings from this multimap. -
keySet
-