|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.util.CachingMapDecorator
public abstract class CachingMapDecorator
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 also 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 |
---|
Map.Entry<K,V> |
Constructor Summary | |
---|---|
CachingMapDecorator()
Create a CachingMapDecorator with strong keys, using an underlying synchronized Map. |
|
CachingMapDecorator(boolean weakKeys)
Create a CachingMapDecorator, using an underlying synchronized Map. |
|
CachingMapDecorator(boolean weakKeys,
int size)
Create a CachingMapDecorator with initial size, using an underlying synchronized Map. |
|
CachingMapDecorator(Map targetMap)
Create a CachingMapDecorator for the given Map. |
Method Summary | |
---|---|
void |
clear()
|
boolean |
containsKey(Object key)
|
boolean |
containsValue(Object value)
|
protected abstract Object |
create(Object key)
Create a value to cache for the given key. |
Set |
entrySet()
|
Object |
get(Object key)
Get value for key. |
boolean |
isEmpty()
|
Set |
keySet()
|
Object |
put(Object key,
Object value)
|
void |
putAll(Map t)
|
Object |
remove(Object key)
|
int |
size()
|
String |
toString()
|
Collection |
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 weakKeys)
weakKeys
- whether to use weak references for keyspublic CachingMapDecorator(boolean weakKeys, int size)
weakKeys
- whether to use weak references for keyssize
- the initial cache sizepublic CachingMapDecorator(Map 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 decorateMethod Detail |
---|
public int size()
public boolean isEmpty()
public boolean containsKey(Object key)
containsKey
in interface Map
public boolean containsValue(Object value)
containsValue
in interface Map
public Object put(Object key, Object value)
public Object remove(Object key)
public void putAll(Map t)
public void clear()
public Set keySet()
public Collection values()
public Set entrySet()
public Object get(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.
create(Object)
protected abstract Object create(Object key)
get
if there is no value cached already.
key
- the cache keyget(Object)
public String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |