jgroup.util
Class CacheMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by jgroup.util.CacheMap<K,V>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<K,V>

public class CacheMap<K,V>
extends java.util.HashMap<K,V>

Implementation of a map with limited access times to a key/value pair. When an entry is inserted in the map, you must specify the number of times the entry can be retrieved before it is inaccessible/removed.

This map can be useful when caching objects, and you need a way to remove old items from the cache.

Author:
Rohnny Moland
See Also:
Serialized Form

Constructor Summary
CacheMap()
           
 
Method Summary
 void clear()
          Clear the map.
 V get(java.lang.Object key)
          Returns the value of the given key, if key is accessible.
 V put(K key, V value)
           
 void put(K key, V value, int maxAccesses)
          Insert a key/value in a HashMap, and set the number of times it can be accessed.
 void putAll(java.util.Map<? extends K,? extends V> m)
           
 int size()
          Returns the size of cache map
 java.lang.String toString()
           
 
Methods inherited from class java.util.HashMap
clone, containsKey, containsValue, entrySet, isEmpty, keySet, remove, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

CacheMap

public CacheMap()
Method Detail

get

public V get(java.lang.Object key)
Returns the value of the given key, if key is accessible. If not, return null.

Specified by:
get in interface java.util.Map<K,V>
Overrides:
get in class java.util.HashMap<K,V>

put

public void put(K key,
                V value,
                int maxAccesses)
Insert a key/value in a HashMap, and set the number of times it can be accessed.


put

public V put(K key,
             V value)
Specified by:
put in interface java.util.Map<K,V>
Overrides:
put in class java.util.HashMap<K,V>

putAll

public void putAll(java.util.Map<? extends K,? extends V> m)
Specified by:
putAll in interface java.util.Map<K,V>
Overrides:
putAll in class java.util.HashMap<K,V>

clear

public void clear()
Clear the map.

Specified by:
clear in interface java.util.Map<K,V>
Overrides:
clear in class java.util.HashMap<K,V>

size

public int size()
Returns the size of cache map

Specified by:
size in interface java.util.Map<K,V>
Overrides:
size in class java.util.HashMap<K,V>

toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractMap<K,V>


Copyright © 1998-2006 The Jgroup/ARM development team. All Rights Reserved.