Package org.apache.struts2.inject.util
Class ReferenceCache<K,V> 
java.lang.Object
org.apache.struts2.inject.util.ReferenceMap<K,V>
 
org.apache.struts2.inject.util.ReferenceCache<K,V> 
- All Implemented Interfaces:
- Serializable,- Map<K,- V> 
Extends 
ReferenceMap to support lazy loading values by overriding
 create(Object).- Author:
- crazybob@google.com (Bob Lee)
- See Also:
- 
Nested Class SummaryNested classes/interfaces inherited from class org.apache.struts2.inject.util.ReferenceMapReferenceMap.Strategy
- 
Constructor SummaryConstructorsConstructorDescriptionEquivalent tonew ReferenceCache(STRONG, STRONG).ReferenceCache(ReferenceType keyReferenceType, ReferenceType valueReferenceType) 
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidcancel()Cancels the currentcreate(Object).protected abstract VOverride to lazy load values.static <K,V> ReferenceCache<K, V> of(ReferenceType keyReferenceType, ReferenceType valueReferenceType, Function<? super K, ? extends V> function) Returns aReferenceCachedelegating to the specifiedfunction.Methods inherited from class org.apache.struts2.inject.util.ReferenceMapclear, containsKey, containsValue, entrySet, getPutStrategy, isEmpty, keySet, put, putAll, putIfAbsent, putIfAbsentStrategy, putStrategy, remove, remove, replace, replace, replaceStrategy, size, valuesMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, replaceAll
- 
Constructor Details- 
ReferenceCache
- 
ReferenceCachepublic ReferenceCache()Equivalent tonew ReferenceCache(STRONG, STRONG).
 
- 
- 
Method Details- 
createOverride to lazy load values. Use as an alternative toReferenceMap.put(Object, Object). Invoked by getter if value isn't already cached. Must not returnnull. This method will not be called again until the garbage collector reclaims the returned value.- Parameters:
- key- the key
- Returns:
- returned value
 
- 
getIf 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.- Specified by:
- getin interface- Map<K,- V> 
- Overrides:
- getin class- ReferenceMap<K,- V> 
- Parameters:
- key- the key
- Returns:
- return new created value
- Throws:
- NullPointerException- if- create(Object)returns null.
- CancellationException- if the creation is cancelled. See- cancel().
 
- 
cancelprotected void cancel()Cancels the currentcreate(Object). ThrowsCancellationExceptionto all clients currently blocked onget(Object).
- 
ofpublic static <K,V> ReferenceCache<K,V> of(ReferenceType keyReferenceType, ReferenceType valueReferenceType, Function<? super K, ? extends V> function) Returns aReferenceCachedelegating to the specifiedfunction. The specified function must not returnnull.- Type Parameters:
- K- type of key
- V- type of value
- Parameters:
- function- function
- keyReferenceType- key reference type
- valueReferenceType- value reference type
- Returns:
- reference cache
 
 
-