net.sf.extjwnl.util.cache
Class LRUCache<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by java.util.LinkedHashMap<K,V>
              extended by net.sf.extjwnl.util.cache.LRUCache<K,V>
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>, Cache<K,V>

public class LRUCache<K,V>
extends LinkedHashMap<K,V>
implements Cache<K,V>

A fixed-capacity Cache that stores the most recently used elements. Once the cache reaches capacity, the least recently used elements will be removed.

Author:
John Didion , Aliaksandr Autayeu
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
LRUCache(int capacity)
           
 
Method Summary
 int getCapacity()
          Returns the maximum number of elements the cache can hold.
 int getSize()
          Returns the current size of the cache.
 boolean isFull()
           
protected  boolean removeEldestEntry(Map.Entry<K,V> eldest)
           
 int setCapacity(int capacity)
          Set the maximum number of elements the cache can hold.
 
Methods inherited from class java.util.LinkedHashMap
clear, containsValue, get
 
Methods inherited from class java.util.HashMap
clone, containsKey, entrySet, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.extjwnl.util.cache.Cache
clear, get, put, remove, values
 
Methods inherited from interface java.util.Map
containsKey, entrySet, equals, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Constructor Detail

LRUCache

public LRUCache(int capacity)
Parameters:
capacity - the maximum number of elements that can be contained in the cache.
Method Detail

isFull

public boolean isFull()

removeEldestEntry

protected boolean removeEldestEntry(Map.Entry<K,V> eldest)
Overrides:
removeEldestEntry in class LinkedHashMap<K,V>

setCapacity

public int setCapacity(int capacity)
Description copied from interface: Cache
Set the maximum number of elements the cache can hold.

Specified by:
setCapacity in interface Cache<K,V>
Parameters:
capacity - capacity
Returns:
new capacity

getCapacity

public int getCapacity()
Description copied from interface: Cache
Returns the maximum number of elements the cache can hold.

Specified by:
getCapacity in interface Cache<K,V>
Returns:
the maximum number of elements the cache can hold

getSize

public int getSize()
Description copied from interface: Cache
Returns the current size of the cache.

Specified by:
getSize in interface Cache<K,V>
Returns:
size


Copyright © 2011. All Rights Reserved.