com.opencms.flex.util
Class CmsLruHashMap

java.lang.Object
  |
  +--java.util.AbstractMap
        |
        +--java.util.HashMap
              |
              +--com.opencms.flex.util.CmsLruHashMap
All Implemented Interfaces:
Cloneable, Map, Serializable

public class CmsLruHashMap
extends HashMap

A hash table based implementation of the Map interface with limited size and a "last-recently-used" cache policy of the mapped key/values.

Version:
$Revision: 1.8 $
Author:
Thomas Weckert (t.weckert@alkacon.com)
See Also:
CmsFlexLruCache, I_CmsFlexLruCacheObject, Serialized Form

Constructor Summary
CmsLruHashMap()
          Creates a LRU hash map with an initial capacity of (16), a load factor of (0.75), and a max. size of cacheable objects of (36).
CmsLruHashMap(int initialCapacity)
          Creates a LRU hash map with a given initial capacity, a load factor of (0.75), and a max. size of cacheable objects of (initialCapacity*3*0.75).
CmsLruHashMap(int initialCapacity, float loadFactor)
          Creates a LRU hash map with a given initial capacity, a given load factor, and a max. size of cacheable objects of (initialCapacity*3*loadFactor).
CmsLruHashMap(int initialCapacity, float loadFactor, int maxLruSize)
          Creates a LRU hash map with a given initial capacity, a given load factor, and a given max. size of cacheable objects.
CmsLruHashMap(int initialCapacity, int maxLruSize)
          Creates a LRU hash map with a given initial capacity, a load factor of (0.75), and a given max. size of cacheable objects.
 
Method Summary
 void clear()
          Removes all objects from this map.
protected  void finalize()
          Clears any allocated resources during finalization.
 Object get(Object key)
          Returns the value to which the specified key is mapped in this identity hash map, or null if the map contains no mapping for this key.
 CmsFlexLruCache getLruCache()
          Returns the internal cache used for the LRU policy.
 Object put(Object key, Object value)
          Associates the specified value with the specified key in this map.
 void putAll(Map t)
          Copies all of the mappings from the specified map to this map.
 Object remove(Object key)
          Removes the mapping for this key from this map if present.
 
Methods inherited from class java.util.HashMap
clone, containsKey, containsValue, entrySet, isEmpty, keySet, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

CmsLruHashMap

public CmsLruHashMap()
Creates a LRU hash map with an initial capacity of (16), a load factor of (0.75), and a max. size of cacheable objects of (36).


CmsLruHashMap

public CmsLruHashMap(int initialCapacity)
Creates a LRU hash map with a given initial capacity, a load factor of (0.75), and a max. size of cacheable objects of (initialCapacity*3*0.75).

Parameters:
initialCapacity - the initial capacity of the hash map

CmsLruHashMap

public CmsLruHashMap(int initialCapacity,
                     float loadFactor)
Creates a LRU hash map with a given initial capacity, a given load factor, and a max. size of cacheable objects of (initialCapacity*3*loadFactor).

Parameters:
initialCapacity - the initial capacity of the hash map
loadFactor - the load factor of the hash map before it is rehashed

CmsLruHashMap

public CmsLruHashMap(int initialCapacity,
                     int maxLruSize)
Creates a LRU hash map with a given initial capacity, a load factor of (0.75), and a given max. size of cacheable objects.

Parameters:
initialCapacity - the initial capacity of the hash map
maxLruSize - the max. count of cacheable objects

CmsLruHashMap

public CmsLruHashMap(int initialCapacity,
                     float loadFactor,
                     int maxLruSize)
Creates a LRU hash map with a given initial capacity, a given load factor, and a given max. size of cacheable objects.

Parameters:
initialCapacity - the initial capacity of the hash map
loadFactor - the load factor of the hash map before it is rehashed
maxLruSize - the max. count of cacheable objects
Method Detail

clear

public void clear()
Removes all objects from this map.

Specified by:
clear in interface Map
Overrides:
clear in class HashMap

finalize

protected void finalize()
                 throws Throwable
Clears any allocated resources during finalization.

Overrides:
finalize in class Object
Throwable

get

public Object get(Object key)
Returns the value to which the specified key is mapped in this identity hash map, or null if the map contains no mapping for this key.

A return value of null does not necessarily indicate that the map contains no mapping for the key; it is also possible that the map explicitly maps the key to null. The containsKey method may be used to distinguish these two cases.

Specified by:
get in interface Map
Overrides:
get in class HashMap
Parameters:
key - the key to look up
See Also:
Map.get(java.lang.Object)

put

public Object put(Object key,
                  Object value)
Associates the specified value with the specified key in this map.

If the map previously contained a mapping for this key, the old value is replaced.

Specified by:
put in interface Map
Overrides:
put in class HashMap
Parameters:
key - the key to store
value - the value to store
See Also:
Map.put(java.lang.Object, java.lang.Object)

putAll

public void putAll(Map t)
Copies all of the mappings from the specified map to this map.

These mappings will replace any mappings that this map had for any of the keys currently in the specified map.

Specified by:
putAll in interface Map
Overrides:
putAll in class HashMap
Parameters:
t - the map to store
See Also:
Map.putAll(java.util.Map)

remove

public Object remove(Object key)
Removes the mapping for this key from this map if present.

Specified by:
remove in interface Map
Overrides:
remove in class HashMap
Parameters:
key - the key to remove
See Also:
Map.remove(java.lang.Object)

getLruCache

public CmsFlexLruCache getLruCache()
Returns the internal cache used for the LRU policy.

Returns:
the internal cache used for the LRU policy