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-capacityCachethat 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 intgetCapacity()Returns the maximum number of elements the cache can hold.intgetSize()Returns the current size of the cache.booleanisFull()protected booleanremoveEldestEntry(java.util.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, 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:
removeEldestEntryin classjava.util.LinkedHashMap
-
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
-
-