com.google.inject.util
Class ReferenceCache<K,V>
java.lang.Object
com.google.inject.util.ReferenceMap<K,V>
com.google.inject.util.ReferenceCache<K,V>
- All Implemented Interfaces:
- java.io.Serializable, java.util.Map<K,V>
public abstract class ReferenceCache<K,V>
- extends ReferenceMap<K,V>
Extends ReferenceMap
to support lazy loading values by overriding
create(Object)
.
- Author:
- crazybob@google.com (Bob Lee)
- See Also:
- Serialized Form
Method Summary |
protected abstract V |
create(K key)
Override to lazy load values. |
V |
get(java.lang.Object key)
If this map does not contain an entry for the given key, 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.google.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 |
ReferenceCache
public ReferenceCache(ReferenceType keyReferenceType,
ReferenceType valueReferenceType)
ReferenceCache
public ReferenceCache()
- Equivalent to
new ReferenceCache(STRONG, STRONG)
.
create
protected abstract V create(K key)
- Override to lazy load values. Use as an alternative to
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.
of
public static <K,V> ReferenceCache<K,V> of(ReferenceType keyReferenceType,
ReferenceType valueReferenceType,
Function<? super K,? extends V> function)
- Returns a
ReferenceCache
delegating to the specified function
. The specified function must not return null
.
get
public V get(java.lang.Object key)
-
If this map does not contain an entry for the given key, this method will
create a new value, put it in the map, and return it. The value
is canonical (i.e. only one value will be created for each key).
- Specified by:
get
in interface java.util.Map<K,V>
- Overrides:
get
in class ReferenceMap<K,V>
- Throws:
java.lang.NullPointerException
- if the value is null
java.util.concurrent.CancellationException
- if the value creation
is cancelled.
Copyright © {inceptionYear}-2008 null. All Rights Reserved.