Interface 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();

Author:
渔民小镇
date:
2023-12-07
  • Method Summary

    Modifier and Type
    Method
    Description
     
    default void
     
    default Collection<V>
    clearAll(K key)
    Clear all elements within the collection corresponding to the key.
    default boolean
     
    default boolean
     
    static <K,V> SetMultiMap<K,V>
    Create a SetMultiMap (framework internal implementation).
     
    default Set<V>
    get(K key)
     
    default boolean
     
    default Set<K>
     
    static <K,V> SetMultiMap<K,V>
    of()
    Create a SetMultiMap (framework internal implementation)
    default Set<V>
    of(K key)
     
    ofIfAbsent(K key, Consumer<Set<V>> consumer)
    Get an element collection by key, creating the collection if it does not exist.
    default boolean
    put(K key, V value)
    Add an element to the collection associated with the specified key.
    default int
    The number of key-collection mappings in the map
    default int
    The total number of all values across all collections in the map.
  • Method Details

    • asMap

      Map<K,Set<V>> asMap()
    • ofIfAbsent

      Set<V> ofIfAbsent(K key, Consumer<Set<V>> consumer)
      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 - key
      consumer - consumer
      Returns:
      the collection
    • of

      default Set<V> of(K key)
    • get

      default Set<V> get(K key)
    • entrySet

      Set<Map.Entry<K,Set<V>>> entrySet()
    • create

      static <K,V> SetMultiMap<K,V> create()
      Create a SetMultiMap (framework internal implementation). Please use of() instead.
      Type Parameters:
      K - k
      V - v
      Returns:
      SetMultiMap
    • of

      static <K,V> SetMultiMap<K,V> of()
      Create a SetMultiMap (framework internal implementation)
      Type Parameters:
      K - k
      V - v
      Returns:
      SetMultiMap
    • clearAll

      default Collection<V> clearAll(K key)
      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

      default boolean put(K key, V value)
      Add an element to the collection associated with the specified key.
      Parameters:
      key - key
      value - element
      Returns:
      true if this collection changed as a result of the call
    • isEmpty

      default boolean isEmpty()
    • containsKey

      default boolean containsKey(K key)
    • containsValue

      default boolean containsValue(V value)
    • clear

      default void clear()
    • keySet

      default Set<K> keySet()