|
qflib 0.98.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--de.qfs.lib.util.MRUCache
This is a cache that stores only a certain number of resources. If more resources are added, only the most recently used ones are kept.
The MRUCache is based on a MultiMap
, so it can store
different kinds of resources distinguished by a key. The size limit of the
cache applies to the total number of resorces stored independent of their
type.
When a resource is retrieved with get
, it is
automatically removed from the MRUCache.
If you just want to store resources of one kind, there is a simplified
interface of get()
and put(Object)
where you don't need to provide a key.
You cannot store the same resource more than once, not even using different keys.
Inner Class Summary | |
static class |
MRUCache.UnitTest
Test cases for the MRUCache class. |
Constructor Summary | |
MRUCache(int size)
Create a new MRUCache. |
Method Summary | |
void |
addMRUCacheListener(MRUCacheListener listener)
Add a listener for dropped resources to the MRUCache. |
protected void |
fireResourceDropped(java.lang.Object key,
java.lang.Object resource)
Notify all listeners about a resource dropped from the cache. |
java.lang.Object |
get()
Get a resource from the MRUCache. |
java.lang.Object |
get(java.lang.Object key)
Get a resource from the MRUCache. |
int |
getCurrentSize()
Query the current size of the MRUCache. |
int |
getMaximumSize()
Query the maximum size of the MRUCache. |
void |
put(java.lang.Object resource)
Store a resource in the MRUCache. |
void |
put(java.lang.Object key,
java.lang.Object resource)
Store a resource in the MRUCache. |
void |
removeMRUCacheListener(MRUCacheListener listener)
Remove a listener for dropped resources from the MRUCache. |
void |
setMaximumSize(int size)
Set the maximum size of the MRUCache. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public MRUCache(int size)
size
- The maximum number of resources to keep.Method Detail |
public java.lang.Object get()
public java.lang.Object get(java.lang.Object key)
key
- The key for the resource.public void put(java.lang.Object resource)
resource
- The resource to store.public void put(java.lang.Object key, java.lang.Object resource)
key
- The key to store the resource under.resource
- The resource to store.public int getMaximumSize()
public void setMaximumSize(int size)
size
- The maximum number of resources allowed for this cache.public int getCurrentSize()
public void addMRUCacheListener(MRUCacheListener listener)
listener
- The listener to add.public void removeMRUCacheListener(MRUCacheListener listener)
listener
- The listener to remove.protected void fireResourceDropped(java.lang.Object key, java.lang.Object resource)
key
- The key the resource was stored under.resource
- The dropped resource.
|
qflib 0.98.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |