org.jaffa.cache
Class SimpleCache

java.lang.Object
  extended byorg.jaffa.cache.SimpleCache
All Implemented Interfaces:
ICache

public class SimpleCache
extends Object
implements ICache

This is a very simple implementation of the ICache interface. It uses a HashMap for caching. This class provides no features to deal with low-memory problems. Note that this implementation is not synchronized. If multiple threads access this cache concurrently, and at least one of the threads modifies the cache structurally, it must be synchronized externally.

Author:
GautamJ

Constructor Summary
SimpleCache()
          Creates a new instance of SimpleCache
 
Method Summary
 void clear()
          Removes all mappings from this cache.
 boolean containsKey(Object key)
          Returns true if this cache contains a mapping for the specified key.
 Object get(Object key)
          Returns the value to which cache maps the specified key.
 boolean isEmpty()
          Returns true if this cache contains no key-value mappings.
 Set keySet()
          Returns a set view of the keys contained in this cache.
 void put(Object key, Object value)
          Associates the specified value with the specified key in this cache.
 void remove(Object key)
          Removes the mapping for this key from this cache if it is present.
 int size()
          Returns the number of key-value mappings in this cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleCache

public SimpleCache()
Creates a new instance of SimpleCache

Method Detail

clear

public void clear()
Removes all mappings from this cache.

Specified by:
clear in interface ICache

containsKey

public boolean containsKey(Object key)
Returns true if this cache contains a mapping for the specified key.

Specified by:
containsKey in interface ICache
Parameters:
key - key whose presence in this cache is to be tested.
Returns:
true if this cache contains a mapping for the specified key.

get

public Object get(Object key)
Returns the value to which cache maps the specified key. Returns null if the cache contains no mapping for this key. A return value of null does not necessarily indicate that the cache contains no mapping for the key; it's also possible that the cache explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Specified by:
get in interface ICache
Parameters:
key - key whose associated value is to be returned.
Returns:
the value to which this cache maps the specified key, or null if the cache contains no mapping for this key.

isEmpty

public boolean isEmpty()
Returns true if this cache contains no key-value mappings.

Specified by:
isEmpty in interface ICache
Returns:
true if this cache contains no key-value mappings.

keySet

public Set keySet()
Returns a set view of the keys contained in this cache. The set is backed by the cache, so changes to the cache are reflected in the set, and vice-versa. If the cache is modified while an iteration over the set is in progress, the results of the iteration are undefined.

Specified by:
keySet in interface ICache
Returns:
a set view of the keys contained in this cache.

put

public void put(Object key,
                Object value)
Associates the specified value with the specified key in this cache. If the cache previously contained a mapping for this key, the old value is replaced by the specified value.

Specified by:
put in interface ICache
Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.

remove

public void remove(Object key)
Removes the mapping for this key from this cache if it is present.

Specified by:
remove in interface ICache
Parameters:
key - key whose mapping is to be removed from the cache.

size

public int size()
Returns the number of key-value mappings in this cache.

Specified by:
size in interface ICache
Returns:
the number of key-value mappings in this cache.


Copyright © 2002-2004 JAFFA Project.