Package org.apache.oro.util
Class GenericCache
- java.lang.Object
-
- org.apache.oro.util.GenericCache
-
- All Implemented Interfaces:
java.io.Serializable
,Cache
- Direct Known Subclasses:
CacheLRU
public abstract class GenericCache extends java.lang.Object implements Cache, java.io.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 theCache
interface.- Since:
- 1.0
- See Also:
Cache
,CacheLRU
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description (package private) GenericCacheEntry[]
_cache
(package private) int
_numEntries
(package private) java.util.HashMap<java.lang.Object,java.lang.Object>
_table
static int
DEFAULT_CAPACITY
The default capacity to be used by the GenericCache subclasses provided with this package.private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description GenericCache(int cap)
The primary constructor for GenericCache.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
addElement(java.lang.Object key, java.lang.Object value)
Adds an element to the cache.int
capacity()
Returns the maximum number of elements that can be cached at one time.java.lang.Object
getElement(java.lang.Object key)
Gets an element from the cache.boolean
isFull()
Checks if the cache is full.java.util.Iterator<java.lang.Object>
keys()
Gets the cache objects names.int
size()
Returns the number of elements in the cache, not to be confused with thecapacity()
which returns the number of elements that can be held in the cache at one time.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
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
int _numEntries
-
_cache
GenericCacheEntry[] _cache
-
_table
java.util.HashMap<java.lang.Object,java.lang.Object> _table
-
-
Constructor Detail
-
GenericCache
GenericCache(int cap)
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:
cap
- The maximum capacity of the cache.
-
-
Method Detail
-
addElement
public abstract void addElement(java.lang.Object key, java.lang.Object value)
Description copied from interface:Cache
Adds an element to the cache.- Specified by:
addElement
in interfaceCache
- Parameters:
key
- Keyvalue
- Value
-
getElement
public java.lang.Object getElement(java.lang.Object key)
Description copied from interface:Cache
Gets an element from the cache.- Specified by:
getElement
in interfaceCache
- Parameters:
key
- Key- Returns:
- Element value
-
keys
public final java.util.Iterator<java.lang.Object> keys()
Gets the cache objects names.- Returns:
- Object names (keys)
-
size
public final int size()
Returns the number of elements in the cache, not to be confused with thecapacity()
which returns the number of elements that can be held in the cache at one time.
-
capacity
public final int capacity()
Returns the maximum number of elements that can be cached at one time.
-
isFull
public final boolean isFull()
Checks if the cache is full.- Returns:
true
if the cache is full,false
otherwise
-
-