Class LeastRecentlyUsedMap<K,V>

java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<K,V>
org.simpleframework.common.LeastRecentlyUsedMap<K,V>
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>, SequencedMap<K,V>

public class LeastRecentlyUsedMap<K,V> extends LinkedHashMap<K,V>
The LeastRecentlyUsedMap is a hash map that keeps only those entries most recently used. This acts much like a hot spot cache for specific keys that are used frequently. It also allows for algorithms to keep hot spot values available in the cache without the risk of running out of memory.
See Also:
  • Field Details

    • listener

      private final LeastRecentlyUsedMap.RemovalListener<K,V> listener
      This is the listener that is called when an entry is removed.
    • capacity

      private final int capacity
      This is the number of items to keep within the cache.
  • Constructor Details

    • LeastRecentlyUsedMap

      public LeastRecentlyUsedMap()
      Constructor for the LeastRecentlyUsedMap object. This creates a hash container that keeps only those entries that have been recently added or accessed available within the collection.
    • LeastRecentlyUsedMap

      public LeastRecentlyUsedMap(int capacity)
      Constructor for the LeastRecentlyUsedMap object. This creates a hash container that keeps only those entries that have been recently added or accessed available within the collection.
      Parameters:
      capacity - this is the capacity of the hash container
    • LeastRecentlyUsedMap

      public LeastRecentlyUsedMap(LeastRecentlyUsedMap.RemovalListener<K,V> listener)
      Constructor for the LeastRecentlyUsedMap object. This creates a hash container that keeps only those entries that have been recently added or accessed available within the collection.
      Parameters:
      listener - this listens for entries that are removed
    • LeastRecentlyUsedMap

      public LeastRecentlyUsedMap(LeastRecentlyUsedMap.RemovalListener<K,V> listener, int capacity)
      Constructor for the LeastRecentlyUsedMap object. This creates a hash container that keeps only those entries that have been recently added or accessed available within the collection.
      Parameters:
      listener - this listens for entries that are removed
      capacity - this is the capacity of the hash container
  • Method Details

    • removeEldestEntry

      protected boolean removeEldestEntry(Map.Entry<K,V> eldest)
      This is used to determine if an entry should be removed from the cache. If the cache has reached its capacity then the listener, if one was specified is given a callback to tell any other participating objects the entry has been removed.
      Overrides:
      removeEldestEntry in class LinkedHashMap<K,V>
      Parameters:
      eldest - this is the candidate for removal