Class WeakValueCache<K,​V>

  • Type Parameters:
    K - the key type
    V - the value type

    public class WeakValueCache<K,​V>
    extends java.lang.Object
    A simple cache for weak values.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.HashMap<K,​java.lang.ref.WeakReference<V>> map  
    • Constructor Summary

      Constructors 
      Constructor Description
      WeakValueCache()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      V get​(K key)
      Get the value if in the cache
      void put​(K key, V value)
      Put a value
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • map

        private final java.util.HashMap<K,​java.lang.ref.WeakReference<V>> map
    • Constructor Detail

      • WeakValueCache

        public WeakValueCache()
    • Method Detail

      • put

        public void put​(K key,
                        V value)
        Put a value
        Parameters:
        key - the key
        value - the value
      • get

        public V get​(K key)
        Get the value if in the cache
        Parameters:
        key - the key
        Returns:
        the value or null