edu.toronto.cs.util.caching
Class NullCache

java.lang.Object
  extended by edu.toronto.cs.util.caching.NullCache
All Implemented Interfaces:
Cache

public class NullCache
extends java.lang.Object
implements Cache

Cache that does absolutely no caching.


Constructor Summary
NullCache()
          Creates new NullCache.
 
Method Summary
 void clear()
          Clears the cache.
 boolean containsKey(java.lang.Object key)
          Checks whether the cache contains a value associated with the key.
 boolean containsValue(java.lang.Object value)
          Checks whether the cache contains the specified value.
 java.util.Set entrySet()
          Returns a Set representation of the mapping.
 java.lang.Object get(java.lang.Object key)
          Retrieves a value with the specified key from the cache.
 boolean isEmpty()
          Determines if the cache is empty.
 boolean isFull()
          Determines if the cache is at its maximum capacity.
 java.util.Set keySet()
          Gets the set of all the keys registered in the cahce.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Stores a value and assotiates a key with it.
 java.lang.Object remove(java.lang.Object key)
          Removes a value with the specified key from the cache.
 void resize(int size)
          Sets the maximum cache size.
 int size()
          Returns the number of elements in cache.
 java.util.Collection values()
          Gets a collection view of the values contained in this map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NullCache

public NullCache()
Creates new NullCache.

Method Detail

clear

public void clear()
Clears the cache.

Specified by:
clear in interface Cache

containsKey

public boolean containsKey(java.lang.Object key)
Checks whether the cache contains a value associated with the key.

Specified by:
containsKey in interface Cache
Parameters:
key - -- the key to look for.
Returns:
-- true if the key is in the cache; false otherwise.

containsValue

public boolean containsValue(java.lang.Object value)
Checks whether the cache contains the specified value.

Specified by:
containsValue in interface Cache
Parameters:
value - -- the value to look for.
Returns:
-- true if the value is in the cache; false otherwise.

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Stores a value and assotiates a key with it. If the key already has a value associated with it, the old value is replaced by the supplied new value and returned.

Specified by:
put in interface Cache
Parameters:
key - -- the key associated with the value.
value - -- value to store.
Returns:
-- the value that has been previously associated with the key or null if none exists.

get

public java.lang.Object get(java.lang.Object key)
Retrieves a value with the specified key from the cache.

Specified by:
get in interface Cache
Parameters:
key - -- the key associated with the value.
Returns:
-- the value associated with the key or null if not found.

remove

public java.lang.Object remove(java.lang.Object key)
Removes a value with the specified key from the cache. If there's no mapping for the specified key, does nothing.

Specified by:
remove in interface Cache
Parameters:
key - -- the key associated with the value.
Returns:
-- the value being removed or null if no such key exists.

size

public int size()
Returns the number of elements in cache.

Specified by:
size in interface Cache
Returns:
-- the number of elements in cashe.

isEmpty

public boolean isEmpty()
Determines if the cache is empty.

Specified by:
isEmpty in interface Cache
Returns:
-- true if th cache is empty and false otherwise.

isFull

public boolean isFull()
Determines if the cache is at its maximum capacity.

Returns:
-- true if maximum capacity has been reached and false otherwise.

values

public java.util.Collection values()
Gets a collection view of the values contained in this map.

Specified by:
values in interface Cache
Returns:
-- collection view of the values contained in this map.

keySet

public java.util.Set keySet()
Gets the set of all the keys registered in the cahce.

Specified by:
keySet in interface Cache
Returns:
-- the Set of all keys in cache.

entrySet

public java.util.Set entrySet()
Returns a Set representation of the mapping.

Specified by:
entrySet in interface Cache
Returns:
-- a Set representing the cache.

resize

public void resize(int size)
Sets the maximum cache size. If the cache is currently bigger than specified size, the excess elements get purged.

Specified by:
resize in interface Cache
Parameters:
size - -- the maximum cache size.