Class ConcurrentUniqueMap<K,V>

java.lang.Object
com.dianxin.tori.base.collections.ConcurrentUniqueMap<K,V>
Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values
All Implemented Interfaces:
UniqueMap<K,V>

@ReleasedSince("26.10.0") public class ConcurrentUniqueMap<K,V> extends Object implements UniqueMap<K,V>
A thread-safe, bidirectional implementation of the UniqueMap interface.

This class guarantees bijective uniqueness across concurrent threads using a ReadWriteLock, allowing concurrent non-blocking reads while ensuring strict atomicity for mutation operations.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.dianxin.tori.base.collections.UniqueMap

    UniqueMap.Entry<K,V>
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    ConcurrentUniqueMap(Map<? extends K,? extends V> map)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns true if this map contains a mapping for the specified key.
    boolean
    Returns true if this map maps one or more keys to the specified value.
    @NonNull V
    get(K key)
    Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
    @Unmodifiable @NonNull Map<K,V>
    Returns an unmodifiable Map view of the mappings contained in this map.
    @NonNull K
    Returns the key associated with the specified value, or null if this map contains no mapping for the value.
    void
    putUnique(@NonNull K key, @NonNull V value)
    Associates the specified value with the specified key in this map.
    void
    Removes the mapping for a key from this map if it is present.
    void
    Removes the mapping for a value from this map if it is present.
    int
    Returns the number of key-value mappings in this map.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ConcurrentUniqueMap

      public ConcurrentUniqueMap()
    • ConcurrentUniqueMap

      public ConcurrentUniqueMap(Map<? extends K,? extends V> map)
  • Method Details

    • putUnique

      public void putUnique(@NonNull K key, @NonNull V value)
      Description copied from interface: UniqueMap
      Associates the specified value with the specified key in this map. Both the key and the value must be unique within the map.
      Specified by:
      putUnique in interface UniqueMap<K,V>
      Parameters:
      key - the key with which the specified value is to be associated
      value - the value to be associated with the specified key
    • get

      public @NonNull V get(K key)
      Description copied from interface: UniqueMap
      Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
      Specified by:
      get in interface UniqueMap<K,V>
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped, or null
    • getKeyByValue

      public @NonNull K getKeyByValue(V value)
      Description copied from interface: UniqueMap
      Returns the key associated with the specified value, or null if this map contains no mapping for the value.
      Specified by:
      getKeyByValue in interface UniqueMap<K,V>
      Parameters:
      value - the value whose associated key is to be returned
      Returns:
      the key associated with the specified value, or null
    • containsKey

      public boolean containsKey(K key)
      Description copied from interface: UniqueMap
      Returns true if this map contains a mapping for the specified key.
      Specified by:
      containsKey in interface UniqueMap<K,V>
      Parameters:
      key - the key whose presence in this map is to be tested
      Returns:
      true if this map contains a mapping for the specified key
    • containsValue

      public boolean containsValue(V value)
      Description copied from interface: UniqueMap
      Returns true if this map maps one or more keys to the specified value.
      Specified by:
      containsValue in interface UniqueMap<K,V>
      Parameters:
      value - the value whose presence in this map is to be tested
      Returns:
      true if this map maps one or more keys to the specified value
    • removeByKey

      public void removeByKey(K key)
      Description copied from interface: UniqueMap
      Removes the mapping for a key from this map if it is present. Also removes the corresponding value from the bidirectional mapping.
      Specified by:
      removeByKey in interface UniqueMap<K,V>
      Parameters:
      key - the key whose mapping is to be removed from the map
    • removeByValue

      public void removeByValue(V value)
      Description copied from interface: UniqueMap
      Removes the mapping for a value from this map if it is present. Also removes the corresponding key from the bidirectional mapping.
      Specified by:
      removeByValue in interface UniqueMap<K,V>
      Parameters:
      value - the value whose mapping is to be removed from the map
    • size

      public int size()
      Description copied from interface: UniqueMap
      Returns the number of key-value mappings in this map.
      Specified by:
      size in interface UniqueMap<K,V>
      Returns:
      the number of key-value mappings in this map
    • getAll

      public @Unmodifiable @NonNull Map<K,V> getAll()
      Description copied from interface: UniqueMap
      Returns an unmodifiable Map view of the mappings contained in this map.
      Specified by:
      getAll in interface UniqueMap<K,V>
      Returns:
      an unmodifiable map containing all key-value pairs