Package net.didion.jwnl.util.cache
Class LRUCache
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<K,V>
-
- java.util.LinkedHashMap
-
- net.didion.jwnl.util.cache.LRUCache
-
- All Implemented Interfaces:
Serializable,Cloneable,Map,Cache
public class LRUCache extends LinkedHashMap implements Cache
A fixed-capacityCachethat stores the most recently used elements. Once the cache reaches capacity, the least recently used elements will be removed.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Constructor Summary
Constructors Constructor Description LRUCache(int capacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetCapacity()Returns the maximum number of elements the cache can hold.intgetSize()Returns the current size of the cache.booleanisFull()protected booleanremoveEldestEntry(Map.Entry eldest)intsetCapacity(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
-
-
-
-
Method Detail
-
isFull
public boolean isFull()
-
removeEldestEntry
protected boolean removeEldestEntry(Map.Entry eldest)
- Overrides:
removeEldestEntryin classLinkedHashMap
-
setCapacity
public int setCapacity(int capacity)
Description copied from interface:CacheSet the maximum number of elements the cache can hold.- Specified by:
setCapacityin interfaceCache
-
getCapacity
public int getCapacity()
Description copied from interface:CacheReturns the maximum number of elements the cache can hold.- Specified by:
getCapacityin interfaceCache
-
-