edu.toronto.cs.util.caching
Class UnboundedMapCache

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

public class UnboundedMapCache
extends AbstractMapCache

Fairly simplistic unbounded caching.


Field Summary
 
Fields inherited from class edu.toronto.cs.util.caching.AbstractMapCache
cache
 
Constructor Summary
UnboundedMapCache()
          Create a new cache.
 
Method Summary
 java.lang.Object get(java.lang.Object key)
          Retrieves a value with the specified key from the cache.
 boolean isFull()
          Determines if the cache is at its maximum capacity.
 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.
 
Methods inherited from class edu.toronto.cs.util.caching.AbstractMapCache
clear, containsKey, containsValue, entrySet, isEmpty, keySet, size, values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UnboundedMapCache

public UnboundedMapCache()
Create a new cache.

Method Detail

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
Specified by:
put in class AbstractMapCache
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
Specified by:
get in class AbstractMapCache
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
Specified by:
remove in class AbstractMapCache
Parameters:
key - -- the key associated with the value.
Returns:
-- the value being removed or null if no such key exists.

isFull

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

Specified by:
isFull in class AbstractMapCache
Returns:
-- true if maximum capacity has been reached and false otherwise.

resize

public void resize(int size)
Description copied from class: AbstractMapCache
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
Specified by:
resize in class AbstractMapCache
Parameters:
size - -- the maximum cache size.