|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jcreme.caches.BaseCache
This abstract cache is the base for policied caches. The policy element is not enforced in this class. It is up to the subclasses to enforce the policies.
Constructor Summary | |
protected |
BaseCache()
Creates new Cache |
protected |
BaseCache(CachePolicy policy)
Creates new Cache |
protected |
BaseCache(int minSize,
int maxSize,
CachePolicy policy)
Creates new Cache |
Method Summary | |
void |
addCacheListener(CacheListener listener)
To add a CacheListener for this cache. |
protected CacheEvent |
buildEvent(java.lang.Object element)
Convenience method to build events when the cache is modified. |
abstract void |
clear()
Removes all the objects from the Cache, leaving it empty. |
protected void |
fireElementAdded(CacheEvent evt)
Convenience method to fire events when the cache is modified. |
protected void |
fireElementRemoved(CacheEvent evt)
Convenience method to fire events when the cache is modified. |
abstract java.lang.Object[] |
getAllObjects()
Gives access to all the objects stored in the Cache. |
abstract java.lang.Object[] |
getAllObjects(java.lang.Class type)
This method gives the same result as the getAllObjects method but the objects in the result array are types with the parameter type. |
CacheListener[] |
getCacheListeners()
Gives access to the list of listeners that listen to this cache. |
int |
getMaxSize()
Gives access to the Cache's maximum size. |
protected int |
getMinSize()
Gives access to the Cache's minimum size. |
abstract java.lang.Object |
getObject(java.lang.Object key)
Gives access to an object registered in the cache. |
CachePolicy |
getReplacementPolicy()
Enables access to the policy currently used by the cache. |
abstract int |
getSize()
This methods gives the current size of the cache. |
abstract void |
registerObject(java.lang.Object key,
java.lang.Object value)
This method adds an object in the cache. |
void |
removeCacheListener(CacheListener listener)
To remove a CacheListener for this cache. |
void |
setMaxSize(int maxSize)
This method modifies the maximum size of the cache. |
protected void |
setReplacementPolicy(CachePolicy policy)
Enables to modify the policy of this Cache. |
abstract void |
unregisterObject(java.lang.Object key)
This method removes an object from the cache. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.jcreme.caches.Cache |
getMap, registerAllObjects |
Constructor Detail |
protected BaseCache()
protected BaseCache(CachePolicy policy)
policy
- the policy used by this cache.protected BaseCache(int minSize, int maxSize, CachePolicy policy)
minSize
- the initial size of the cache (number of objects).maxSize
- the maximum size of the cache (number of objects).policy
- the policy of this cache.Method Detail |
public void setMaxSize(int maxSize)
setMaxSize
in interface Cache
maxSize
- the maximum number of objects that can be stored in the cache.public CachePolicy getReplacementPolicy()
getReplacementPolicy
in interface Cache
protected void setReplacementPolicy(CachePolicy policy)
policy
- the new policy for the Cache.public abstract void registerObject(java.lang.Object key, java.lang.Object value) throws CacheFullException
registerObject
in interface Cache
key
- the key that will be used to retrieve the object.value
- the object to store in the cache.
CacheFullException
- if the object could not be stored in the cache.public abstract void unregisterObject(java.lang.Object key)
unregisterObject
in interface Cache
key
- the key that was used to store the object in the cache.public abstract java.lang.Object getObject(java.lang.Object key)
getObject
in interface Cache
key
- the key used to register the searched object.
public int getMaxSize()
getMaxSize
in interface Cache
protected int getMinSize()
public void addCacheListener(CacheListener listener)
addCacheListener
in interface Cache
listener
- a cache listener. It is silently ignored if it is null.public void removeCacheListener(CacheListener listener)
removeCacheListener
in interface Cache
listener
- a cache listener. It is silently ignored if it is null.protected void fireElementRemoved(CacheEvent evt)
evt
- a cache event.protected void fireElementAdded(CacheEvent evt)
evt
- a cache event.protected CacheEvent buildEvent(java.lang.Object element)
element
- the element that changed in the cache.
public abstract java.lang.Object[] getAllObjects()
getAllObjects
in interface Cache
public abstract void clear()
clear
in interface Cache
public abstract int getSize()
getSize
in interface Cache
public abstract java.lang.Object[] getAllObjects(java.lang.Class type)
getAllObjects
in interface Cache
type
- the type to give to the object in the result array.
public CacheListener[] getCacheListeners()
getCacheListeners
in interface Cache
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |