C
- the class types that are used as the cache keysT
- the cached value typepublic class ReflectionCache<C,T> extends Object
Constructor and Description |
---|
ReflectionCache(SerializableFunction<Class<C>,T> valueProvider)
Creates a new reflection cache with the given value provider.
|
Modifier and Type | Method and Description |
---|---|
static Registration |
addClearAllAction(Runnable action)
Adds an action that will be run when all reflection caches are cleared.
|
void |
clear()
Removes all mappings from this cache.
|
static void |
clearAll()
Clears all mappings from all reflection caches and related resources.
|
boolean |
contains(Class<? extends C> type)
Checks whether this cache contains an entry for the given type.
|
T |
get(Class<? extends C> type)
Gets a cached value.
|
public ReflectionCache(SerializableFunction<Class<C>,T> valueProvider)
CurrentInstance
is available to prevent accidentally caching values that are computed
differently depending on external circumstances.valueProvider
- a function that computes the cached value for a class, not
null
public T get(Class<? extends C> type)
type
- the type for which to get reflection resultspublic boolean contains(Class<? extends C> type)
type
- the type to check fortrue
if there is a mapping for the type,
false
if there is no mappingpublic void clear()
public static Registration addClearAllAction(Runnable action)
The actions are held with a weak reference, which typically means that the action will be ignored if the returned registration is garbage collected.
action
- the action to runclearAll()
public static void clearAll()
Copyright © 2018. All rights reserved.