Class LRU<K,V>

All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>, SequencedMap<K,V>

public class LRU<K,V> extends LinkedHashMap<K,V>
A least recently used map.
See Also:
  • Field Details

    • max

      protected int max
      The maximum number of entries.
    • cleaner

      protected ILRUEntryCleaner cleaner
      The entry cleaner (for performing cleanup code on removed entries).
  • Constructor Details

    • LRU

      public LRU()
      Create a new LRU with 1000 entries.
    • LRU

      public LRU(int max)
      Create a new LRU.
      Parameters:
      max - The maximum number of entries.
    • LRU

      public LRU(int max, ILRUEntryCleaner cleaner)
      Create a new LRU.
      Parameters:
      max - The maximum number of entries.
    • LRU

      public LRU(int max, ILRUEntryCleaner cleaner, boolean accessorder)
      Create a new LRU.
      Parameters:
      max - The maximum number of entries.
      cleaner - Optional cleaner.
      accessorder - If true, entry use is refreshed on read as well as write.
  • Method Details

    • put

      public V put(K key, V value)
      Specified by:
      put in interface Map<K,V>
      Overrides:
      put in class HashMap<K,V>
    • getMaxEntries

      public int getMaxEntries()
      Get the maximum number of the
      Returns:
      The maximum number of entries.
    • setMaxEntries

      public void setMaxEntries(int max)
      Set the maximum number of entries.
      Parameters:
      max - The maximum number of entries.
    • getCleaner

      public ILRUEntryCleaner getCleaner()
      Get the cleaner object.
      Returns:
      The cleaner object.
    • setCleaner

      public void setCleaner(ILRUEntryCleaner cleaner)
      Set the cleaner object.
      Parameters:
      cleaner - The cleaner object.
    • removeEldestEntry

      public boolean removeEldestEntry(Map.Entry<K,V> eldest)
      Remove the eldest entry.
      Overrides:
      removeEldestEntry in class LinkedHashMap<K,V>
      Parameters:
      eldest - The eldest entry.
      Returns:
      True if need to be removed.