接口 SetMultiMap<K,V>
public interface SetMultiMap<K,V>
线程安全的 SetMultiMap
value 为 set 集合实现
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();
- 作者:
- 渔民小镇
- 日期:
- 2023-12-07
-
方法概要
修饰符和类型方法说明asMap()default voidclear()default Collection<V> clear key 所对应的集合内的所有元素default booleancontainsKey(K key) default booleancontainsValue(V value) static <K,V> SetMultiMap <K, V> create()创建 SetMultiMap(框架内置实现)请使用of()代替entrySet()default booleanisEmpty()keySet()static <K,V> SetMultiMap <K, V> of()创建 SetMultiMap(框架内置实现)ofIfAbsent(K key, Consumer<Set<V>> consumer) 根据 key 来 get 一个元素,如果不存在就创建集合default boolean向指定 key 的集合添加元素default intsize()map 集合的数目default intmap 所有 value 集合的汇总
-
方法详细资料
-
asMap
-
ofIfAbsent
根据 key 来 get 一个元素,如果不存在就创建集合get 的元素集合一定不为 null,如果不存在就新创建。 首次创建该 key 的集合时,会调用 consumer 并将新创建集合传入 consumer 中。 开发者有需要初始化的内容,可以通过 consumer 来实现- 参数:
key- keyconsumer- consumer- 返回:
- 集合
-
of
-
get
-
entrySet
-
create
创建 SetMultiMap(框架内置实现)请使用of()代替- 类型参数:
K- kV- v- 返回:
- SetMultiMap
-
of
创建 SetMultiMap(框架内置实现)- 类型参数:
K- kV- v- 返回:
- SetMultiMap
-
clearAll
clear key 所对应的集合内的所有元素- 参数:
key- key- 返回:
- clear 后的集合,一定不为 null
-
size
default int size()map 集合的数目- 返回:
- size
-
sizeValue
default int sizeValue()map 所有 value 集合的汇总- 返回:
- value size
-
put
向指定 key 的集合添加元素- 参数:
key- keyvalue- 元素- 返回:
- true if this collection changed as a result of the call
-
isEmpty
default boolean isEmpty() -
containsKey
-
containsValue
-
clear
default void clear() -
keySet
-