A
- T
- public abstract class AbstractCachingAdapterFactory<A,T> extends java.lang.Object implements AdapterFactory<A,T>
AbstractCachingAdapterFactory
class may be used to implement
an AdapterFactory
that provides caching of target instances
keyed by their respective adaptable objects.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAX_CACHE_SIZE
The default maximum cache size.
|
Constructor and Description |
---|
AbstractCachingAdapterFactory() |
Modifier and Type | Method and Description |
---|---|
T |
adapt(A obj)
Adapt the given object to the target type.
|
abstract T |
adaptImpl(A obj)
Perform the adaptation of the given object to the declared target type.
|
protected void |
addToCache(A adaptable,
T target)
Add the given target instance for the given adaptable object to the cache.
|
protected void |
clearCache()
Removes all entries from the cache.
|
protected T |
findInCache(A adaptable)
Find the target instance for the given adaptable object in the cache.
|
protected int |
getMaxCacheSize()
Get the maximum number of entries to be cached.
|
protected void |
removeFromCache(A adaptable)
Remove the adaptable object as well as its adapted type from the cache.
|
protected boolean |
shouldRemoveFromCache(java.util.Map.Entry<A,T> entry)
Determine if the given entry should be removed from the cache.
|
public static final int DEFAULT_MAX_CACHE_SIZE
protected int getMaxCacheSize()
DEFAULT_MAX_CACHE_SIZE
.protected boolean shouldRemoveFromCache(java.util.Map.Entry<A,T> entry)
entry
- the candidate to be removed from the cachetrue
if the given entry should be removed from the
cache, false
otherwiseprotected final T findInCache(A adaptable)
adaptable
- the object for which to find the cached target instancenull
otherwiseprotected final void addToCache(A adaptable, T target)
adaptable
- the adaptable objecttarget
- the target instanceprotected final void removeFromCache(A adaptable)
adaptable
- the adaptable objectprotected final void clearCache()
public final T adapt(A obj)
adaptImpl(Object)
method is invoked, its return value stored in the cache and returned to the
caller.adapt
in interface AdapterFactory<A,T>
obj
- the object to be adaptednull
if the given object could
not be adaptedpublic abstract T adaptImpl(A obj)
Note: this method is public for internal adapter framework reasons. This method is not intended to be called by clients.
obj
- the object to be adaptednull
if the given object could
not be adapted