|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.opensymphony.xwork2.inject.util.ReferenceMap<K,V> com.opensymphony.xwork2.inject.util.ReferenceCache<K,V>
public abstract class ReferenceCache<K,V>
Extends ReferenceMap
to support lazy loading values by overriding
create(Object)
.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.opensymphony.xwork2.inject.util.ReferenceMap |
---|
ReferenceMap.Strategy |
Constructor Summary | |
---|---|
ReferenceCache()
Equivalent to new ReferenceCache(STRONG, STRONG) . |
|
ReferenceCache(ReferenceType keyReferenceType,
ReferenceType valueReferenceType)
|
Method Summary | ||
---|---|---|
protected void |
cancel()
Cancels the current create(Object) . |
|
protected abstract V |
create(K key)
Override to lazy load values. |
|
V |
get(Object key)
If this map does not contain an entry for the given key and create(Object) has been overridden, this method will create a new
value, put it in the map, and return it. |
|
static
|
of(ReferenceType keyReferenceType,
ReferenceType valueReferenceType,
Function<? super K,? extends V> function)
Returns a ReferenceCache delegating to the specified function . |
Methods inherited from class com.opensymphony.xwork2.inject.util.ReferenceMap |
---|
clear, containsKey, containsValue, entrySet, getPutStrategy, isEmpty, keySet, put, putAll, putIfAbsent, putIfAbsentStrategy, putStrategy, remove, remove, replace, replace, replaceStrategy, size, 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 ReferenceCache(ReferenceType keyReferenceType, ReferenceType valueReferenceType)
public ReferenceCache()
new ReferenceCache(STRONG, STRONG)
.
Method Detail |
---|
protected abstract V create(K key)
ReferenceMap.put(Object,Object)
. Invoked by getter if value isn't already cached.
Must not return null
. This method will not be called again until
the garbage collector reclaims the returned value.
public V get(Object key)
create(Object)
has been overridden, this method will create a new
value, put it in the map, and return it.
get
in interface Map<K,V>
get
in class ReferenceMap<K,V>
NullPointerException
- if create(Object)
returns null.
CancellationException
- if the creation is
cancelled. See cancel()
.protected void cancel()
create(Object)
. Throws CancellationException
to all clients currently
blocked on get(Object)
.
public static <K,V> ReferenceCache<K,V> of(ReferenceType keyReferenceType, ReferenceType valueReferenceType, Function<? super K,? extends V> function)
ReferenceCache
delegating to the specified function
. The specified function must not return null
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |