dsto.dfc.collections.cache
Class AbstractCache

java.lang.Object
  extended by dsto.dfc.collections.cache.AbstractCache
All Implemented Interfaces:
Cache, Serializable
Direct Known Subclasses:
CacheLRU

public abstract class AbstractCache
extends Object
implements Cache, Serializable

This is the base class for all cache implementations provided in the org.apache.oro.util package. To derive a subclass from GenericCache only the ... methods need be overridden. Although 4 subclasses of GenericCache are provided with this package, users may not derive subclasses from this class. Rather, users should create their own implmentations of the Cache interface.

Since:
1.0
Version:
@version@
Author:
Daniel F. Savarese
See Also:
Cache, CacheLRU, Serialized Form

Field Summary
protected  CacheEntry[] cache
           
static int DEFAULT_CAPACITY
          The default capacity to be used by the GenericCache subclasses provided with this package.
protected  int numEntries
           
protected  HashMap table
           
 
Constructor Summary
protected AbstractCache(int capacity)
          The primary constructor for GenericCache.
 
Method Summary
 int capacity()
          Returns the maximum number of elements that can be cached at one time.
 Object get(Object key)
           
 boolean isFull()
           
 Iterator keys()
           
abstract  Object put(Object key, Object value)
          Put an object into the cache.
 int size()
          Returns the number of elements in the cache, not to be confused with the capacity()which returns the number of elements that can be held in the cache at one time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CAPACITY

public static final int DEFAULT_CAPACITY
The default capacity to be used by the GenericCache subclasses provided with this package. Its value is 20.

See Also:
Constant Field Values

numEntries

protected int numEntries

cache

protected CacheEntry[] cache

table

protected HashMap table
Constructor Detail

AbstractCache

protected AbstractCache(int capacity)
The primary constructor for GenericCache. It has default access so it will only be used within the package. It initializes _table to a Hashtable of capacity equal to the capacity argument, _cache to an array of size equal to the capacity argument, and _numEntries to 0.

Parameters:
capacity - The maximum capacity of the cache.
Method Detail

put

public abstract Object put(Object key,
                           Object value)
Description copied from interface: Cache
Put an object into the cache.

Specified by:
put in interface Cache
Parameters:
key - The key.
value - The value to cache.
Returns:
The object that this one replaced, if any, within the cache.

get

public Object get(Object key)
Specified by:
get in interface Cache

keys

public Iterator keys()

size

public int size()
Returns the number of elements in the cache, not to be confused with the capacity()which returns the number of elements that can be held in the cache at one time.

Specified by:
size in interface Cache
Returns:
The current size of the cache (i.e., the number of elements currently cached).

capacity

public int capacity()
Returns the maximum number of elements that can be cached at one time.

Specified by:
capacity in interface Cache
Returns:
The maximum number of elements that can be cached at one time.

isFull

public boolean isFull()


Copyright © 2008 Commonwealth of Australia