Class LRUCache
java.lang.Object
java.util.AbstractMap
java.util.HashMap
java.util.LinkedHashMap
net.didion.jwnl.util.cache.LRUCache
- All Implemented Interfaces:
Serializable, Cloneable, Map, Cache
- Direct Known Subclasses:
AbstractCachingDictionary.ObservableCache
A fixed-capacity
Cache that stores the most recently used elements. Once the cache reaches
capacity, the least recently used elements will be removed.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns 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 LinkedHashMap
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, replaceAll, valuesMethods inherited from class HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, sizeMethods inherited from class AbstractMap
equals, hashCode, toStringMethods inherited from interface Map
compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
-
Field Details
-
_capacity
private int _capacity
-
-
Constructor Details
-
LRUCache
public LRUCache(int capacity) - Parameters:
capacity- the maximum number of elements that can be contained in the cache.
-
-
Method Details
-
isFull
public boolean isFull() -
removeEldestEntry
- 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
-
getSize
-