K
- The keyV
- The valuepublic class CacheMap<K,V> extends LinkedHashMap<K,V>
put(Object, Object)
or putIfAbsent(Object, Object)
will
be used. This is useful for entries that have timing information and that should not be updated if the same key is
going to be used. This class extends LinkedHashMap
, which means that this class is not thread safe.AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
CacheMap(int maxEntries,
boolean updateEntryOnInsert)
Creates a new CacheMap with a fixed capacity.
|
Modifier and Type | Method and Description |
---|---|
V |
put(K key,
V value) |
V |
putIfAbsent(K key,
V value)
If the key is not associated with a value, associate it with the value.
|
protected boolean |
removeEldestEntry(Map.Entry<K,V> eldest) |
clear, containsValue, get
clone, containsKey, entrySet, isEmpty, keySet, putAll, remove, size, values
equals, hashCode, toString
public CacheMap(int maxEntries, boolean updateEntryOnInsert)
maxEntries
- The number of entries that can be stored in this mapupdateEntryOnInsert
- Set to true to update (overwrite) values. Set false to not overwrite the values if there is a value
present.public V putIfAbsent(K key, V value)
if (!map.containsKey(key)) { return map.put(key, value); } else { return map.get(key); }
key
- key with which the value is to be associated.value
- value to be associated with the key.protected boolean removeEldestEntry(Map.Entry<K,V> eldest)
removeEldestEntry
in class LinkedHashMap<K,V>
Copyright © 2013. All Rights Reserved.