Interface ListMultiMap<K,V>


public interface ListMultiMap<K,V>
ListMultiMap for example
ListMultiMap<Integer, String> map = ListMultiMap.of();
map.put(1, "a");
map.put(1, "a");
map.put(1, "b");

List<String> list2 = map.get(2); // is null
List<String> list2 = map.of(2); // is empty list

list2.add("2 - a");
list2.add("2 - a");
map.sizeValue(); // sizeValue == 5

map.containsValue("a"); // true
map.containsValue("b"); // true

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> ListMultiMap<K,V>
    Create a ListMultiMap (framework internal implementation).
    default Set<Map.Entry<K,List<V>>>
     
    default List<V>
    get(K key)
     
    default boolean
     
    default Set<K>
     
    static <K,V> ListMultiMap<K,V>
    of()
    Create a ListMultiMap (framework internal implementation)
    default List<V>
    of(K key)
     
    ofIfAbsent(K key, Consumer<List<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,List<V>> asMap()
    • ofIfAbsent

      List<V> ofIfAbsent(K key, Consumer<List<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 List<V> of(K key)
    • get

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

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

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

      static <K,V> ListMultiMap<K,V> of()
      Create a ListMultiMap (framework internal implementation)
      Type Parameters:
      K - k
      V - v
      Returns:
      ListMultiMap
    • 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()