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:
java.io.Serializable
,java.lang.Cloneable
,java.util.Map
,Cache
- Direct Known Subclasses:
AbstractCachingDictionary.ObservableCache
public class LRUCache extends java.util.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
-
-
Field Summary
Fields Modifier and Type Field Description private int
_capacity
-
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(java.util.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, entrySet, forEach, get, getOrDefault, keySet, replaceAll, values
-
Methods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
-
-
-
-
Method Detail
-
isFull
public boolean isFull()
-
removeEldestEntry
protected boolean removeEldestEntry(java.util.Map.Entry eldest)
- Overrides:
removeEldestEntry
in classjava.util.LinkedHashMap
-
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
-
-