|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.mina.util.LazyInitializedCacheMap<K,V>
public class LazyInitializedCacheMap<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 an
IoBuffer
for example.
Based on the final implementation of Memoizer written by Brian Goetz and Tim
Peierls. This implementation will return an
UnsupportedOperationException
on each method that is not intended to
be called by user code for performance reasons.
Nested Class Summary | |
---|---|
class |
LazyInitializedCacheMap.NoopInitializer
This class provides a noop LazyInitializer meaning it
will return the same object it received when instantiated. |
Nested classes/interfaces inherited from interface java.util.Map |
---|
Map.Entry<K,V> |
Constructor Summary | |
---|---|
LazyInitializedCacheMap()
Default constructor. |
|
LazyInitializedCacheMap(ConcurrentHashMap<K,LazyInitializer<V>> map)
This constructor allows to provide a fine tuned ConcurrentHashMap
to stick with each special case the user needs. |
Method Summary | |
---|---|
void |
clear()
|
boolean |
containsKey(Object key)
|
boolean |
containsValue(Object value)
|
Set<Map.Entry<K,V>> |
entrySet()
|
V |
get(Object key)
|
Collection<LazyInitializer<V>> |
getValues()
|
boolean |
isEmpty()
|
Set<K> |
keySet()
|
V |
put(K key,
V value)
|
void |
putAll(Map<? extends K,? extends V> m)
|
V |
putIfAbsent(K key,
LazyInitializer<V> value)
If the specified key is not already associated with a value, associate it with the given value. |
V |
remove(Object key)
|
int |
size()
|
Collection<V> |
values()
|
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 |
---|
equals, hashCode |
Constructor Detail |
---|
public LazyInitializedCacheMap()
ConcurrentHashMap
.
public LazyInitializedCacheMap(ConcurrentHashMap<K,LazyInitializer<V>> map)
ConcurrentHashMap
to stick with each special case the user needs.
Method Detail |
---|
public V get(Object key)
get
in interface Map<K,V>
public V remove(Object key)
remove
in interface Map<K,V>
public V putIfAbsent(K key, LazyInitializer<V> value)
if (!map.containsKey(key)) return map.put(key, value); else return map.get(key);except that the action is performed atomically.
key
- key with which the specified value is to be associatedvalue
- a lazy initialized value object.
NullPointerException
- if the specified key or value is nullpublic V put(K key, V value)
put
in interface Map<K,V>
public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
{@link
- UnsupportedOperationException} as this method would imply
performance drops.public Collection<V> values()
values
in interface Map<K,V>
{@link
- UnsupportedOperationException} as this method would imply
performance drops.public Set<Map.Entry<K,V>> entrySet()
entrySet
in interface Map<K,V>
{@link
- UnsupportedOperationException} as this method would imply
performance drops.public void putAll(Map<? extends K,? extends V> m)
putAll
in interface Map<K,V>
public Collection<LazyInitializer<V>> getValues()
public void clear()
clear
in interface Map<K,V>
public boolean containsKey(Object key)
containsKey
in interface Map<K,V>
public boolean isEmpty()
isEmpty
in interface Map<K,V>
public Set<K> keySet()
keySet
in interface Map<K,V>
public int size()
size
in interface Map<K,V>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |