public class Cache<K,V>
extends java.lang.Object
Constructor and Description |
---|
Cache() |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
containsKey(K key) |
V |
get(K key) |
java.util.Set<K> |
keys()
Returns a snapshot of the keys currently in the cache.
|
java.util.Set<K> |
keySet() |
V |
put(K key,
V value) |
V |
putIfAbsent(K key,
V value)
If the specified key is not already associated with a value, associate it
with the given value.
|
V |
remove(K key) |
boolean |
remove(K key,
V value)
Removes the entry for a key only if currently mapped to a given value.
|
V |
replace(K key,
V value)
Replaces the entry for a key only if currently mapped to some value.
|
boolean |
replace(K key,
V oldValue,
V newValue)
Replaces the entry for a key only if currently mapped to a given value.
|
public void clear()
public boolean containsKey(K key)
public java.util.Set<K> keySet()
public V putIfAbsent(K key, V value)
if (!cache.containsKey(key)) return map.put(key, value);
else return map.get(key);
except that the action is performed atomically.public V replace(K key, V value)
if (cache.containsKey(key)) {
return cache.put(key, value);
} else return null;
except that the action is performed atomically.key
- key with which the specified value is associated.value
- value to be associated with the specified key.public boolean replace(K key, V oldValue, V newValue)
if (cache.containsKey(key) && cache.get(key).equals(oldValue)) {
cache.put(key, newValue);
return true;
} else return false;
except that the action is performed atomically.key
- key with which the specified value is associated.oldValue
- value expected to be associated with the specified key.newValue
- value to be associated with the specified key.public boolean remove(K key, V value)
if (cache.containsKey(key) && cache.get(key).equals(value)) {
cache.remove(key);
return true;
} else return false;
except that the action is performed atomically.key
- key with which the specified value is associated.value
- value expected to be associated with the specified key.public java.util.Set<K> keys()