org.jcreme.caches
Class LUFOCache

java.lang.Object
  extended byorg.jcreme.caches.BaseCache
      extended byorg.jcreme.caches.LUFOCache
All Implemented Interfaces:
Cache

public class LUFOCache
extends BaseCache

A Cache object using a Least Used First Out policy. The LUFO cache is based on a Least Used First Out algorithm to select the objects that are removed from the cache to make room. This implementation uses a TreeMap. It also uses an encapsulation of the keys that counts the calls to the cache to retrieve an object.

Version:
$Revision: 1.4 $
Author:
$Author: dbregeon $

Nested Class Summary
protected  class LUFOCache.LocalKey
          This class enable to store the original key and the number of occurences when the associated value was recovered from the cache.
 
Constructor Summary
LUFOCache()
          Creates new LUFOCache
LUFOCache(int minSize, int maxSize)
          Creates new LUFOCache
 
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.
 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.
protected  void removeOneElement()
          This method is called when room is needed to add a new object in the 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, setMaxSize, setReplacementPolicy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LUFOCache

public LUFOCache()
Creates new LUFOCache


LUFOCache

public LUFOCache(int minSize,
                 int maxSize)
Creates new LUFOCache

Parameters:
minSize - the initial size of the Cache.
maxSize - the maximum number of objects contained by the cache.
Method Detail

registerObject

public void registerObject(java.lang.Object key,
                           java.lang.Object value)
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.

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.

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.

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

removeOneElement

protected void removeOneElement()
This method is called when room is needed to add a new 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.

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.

getMap

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

Returns:
a map of the (key,value) contents of the cache.

registerAllObjects

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

Parameters:
m - the map that contains the objects (and keys) to use.

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.


Copyright 2006 null. All Rights Reserved.