Package jade.util
Class HashCache
- java.lang.Object
-
- jade.util.HashCache
-
- All Implemented Interfaces:
Map
public class HashCache extends 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$ $Revision$
- Author:
- Alessandro Chiarotto, Fabio Bellifemine - TILAB S.p.A.
-
-
Constructor Summary
Constructors Constructor Description HashCache(int cacheSize)Constructs a new, empty HashCache with the specified size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Objectadd(Object o)Adds the specified element to this hashcache if it is not already present.voidclear()Clears the cache, removing all key-value pairsbooleancontains(Object o)Tests if the specified object is a key in this hashcache.booleancontainsKey(Object key)Returns true if this map contains a mapping for the specified key.Objectget(Object key)Retrieves a cached element.booleanisEmpty()Returns true if this map contains no key-value mappings.SetkeySet()Returns a set view of the keys contained in this map.Objectput(Object key, Object value)Adds a key-value pair to this cacheObjectremove(Object key)Remove an existing key-value pair from the cacheintsize()Returns the number of mappings in this map.Collectionvalues()Returns a Collection view of the values contained in this map.
-
-
-
Method Detail
-
add
public Object add(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.
-
contains
public boolean contains(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 Object get(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.
-
clear
public void clear()
Clears the cache, removing all key-value pairs
-
isEmpty
public boolean isEmpty()
Description copied from interface:MapReturns true if this map contains no key-value mappings.
-
keySet
public Set keySet()
Description copied from interface:MapReturns a set view of the keys contained in this map.
-
values
public Collection values()
Description copied from interface:MapReturns a Collection view of the values contained in this map.
-
containsKey
public boolean containsKey(Object key)
Description copied from interface:MapReturns true if this map contains a mapping for the specified key.- Specified by:
containsKeyin interfaceMap- 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
-
-