|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectwt.templateutil.processor.MostRecentlyUsedCache
This class is intended to be used as a most-recently-used cache. Extend this class with an anonymous inner class and provide the method. The values stored in the cache can be null, but the key used to store the values cannot be null.
This class does not do any synchronization.
Nested Class Summary | |
private class |
MostRecentlyUsedCache.LeastRecentlyUsedIterator
|
private static class |
MostRecentlyUsedCache.ValueHolder
|
Field Summary | |
private Map |
cache
Map that stores MostRecentlyUsedCache.ValueHolder s keyed by MostRecentlyUsedCache.ValueHolder.key . |
private MostRecentlyUsedCache.ValueHolder |
listHead
Dummy head node of the doubly-linked list. |
Constructor Summary | |
MostRecentlyUsedCache()
Default constructor. |
|
MostRecentlyUsedCache(int initialCapacity)
Constructor. |
|
MostRecentlyUsedCache(int initialCapacity,
float loadFactor)
Constructor. |
Method Summary | |
private void |
addMostRecentlyUsed(MostRecentlyUsedCache.ValueHolder holder)
|
Map.Entry |
cache(Object key,
Object value)
Add the value to the cache, storing it under the specified key . |
void |
clear()
Remove all entries from the cache. |
private void |
clearList()
|
private MostRecentlyUsedCache.ValueHolder |
getLeastRecentlyUsed()
|
private void |
insertAfter(MostRecentlyUsedCache.ValueHolder previous,
MostRecentlyUsedCache.ValueHolder holder)
|
private boolean |
isListEmpty()
|
Iterator |
iterator()
Returns an MostRecentlyUsedCache.LeastRecentlyUsedIterator that iterates on the Map.Entry elements stored in this cache, in order of least recently used to most
recently used. |
Object |
lookup(Object key)
Look in the cache to find a cached value. |
void |
readExternal(ObjectInput in)
|
protected abstract boolean |
removeEldestEntry(Map.Entry eldest)
Override this method as described in LinkedHashMap.removeEldestEntry(java.util.Map.Entry) . |
private void |
removeFromList(MostRecentlyUsedCache.ValueHolder holder)
|
int |
size()
Get the number of entries currently in the cache. |
Object |
uncache(Object key)
Remove a cached value from the cache if there is a value is cached under key . |
void |
writeExternal(ObjectOutput out)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private Map cache
MostRecentlyUsedCache.ValueHolder
s keyed by MostRecentlyUsedCache.ValueHolder.key
.
private MostRecentlyUsedCache.ValueHolder listHead
Constructor Detail |
public MostRecentlyUsedCache()
public MostRecentlyUsedCache(int initialCapacity)
HashMap.HashMap(int)
public MostRecentlyUsedCache(int initialCapacity, float loadFactor)
HashMap.HashMap(int, float)
Method Detail |
protected abstract boolean removeEldestEntry(Map.Entry eldest)
LinkedHashMap.removeEldestEntry(java.util.Map.Entry)
.
public int size()
public Iterator iterator()
MostRecentlyUsedCache.LeastRecentlyUsedIterator
that iterates on the Map.Entry
elements stored in this cache, in order of least recently used to most
recently used. If this cache is modified, even by a call to lookup(java.lang.Object)
, any iterators are invalidated and must not be used. But unlike the
standard Java collection iterators, this iterator does try and catch this error.
public Map.Entry cache(Object key, Object value)
value
to the cache, storing it under the specified key
. removeEldestEntry(java.util.Map.Entry)
will
be called after this cache has been updated and can determine if the eldest entry in this cache should be removed. If removeEldestEntry(java.util.Map.Entry)
returns true
, the entry will be removed from this cache and returned by this method. If
removeEldestEntry(java.util.Map.Entry)
returns false, this method will not remove the entry and will return null
.
key
- The key value under which the value
is stored.value
- The value to store in the cache.public Object lookup(Object key)
key
- The key value to use to lookup the cached value.
key
.public Object uncache(Object key)
key
.
key
- The key whose cached value is removed from the cache.
key
.public void clear()
private boolean isListEmpty()
private void clearList()
private MostRecentlyUsedCache.ValueHolder getLeastRecentlyUsed()
private void addMostRecentlyUsed(MostRecentlyUsedCache.ValueHolder holder)
private void insertAfter(MostRecentlyUsedCache.ValueHolder previous, MostRecentlyUsedCache.ValueHolder holder)
private void removeFromList(MostRecentlyUsedCache.ValueHolder holder)
public void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
IOException
ClassNotFoundException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |