Class WeakValueMap<K,​V>

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

    public class WeakValueMap<K,​V>
    extends java.lang.Object
    implements java.util.Map<K,​V>
    A map with weak values.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Map<K,​WeakEntry<V>> contents
      The contents.
      protected java.lang.ref.ReferenceQueue<V> queue
      The reference queue.
    • Constructor Summary

      Constructors 
      Constructor Description
      WeakValueMap()
      Create a new weak value map.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clear the map.
      boolean containsKey​(java.lang.Object key)
      Test if key contained.
      boolean containsValue​(java.lang.Object value)
      Test if value contained.
      java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
      Get the entries.
      protected void expungeStaleEntries()
      Remove garbage collected entries.
      V get​(java.lang.Object key)
      Get value for key.
      boolean isEmpty()
      Check if empty.
      java.util.Set<K> keySet()
      Get the key set.
      V put​(K key, V value)
      Add value for key.
      void putAll​(java.util.Map<? extends K,​? extends V> m)
      Add all mappings.
      V remove​(java.lang.Object key)
      Remove value for key.
      int size()
      Get the size.
      java.util.Collection<V> values()
      Get the values.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Map

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

      • contents

        protected java.util.Map<K,​WeakEntry<V>> contents
        The contents.
      • queue

        protected java.lang.ref.ReferenceQueue<V> queue
        The reference queue.
    • Constructor Detail

      • WeakValueMap

        public WeakValueMap()
        Create a new weak value map.
    • Method Detail

      • size

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

        public boolean isEmpty()
        Check if empty.
        Specified by:
        isEmpty in interface java.util.Map<K,​V>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Test if key contained.
        Specified by:
        containsKey in interface java.util.Map<K,​V>
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Test if value contained.
        Specified by:
        containsValue in interface java.util.Map<K,​V>
      • get

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

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

        public V remove​(java.lang.Object key)
        Remove value for key.
        Specified by:
        remove in interface java.util.Map<K,​V>
      • clear

        public void clear()
        Clear the map.
        Specified by:
        clear in interface java.util.Map<K,​V>
      • putAll

        public void putAll​(java.util.Map<? extends K,​? extends V> m)
        Add all mappings.
        Specified by:
        putAll in interface java.util.Map<K,​V>
      • keySet

        public java.util.Set<K> keySet()
        Get the key set.
        Specified by:
        keySet in interface java.util.Map<K,​V>
      • values

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

        public java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
        Get the entries.
        Specified by:
        entrySet in interface java.util.Map<K,​V>
      • expungeStaleEntries

        protected final void expungeStaleEntries()
        Remove garbage collected entries.