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-capacityCache
that 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 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 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
-
-
-
-
Method Detail
-
isFull
public boolean isFull()
-
removeEldestEntry
protected boolean removeEldestEntry(Map.Entry eldest)
- Overrides:
removeEldestEntry
in classLinkedHashMap
-
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 interfaceCache
-
getCapacity
public int getCapacity()
Description copied from interface:Cache
Returns the maximum number of elements the cache can hold.- Specified by:
getCapacity
in interfaceCache
-
-