|
Spring Framework | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.springframework.util.CachingMapDecorator<K,V>
public abstract class CachingMapDecorator<K,V>
A simple decorator for a Map, encapsulating the workflow for caching expensive values in a target Map. Supports caching weak or strong keys.
This class is an abstract template. Caching Map implementations
should subclass and override the create(key) method which
encapsulates expensive creation of a new object.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface java.util.Map |
|---|
java.util.Map.Entry<K,V> |
| Constructor Summary | |
|---|---|
CachingMapDecorator()
Create a CachingMapDecorator with strong keys, using an underlying synchronized Map. |
|
CachingMapDecorator(boolean weak)
Create a CachingMapDecorator, using an underlying synchronized Map. |
|
CachingMapDecorator(boolean weak,
int size)
Create a CachingMapDecorator with initial size, using an underlying synchronized Map. |
|
CachingMapDecorator(java.util.Map<K,V> targetMap)
Create a CachingMapDecorator for the given Map. |
|
CachingMapDecorator(java.util.Map<K,V> targetMap,
boolean synchronize,
boolean weak)
Create a CachingMapDecorator for the given Map. |
|
| Method Summary | |
|---|---|
void |
clear()
|
boolean |
containsKey(java.lang.Object key)
|
boolean |
containsValue(java.lang.Object value)
|
protected abstract V |
create(K key)
Create a value to cache for the given key. |
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet()
|
V |
get(java.lang.Object key)
Get value for key. |
boolean |
isEmpty()
|
java.util.Set<K> |
keySet()
|
V |
put(K key,
V value)
Put an object into the cache, possibly wrapping it with a weak reference. |
void |
putAll(java.util.Map<? extends K,? extends V> map)
|
V |
remove(java.lang.Object key)
|
int |
size()
|
java.lang.String |
toString()
|
protected boolean |
useWeakValue(K key,
V value)
Decide whether to use a weak reference for the value of the given key-value pair. |
java.util.Collection<V> |
values()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Map |
|---|
equals, hashCode |
| Constructor Detail |
|---|
public CachingMapDecorator()
public CachingMapDecorator(boolean weak)
weak - whether to use weak references for keys and values
public CachingMapDecorator(boolean weak,
int size)
weak - whether to use weak references for keys and valuessize - the initial cache sizepublic CachingMapDecorator(java.util.Map<K,V> targetMap)
The passed-in Map won't get synchronized explicitly, so make sure to pass in a properly synchronized Map, if desired.
targetMap - the Map to decorate
public CachingMapDecorator(java.util.Map<K,V> targetMap,
boolean synchronize,
boolean weak)
The passed-in Map won't get synchronized explicitly unless you specify "synchronize" as "true".
targetMap - the Map to decoratesynchronize - whether to synchronize on the given Mapweak - whether to use weak references for values| Method Detail |
|---|
public int size()
size in interface java.util.Map<K,V>public boolean isEmpty()
isEmpty in interface java.util.Map<K,V>public boolean containsKey(java.lang.Object key)
containsKey in interface java.util.Map<K,V>public boolean containsValue(java.lang.Object value)
containsValue in interface java.util.Map<K,V>public V remove(java.lang.Object key)
remove in interface java.util.Map<K,V>public void putAll(java.util.Map<? extends K,? extends V> map)
putAll in interface java.util.Map<K,V>public void clear()
clear in interface java.util.Map<K,V>public java.util.Set<K> keySet()
keySet in interface java.util.Map<K,V>public java.util.Collection<V> values()
values in interface java.util.Map<K,V>public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
entrySet in interface java.util.Map<K,V>
public V put(K key,
V value)
put in interface java.util.Map<K,V>useWeakValue(Object, Object)
protected boolean useWeakValue(K key,
V value)
key - the candidate keyvalue - the candidate value
true in order to use a weak reference;
false otherwise.public V get(java.lang.Object key)
This implementation is not synchronized: This is highly concurrent but does not guarantee unique instances in the cache, as multiple values for the same key could get created in parallel. Consider overriding this method to synchronize it, if desired.
get in interface java.util.Map<K,V>create(Object)protected abstract V create(K key)
get if there is no value cached already.
key - the cache keyget(Object)public java.lang.String toString()
toString in class java.lang.Object
|
Spring Framework | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||