public class LRUCache extends LinkedHashMap implements Cache
Cache
that stores the most recently used elements. Once the cache reaches
capacity, the least recently used elements will be removed.AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
LRUCache(int capacity) |
Modifier and Type | Method and Description |
---|---|
int |
getCapacity()
Returns the maximum number of elements the cache can hold.
|
int |
getSize()
Returns the current size of the cache.
|
boolean |
isFull() |
int |
setCapacity(int capacity)
Set the maximum number of elements the cache can hold.
|
clear, containsValue, get
clone, containsKey, entrySet, isEmpty, keySet, put, putAll, remove, size, values
equals, hashCode, toString
public LRUCache(int capacity)
capacity
- the maximum number of elements that can be contained in the cache.public boolean isFull()
public int setCapacity(int capacity)
Cache
setCapacity
in interface Cache
public int getCapacity()
Cache
getCapacity
in interface Cache