Package org.apache.mina.util
Class LazyInitializedCacheMap<K,V>
- java.lang.Object
-
- org.apache.mina.util.LazyInitializedCacheMap<K,V>
-
- Type Parameters:
K- The key typeV- The value type
- All Implemented Interfaces:
Map<K,V>
public class LazyInitializedCacheMap<K,V> extends Object implements Map<K,V>
This map is specially useful when reads are much more frequent than writes and if the cost of instantiating the values is high like allocating anIoBufferfor example. Based on the final implementation of Memoizer written by Brian Goetz and Tim Peierls. This implementation will return anUnsupportedOperationExceptionon each method that is not intended to be called by user code for performance reasons.- Since:
- MINA 2.0.0-M2
- Author:
- Apache MINA Project
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classLazyInitializedCacheMap.NoopInitializerThis class provides a noopLazyInitializermeaning it will return the same object it received when instantiated.
-
Constructor Summary
Constructors Constructor Description LazyInitializedCacheMap()Default constructor.LazyInitializedCacheMap(ConcurrentHashMap<K,LazyInitializer<V>> map)This constructor allows to provide a fine tunedConcurrentHashMapto stick with each special case the user needs.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()booleancontainsKey(Object key)booleancontainsValue(Object value)ThrowsUnsupportedOperationExceptionas this method would imply performance drops.Set<Map.Entry<K,V>>entrySet()ThrowsUnsupportedOperationExceptionas this method would imply performance drops.Vget(Object key)Collection<LazyInitializer<V>>getValues()booleanisEmpty()Set<K>keySet()Vput(K key, V value)voidputAll(Map<? extends K,? extends V> m)VputIfAbsent(K key, LazyInitializer<V> value)If the specified key is not already associated with a value, associate it with the given value.Vremove(Object key)intsize()Collection<V>values()ThrowsUnsupportedOperationExceptionas this method would imply performance drops.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Constructor Detail
-
LazyInitializedCacheMap
public LazyInitializedCacheMap()
Default constructor. Uses the default parameters to initialize its internalConcurrentHashMap.
-
LazyInitializedCacheMap
public LazyInitializedCacheMap(ConcurrentHashMap<K,LazyInitializer<V>> map)
This constructor allows to provide a fine tunedConcurrentHashMapto stick with each special case the user needs.- Parameters:
map- The map to use as a cache
-
-
Method Detail
-
putIfAbsent
public V putIfAbsent(K key, LazyInitializer<V> value)
If the specified key is not already associated with a value, associate it with the given value. This is equivalent toif (!map.containsKey(key)) return map.put(key, value); else return map.get(key);except that the action is performed atomically.- Parameters:
key- key with which the specified value is to be associatedvalue- a lazy initialized value object.- Returns:
- the previous value associated with the specified key,
or
nullif there was no mapping for the key
-
containsValue
public boolean containsValue(Object value)
ThrowsUnsupportedOperationExceptionas this method would imply performance drops.- Specified by:
containsValuein interfaceMap<K,V>
-
values
public Collection<V> values()
ThrowsUnsupportedOperationExceptionas this method would imply performance drops.
-
entrySet
public Set<Map.Entry<K,V>> entrySet()
ThrowsUnsupportedOperationExceptionas this method would imply performance drops.
-
getValues
public Collection<LazyInitializer<V>> getValues()
- Returns:
- return the values from the cache
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKeyin interfaceMap<K,V>
-
-