|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectsk.baka.tools.concurrent.EffectivePutMap<K,V>
K - the map keyV - the map value@ThreadSafe public final class EffectivePutMap<K,V>
Adds a possibility to effectively put a key-value mapping to a ConcurrentMap if such mapping is missing. The main difference
between this map and ConcurrentMap.putIfAbsent(java.lang.Object, java.lang.Object) is that this object uses a producer to produce values.
This producer is expected to be used effectively - the value production is performed only when the object is really added to the map.
Note that in several cases the object may be produced but not actually stored in the map.
map may randomly contain the marker items as values - you'll have to skip such entries manually, e.g. when iterating
the map contents.
| Field Summary | |
|---|---|
ConcurrentMap<K,V> |
map
The map itself. |
| Constructor Summary | |
|---|---|
EffectivePutMap(ConcurrentMap<K,V> map,
V marker,
IValueProducer<? super K,? extends V> producer)
Constructor. |
|
| Method Summary | |
|---|---|
void |
clear()
|
Map<K,V> |
copy()
Returns a list of all map entries with the marker values filtered out. |
V |
get(K key)
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key. |
V |
putIfAbsent(K key)
Similar to ConcurrentMap.putIfAbsent(java.lang.Object, java.lang.Object) except that it uses #produce() to produce value objects. |
V |
remove(K key)
Removes the mapping for a key from this map if it is present (optional operation). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public final ConcurrentMap<K,V> map
| Constructor Detail |
|---|
public EffectivePutMap(ConcurrentMap<K,V> map,
V marker,
IValueProducer<? super K,? extends V> producer)
map - the map to usemarker - a "marker" object, used in utility methods. The marker must not be null and must not be equal to any other instances of V.producer - the value producer, must not be null. Must not produce null values.| Method Detail |
|---|
public V putIfAbsent(K key)
ConcurrentMap.putIfAbsent(java.lang.Object, java.lang.Object) except that it uses #produce() to produce value objects.
#produce() is called only when the value object is really added to the map.
key - the map key
public Map<K,V> copy()
public void clear()
public V get(K key)
null if this map contains no mapping for the key.
key - the key whose associated value is to be returned
null if this map contains no mapping for the key. Never returns the marker.public V remove(K key)
(key==null ? k==null : key.equals(k)), that mapping
is removed. (The map can contain at most one such mapping.)
Returns the value to which this map previously associated the key, or null if the map contained no mapping for the key.
If this map permits null values, then a return value of null does not necessarily indicate that the map contained no mapping for the key; it's also possible that the map explicitly mapped the key to null.
The map will not contain a mapping for the specified key once the call returns.
key - key whose mapping is to be removed from the map
marker element.
UnsupportedOperationException - if the remove operation
is not supported by this map
NullPointerException - if the specified key is null and this
map does not permit null keys (optional)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||