Class WeakIdentityMap<K,​V>

  • All Implemented Interfaces:
    java.util.Map<K,​V>

    public class WeakIdentityMap<K,​V>
    extends java.util.AbstractMap<K,​V>
    implements java.util.Map<K,​V>
    WeakIdentityMap is like WeakHashMap, except it uses a key's identity hashcode and equals methods. WeakIdentityMap is not thread-safe and must be wrapped with Collections.synchronizedMap to be made thread-safe.

    The documentation for WeakHashMap states that it is intended primarily for use with key objects whose equals methods test for object identity using the == operator. Because WeakIdentityMap strictly follows this behavior, it is better suited for this purpose.

    Note: Weakly referenced entries may be automatically removed during either accessor or mutator operations, possibly causing a concurrent modification to be detected. Therefore, even if multiple threads are only accessing this map, be sure to synchronize this map first. Also, do not rely on the value returned by size() when using an iterator from this map. The iterators may return less entries than the amount reported by size().

    Since:
    6.0.0
    Author:
    Brian S O'Neill
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()  
      java.lang.Object clone()  
      boolean containsKey​(java.lang.Object key)  
      boolean containsValue​(java.lang.Object value)  
      java.util.Set<java.util.Map.Entry<K,​V>> entrySet()  
      V get​(java.lang.Object key)  
      boolean isEmpty()  
      java.util.Set<K> keySet()  
      V put​(K key, V value)  
      void putAll​(java.util.Map<? extends K,​? extends V> t)  
      V remove​(java.lang.Object key)  
      int size()  
      java.lang.String toString()
      Gets the map as a String.
      java.util.Collection<V> values()  
      • Methods inherited from class java.util.AbstractMap

        equals, hashCode
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Constructor Detail

      • WeakIdentityMap

        public WeakIdentityMap​(int initialCapacity,
                               float loadFactor)
      • WeakIdentityMap

        public WeakIdentityMap​(int initialCapacity)
      • WeakIdentityMap

        public WeakIdentityMap()
      • WeakIdentityMap

        public WeakIdentityMap​(java.util.Map<? extends K,​? extends V> t)
    • Method Detail

      • toString

        public java.lang.String toString()
        Gets the map as a String.
        Overrides:
        toString in class java.util.AbstractMap<K,​V>
        Returns:
        a string version of the map
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<K,​V>
        Overrides:
        size in class java.util.AbstractMap<K,​V>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<K,​V>
        Overrides:
        isEmpty in class java.util.AbstractMap<K,​V>
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<K,​V>
        Overrides:
        containsValue in class java.util.AbstractMap<K,​V>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<K,​V>
        Overrides:
        containsKey in class java.util.AbstractMap<K,​V>
      • get

        public V get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<K,​V>
        Overrides:
        get in class java.util.AbstractMap<K,​V>
      • put

        public V put​(K key,
                     V value)
        Specified by:
        put in interface java.util.Map<K,​V>
        Overrides:
        put in class java.util.AbstractMap<K,​V>
      • remove

        public V remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<K,​V>
        Overrides:
        remove in class java.util.AbstractMap<K,​V>
      • putAll

        public void putAll​(java.util.Map<? extends K,​? extends V> t)
        Specified by:
        putAll in interface java.util.Map<K,​V>
        Overrides:
        putAll in class java.util.AbstractMap<K,​V>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<K,​V>
        Overrides:
        clear in class java.util.AbstractMap<K,​V>
      • clone

        public java.lang.Object clone()
        Overrides:
        clone in class java.util.AbstractMap<K,​V>
      • keySet

        public java.util.Set<K> keySet()
        Specified by:
        keySet in interface java.util.Map<K,​V>
        Overrides:
        keySet in class java.util.AbstractMap<K,​V>
      • values

        public java.util.Collection<V> values()
        Specified by:
        values in interface java.util.Map<K,​V>
        Overrides:
        values in class java.util.AbstractMap<K,​V>
      • entrySet

        public java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<K,​V>
        Specified by:
        entrySet in class java.util.AbstractMap<K,​V>