org.jcreme.caches
Class AggregateCache

java.lang.Object
  extended byorg.jcreme.caches.BaseCache
      extended byorg.jcreme.caches.AggregateCache
All Implemented Interfaces:
Cache, ModifiableCache

public class AggregateCache
extends BaseCache
implements ModifiableCache

This is a helper class. It should be specialized to store specific types. The actual cache is provided by one of the generic caches. This inner cache depends on the storage policy entered. The class can be used as is but developpers should subclass it to fit the needs of particular object subclasses.

Version:
$Revision: 1.3 $
Author:
$Author: dbregeon $

Constructor Summary
AggregateCache()
          Creates new AggregateCache
AggregateCache(int minSize, int maxSize, CachePolicy policy)
          Creates new BaseBondCache
 
Method Summary
 void clear()
          Removes all the objects from the Cache, leaving it empty.
 java.lang.Object[] getAllObjects()
          This method gives access to the full content of the cache.
 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.
protected  BaseCache getInnerCache()
          Provides access to the innerCache for subclasses that would need it.
 java.util.Map getMap()
          This method enables to access to the cache contents.
 java.lang.Object getObject(java.lang.Object key)
          Gives access to an object registered in the cache.
 int getSize()
          This methods gives the current size of the cache.
 void registerAllObjects(java.util.Map m)
          This is a convenience method.
 void registerObject(java.lang.Object key, java.lang.Object value)
          This method adds an object in the cache.
 void setMaxSize(int maxSize)
          This method modifies the maximum size of the cache.
 void setReplacementPolicy(CachePolicy policy)
          This method changes both the storage policy and the inner cache.
 void unregisterObject(java.lang.Object key)
          This method removes an object from the cache.
 
Methods inherited from class org.jcreme.caches.BaseCache
addCacheListener, buildEvent, fireElementAdded, fireElementRemoved, getCacheListeners, getMaxSize, getMinSize, getReplacementPolicy, removeCacheListener
 
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
addCacheListener, getCacheListeners, getMaxSize, getReplacementPolicy, removeCacheListener
 

Constructor Detail

AggregateCache

public AggregateCache(int minSize,
                      int maxSize,
                      CachePolicy policy)
               throws java.lang.IllegalArgumentException
Creates new BaseBondCache

Parameters:
minSize - the initial size of the cache (counted as a number of elements).
maxSize - the maximum size of the cache (counted as a number of elements).
policy - the policy used to store the objects.
Throws:
java.lang.IllegalArgumentException - if the policy is null.

AggregateCache

public AggregateCache()
Creates new AggregateCache

Method Detail

clear

public void clear()
Removes all the objects from the Cache, leaving it empty.

Specified by:
clear in interface Cache
Specified by:
clear in class BaseCache

setReplacementPolicy

public void setReplacementPolicy(CachePolicy policy)
                          throws java.lang.IllegalArgumentException
This method changes both the storage policy and the inner cache. All the objects contained in the cache remain under the new policy.

Specified by:
setReplacementPolicy in interface ModifiableCache
Overrides:
setReplacementPolicy in class BaseCache
Parameters:
policy - the policy to use to store objects.
Throws:
java.lang.IllegalArgumentException - when the policy is null.

getObject

public java.lang.Object getObject(java.lang.Object key)
Gives access to an object registered in the cache.

Specified by:
getObject in interface Cache
Specified by:
getObject in class BaseCache
Parameters:
key - the key used to register the searched object.
Returns:
the object stored in the cache. Null if no object was stored with this key.

getSize

public int getSize()
This methods gives the current size of the cache.

Specified by:
getSize in interface Cache
Specified by:
getSize in class BaseCache
Returns:
the number of objects currently stored in the cache.

unregisterObject

public void unregisterObject(java.lang.Object key)
This method removes an object from the cache.

Specified by:
unregisterObject in interface Cache
Specified by:
unregisterObject in class BaseCache
Parameters:
key - the key that was used to store the object in the cache.

getAllObjects

public java.lang.Object[] getAllObjects()
This method gives access to the full content of the cache.

Specified by:
getAllObjects in interface Cache
Specified by:
getAllObjects in class BaseCache
Returns:
an array containing all the objects stored in the cache.

registerObject

public void registerObject(java.lang.Object key,
                           java.lang.Object value)
                    throws CacheFullException
This method adds an object in the cache.

Specified by:
registerObject in interface Cache
Specified by:
registerObject in class BaseCache
Parameters:
key - the key that will be used to retrieve the object.
value - the object to store in the cache.
Throws:
CacheFullException - if the object could not be stored in the cache.

setMaxSize

public void setMaxSize(int maxSize)
This method modifies the maximum size of the cache.

Specified by:
setMaxSize in interface Cache
Overrides:
setMaxSize in class BaseCache
Parameters:
maxSize - the maximum number of objects that can be stored in the cache.

registerAllObjects

public void registerAllObjects(java.util.Map m)
                        throws CacheFullException
This is a convenience method. It enables to add to the cache all the objects present in the map.

Specified by:
registerAllObjects in interface Cache
Parameters:
m - the map that contains the objects (and keys) to use.
Throws:
CacheFullException - when the Cache would exceed its maximum size and no room can be made.

getMap

public java.util.Map getMap()
This method enables to access to the cache contents.

Specified by:
getMap in interface Cache
Returns:
a map of the (key,value) contents of the cache.

getAllObjects

public 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.

Specified by:
getAllObjects in interface Cache
Specified by:
getAllObjects in class BaseCache
Parameters:
type - the type to give to the object in the result array.
Returns:
an array of objects of the type.

getInnerCache

protected BaseCache getInnerCache()
Provides access to the innerCache for subclasses that would need it.

Returns:
the innerCache.


Copyright 2006 null. All Rights Reserved.