Class SoftHashMap

  • All Implemented Interfaces:
    java.util.Map

    public class SoftHashMap
    extends java.util.AbstractMap
    A in memory cache using soft references. (can be garbage collected) This code is based on: http://java-interview-faqs.blogspot.com/2008/09/building-faster-and-efficient-cache.html
    • 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>
      • 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
      static boolean DEBUG  
      static int DEFAULT_LIMIT  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()  
      java.util.Set entrySet()  
      java.lang.Object get​(java.lang.Object key)  
      java.lang.Object put​(java.lang.Object key, java.lang.Object value)
      Here we put the key, value pair into the HashMap using a SoftValue object.
      java.lang.Object remove​(java.lang.Object key)  
      int size()  
      • Methods inherited from class java.util.AbstractMap

        clone, containsKey, containsValue, equals, hashCode, isEmpty, keySet, putAll, toString, values
      • Methods inherited from class java.lang.Object

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

        compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Method Detail

      • get

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

        public java.lang.Object put​(java.lang.Object key,
                                    java.lang.Object value)
        Here we put the key, value pair into the HashMap using a SoftValue object.
        Specified by:
        put in interface java.util.Map
        Overrides:
        put in class java.util.AbstractMap
      • remove

        public java.lang.Object remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map
        Overrides:
        remove in class java.util.AbstractMap
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map
        Overrides:
        clear in class java.util.AbstractMap
      • size

        public int size()
        Specified by:
        size in interface java.util.Map
        Overrides:
        size in class java.util.AbstractMap
      • entrySet

        public java.util.Set entrySet()
        Specified by:
        entrySet in interface java.util.Map
        Specified by:
        entrySet in class java.util.AbstractMap