com.sun.sgs.impl.util
Class CacheMap<K,V>

java.lang.Object
  extended by com.sun.sgs.impl.util.CacheMap<K,V>
Type Parameters:
K - the key type
V - the value type

public class CacheMap<K,V>
extends Object

A map with values that are softly-referenced. An entry is removed if its associated value gets garbage-collected, or, if the cache was constructed with a timeout, and entry is removed (lazily) when the timeout expires for that entry. A timeout is typically used to have the implementation remove values that become stale after a certain period of time. The implementation ensures that a caller will not have access to stale entries (i.e., entries whose timeout has expired).


Constructor Summary
CacheMap()
          Creates an instance of this class.
CacheMap(long entryTimeout)
          Creates an instance of this class with the specified entryTimeout.
 
Method Summary
 void clear()
          Removes all associations from this map.
 boolean containsKey(K key)
          Checks if the map contains the specified key.
 V get(K key)
          Returns the value associated with given key, or null if the key is not found.
 V put(K key, V value)
          Associates a value with given key, returning the value previously associated with key, or null if none is found.
 V remove(K key)
          Removes the association for the given key, returning the value previously associated with the key, or null if the key is not found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheMap

public CacheMap()
Creates an instance of this class.


CacheMap

public CacheMap(long entryTimeout)
Creates an instance of this class with the specified entryTimeout.

Parameters:
entryTimeout - an entry timeout, in milliseconds
Throws:
IllegalArgumentException - if entryTimeout is negative
Method Detail

put

public V put(K key,
             V value)
Associates a value with given key, returning the value previously associated with key, or null if none is found.

Parameters:
key - the key
value - the value
Returns:
the previous value or null

containsKey

public boolean containsKey(K key)
Checks if the map contains the specified key.

Parameters:
key - the key
Returns:
true if the map contains the key, else false

get

public V get(K key)
Returns the value associated with given key, or null if the key is not found.

Parameters:
key - the key
Returns:
the value associated with the key or null

remove

public V remove(K key)
Removes the association for the given key, returning the value previously associated with the key, or null if the key is not found.

Parameters:
key - the key
Returns:
the value previously associated with the key or null

clear

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


RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved