K
- Type of cache element key.V
- Type of cache element value.public interface Cache<K,V>
Modifier and Type | Interface and Description |
---|---|
static class |
Cache.Entry<K,V>
An node containing the hashable key and value of a cache element.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Iterable<Cache.Entry<K,V>> |
entries()
Get an object which allows iteration of all of the entries in the cache, in a for-each loop.
|
V |
get(K key)
Retrieve a value, given its key.
|
java.lang.Iterable<K> |
keys()
Get an object which allows iteration of all of the keys in the cache, in a for-each loop.
|
V |
put(K key,
V value)
Add an entry to the cache, identified by the given key.
|
V |
putIfAbsent(K key,
V value)
Add an entry to the cache, identified by the given key, if and only if an entry does not already
exist with that key.
|
java.lang.Object |
remove(K key)
Remove the entry associated with the given key from the cache.
|
int |
size()
Get the number of entries currently in the cache.
|
java.lang.Iterable<V> |
values()
Get an object which allows iteration of all of the values in the cache, in a for-each loop.
|
V get(K key)
key
- A hashable key.null
if there is no mapping
for the given key.V put(K key, V value)
key
- A hashable key to associate with the value.value
- Value to store.null
if there was no
mapping for the given key.V putIfAbsent(K key, V value)
key
- A hashable key to associate with the value.value
- Value to store.null
if there was no
mapping for the given key.java.lang.Object remove(K key)
key
- A hashable key identifying the entry to remove.null
if there was no mapping for the given key.int size()
java.lang.Iterable<K> keys()
Iterable
on all the keys in the cache.java.lang.Iterable<V> values()
Iterable
on all the values in the cache.java.lang.Iterable<Cache.Entry<K,V>> entries()
Iterable
on all the entries in the cache.