public class LRUCache<K,V> extends Object
| Constructor and Description |
|---|
LRUCache()
Construct a new cache with default settings.
|
LRUCache(int maxSize)
Construct a new cache based on the given max size.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clear the cache.
|
boolean |
containsKey(K key)
Determine if the cache contains the given key.
|
V |
get(K key)
Return the value mapped to the given key.
|
V |
getAndPut(K key,
V value)
Return the previously mapped value and map a new value.
|
V |
getAndRemove(K key)
Return the previously mapped value and remove the key.
|
void |
put(K key,
V value)
Map a given key to the given value.
|
void |
putAll(Map<? extends K,? extends V> map)
Copies all of the mappings from the provided map to this cache.
|
boolean |
putIfAbsent(K key,
V value)
Map a given key to the given value if not already mapped.
|
boolean |
remove(K key)
Remove a given key from the cache.
|
boolean |
remove(K key,
V oldValue)
Remove a given key and value from the cache.
|
void |
removeAll()
Remove all of the cached items.
|
public LRUCache()
public LRUCache(int maxSize)
maxSize - The maximum number of items to store in the cache.public V get(K key)
key - The key used to return the mapped value.public boolean containsKey(K key)
key - The key used to determine it there is a mapped value.public void put(K key, V value)
key - The key to map to the given value.value - The value to map to the given key.public V getAndPut(K key, V value)
key - The key to map to the given value.value - The value to map to the given key.public void putAll(Map<? extends K,? extends V> map)
map - The mappings to copy.public boolean putIfAbsent(K key, V value)
key - The key to map to the given value.value - The value to map to the given key.public boolean remove(K key)
key - The key to remove.public boolean remove(K key, V oldValue)
key - The key to remove.oldValue - The value to remove.public V getAndRemove(K key)
key - The key to remove.public void removeAll()
public void clear()
Copyright © 2018. All rights reserved.