jade.util
Class HashCache

java.lang.Object
  extended by jade.util.HashCache
All Implemented Interfaces:
Map

public class HashCache
extends java.lang.Object
implements Map

This class is a cache with fixed dimension that can be set in the constructur. All element are indexed with an hashcode. When an element is added and the cache is already full,the oldest element is deleted.

Version:
$Date: 2004-09-27 14:50:46 +0200 (lun, 27 set 2004) $ $Revision: 5378 $
Author:
Alessandro Chiarotto, Fabio Bellifemine - TILAB S.p.A.

Constructor Summary
HashCache(int cacheSize)
          Constructs a new, empty HashCache with the specified size.
 
Method Summary
 java.lang.Object add(java.lang.Object o)
          Adds the specified element to this hashcache if it is not already present.
 void clear()
          Clears the cache, removing all key-value pairs
 boolean contains(java.lang.Object o)
          Tests if the specified object is a key in this hashcache.
 boolean containsKey(java.lang.Object key)
          Returns true if this map contains a mapping for the specified key.
 java.lang.Object get(java.lang.Object key)
          Retrieves a cached element.
 boolean isEmpty()
          Returns true if this map contains no key-value mappings.
 Set keySet()
          Returns a set view of the keys contained in this map.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Adds a key-value pair to this cache
 java.lang.Object remove(java.lang.Object key)
          Remove an existing key-value pair from the cache
 int size()
          Returns the number of mappings in this map.
 Collection values()
          Returns 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

HashCache

public HashCache(int cacheSize)
Constructs a new, empty HashCache with the specified size.

Parameters:
cacheSize - is the size of this cache
Method Detail

add

public java.lang.Object add(java.lang.Object o)
Adds the specified element to this hashcache if it is not already present. If the cache is already full,the oldest element is deleted.

Parameters:
o - element to be added to this set.
Returns:
o the specified added object element.

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Adds a key-value pair to this cache

Specified by:
put in interface Map
Parameters:
key - The key with which the value can be retrieved in the future.
value - The value to store in the cache.
Returns:
The value previously associated to the key, if any.
See Also:
Map

remove

public java.lang.Object remove(java.lang.Object key)
Remove an existing key-value pair from the cache

Specified by:
remove in interface Map
Parameters:
o - The key to be removed (together with its associated value.
Returns:
The value associated to the given key, if any.
See Also:
Map

contains

public boolean contains(java.lang.Object o)
Tests if the specified object is a key in this hashcache. present. the oldest element is deleted.

Parameters:
o - element to be added to this set.
Returns:
true if the haschcache contains the object o, otherwise false

get

public java.lang.Object get(java.lang.Object key)
Retrieves a cached element. The retrieved element is also marked as the last used one, so that the cache replacement policy becomes LRU instead of FIFO.

Specified by:
get in interface Map
Parameters:
o - The
Returns:
the value to which this map maps the specified key, or null if the map contains no mapping for this key.
See Also:
Map

clear

public void clear()
Clears the cache, removing all key-value pairs

Specified by:
clear in interface Map
See Also:
Map

isEmpty

public boolean isEmpty()
Description copied from interface: Map
Returns true if this map contains no key-value mappings.

Specified by:
isEmpty in interface Map
Returns:
true if this map contains no key-value mappings.
See Also:
Map

keySet

public Set keySet()
Description copied from interface: Map
Returns a set view of the keys contained in this map.

Specified by:
keySet in interface Map
Returns:
a set view of the keys contained in this map.
See Also:
Map

values

public Collection values()
Description copied from interface: Map
Returns a Collection view of the values contained in this map.

Specified by:
values in interface Map
Returns:
the Collection of elements contained in this map.
See Also:
Map

containsKey

public boolean containsKey(java.lang.Object key)
Description copied from interface: Map
Returns true if this map contains a mapping for the specified key.

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

size

public int size()
Description copied from interface: Map
Returns the number of mappings in this map.

Specified by:
size in interface Map
See Also:
Map