Class SoftReferenceCache

  • All Implemented Interfaces:
    Cache

    public class SoftReferenceCache
    extends java.lang.Object
    implements Cache
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.Object,​java.lang.ref.SoftReference<?>> cache  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Removes all mappings from a map (optional operation).
      java.lang.Object get​(java.lang.Object key)  
      private java.lang.Object getValueNullSafe​(java.lang.ref.SoftReference<?> softReference)  
      java.lang.Object put​(java.lang.Object key, java.lang.Object value, int sizeEstimate)  
      java.lang.Object remove​(java.lang.Object key)  
      • Methods inherited from class java.lang.Object

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

      • cache

        private final java.util.Map<java.lang.Object,​java.lang.ref.SoftReference<?>> cache
    • Constructor Detail

      • SoftReferenceCache

        public SoftReferenceCache()
    • Method Detail

      • put

        public java.lang.Object put​(java.lang.Object key,
                                    java.lang.Object value,
                                    int sizeEstimate)
        Specified by:
        put in interface Cache
        Parameters:
        key - value to be used as key
        value - value to be stored
        sizeEstimate - estimated size
        Returns:
        the old object, that was replaced if present. Otherwise null.
      • get

        public java.lang.Object get​(java.lang.Object key)
        Specified by:
        get in interface Cache
      • clear

        public void clear()
        Description copied from interface: Cache
        Removes all mappings from a map (optional operation).
        Specified by:
        clear in interface Cache
      • remove

        public java.lang.Object remove​(java.lang.Object key)
        Specified by:
        remove in interface Cache
        Parameters:
        key - the key of the to be removed object
        Returns:
        the removed object, if present. Otherwise null.
      • getValueNullSafe

        private java.lang.Object getValueNullSafe​(java.lang.ref.SoftReference<?> softReference)