Package jade.util

Class 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 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 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.
      • put

        public Object put​(Object key,
                          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 Object remove​(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​(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.
        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​(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