TUM CCSM Commons

edu.tum.cs.commons.cache
Class CacheBase<I,H,E,X extends java.lang.Exception>

java.lang.Object
  extended by edu.tum.cs.commons.cache.CacheBase<I,H,E,X>
Type Parameters:
I - the index type of the cache
H - the hash map key type
E - the type stored in the cache
X - the type of exception thrown by the obtainItem(Object) method. Use the NeverThrownRuntimeException if no exception will be thrown.
Direct Known Subclasses:
LRUCacheBase, SoftRefCacheBase

public abstract class CacheBase<I,H,E,X extends java.lang.Exception>
extends java.lang.Object

Common base class for caches. This class basically works like a map that maps elements of type I to elements of type E. As this class uses a hash map and elements of type I are not necessarily suitable as hash map keys a special type (H) for the hash keys must be defined. Concrecte keys are determined by method getHashKey(I). Please note that making the hash type explicit as generic parameter is not due to implementation reasons but to make design more obvious.

Version:
$Rev: 26268 $
Author:
hummelb, $Author: juergens $
Rating:
GREEN Hash: A07537A9758D46A058FC18A23FBEB4FF

Constructor Summary
CacheBase()
           
 
Method Summary
protected abstract  H getHashKey(I identifier)
          Determine hash key for an identifier.
abstract  E getItem(I identifier)
          Obtain an item from the cache.
protected abstract  E obtainItem(I identifier)
          Extenders of the cache class must implemented that method to define the item acquisition mechanism.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheBase

public CacheBase()
Method Detail

getItem

public abstract E getItem(I identifier)
                   throws X extends java.lang.Exception
Obtain an item from the cache. If the item was not cached yet, it will be cached.

Parameters:
identifier - an object identifying the item to retrieve from the cache. This class' implementation works with a hash map so identifiers must adhere to the conventions for Object.hashcode().
Returns:
The item.
Throws:
X extends java.lang.Exception

obtainItem

protected abstract E obtainItem(I identifier)
                         throws X extends java.lang.Exception
Extenders of the cache class must implemented that method to define the item acquisition mechanism.

Parameters:
identifier - identifer unambiguously identifying the item.
Returns:
the item to cache.
Throws:
X extends java.lang.Exception

getHashKey

protected abstract H getHashKey(I identifier)
Determine hash key for an identifier. If the identifier itself is a suitable hash key, simply return it or better, use one of the straight cache implementations.

Parameters:
identifier -
Returns:
an object that is suitable hash key
See Also:
Object.hashCode()

TUM CCSM Commons

TUM CCSM Commons - 2.7