Extension SDK 10.1.2

oracle.ide.util
Class WeakCache

java.lang.Object
  extended byoracle.ide.util.WeakCache

public class WeakCache
extends java.lang.Object

This class provides essentially a map with strongly referenced keys and weakly referenced values. Getting a value whose reference has been cleared gets null.

By default, when the reference to a value is found to have been cleared, the corresponding key is removed. If the keyRetained property is set to true, the key is retained instead. This class stands in contrast with WeakHashMap, which is a map with weakly referenced keys and strongly referenced values.


Nested Class Summary
static class WeakCache.Entry
          A class whose instances wrap a key and its corresponding value.
 
Constructor Summary
WeakCache()
           
 
Method Summary
 void clear()
          Clear all keys and values from this cache.
 boolean containsKey(java.lang.Object key)
           
 java.util.List entries()
          Creates a list of the key/value pairs of this map.
 java.lang.Object get(java.lang.Object key)
          Gets a value corresponding to a key from this cache, or null if the key is not present or the reference to the value has been cleared.
 boolean isKeyRetained()
          Gets whether keys are retained once the reference to the corresponding values is cleared.
 java.util.Iterator iterator()
          Creates an iterator over the values of this map.
 java.util.Set keys()
          Gets a set containing the keys of this cache.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Puts a value corresponding to a key into this cache.
 java.lang.Object remove(java.lang.Object key)
          Removes a key and the corresponding value from this cache.
 void setKeyRetained(boolean retained)
          Sets whether keys are retained once the reference to the corresponding value is cleared.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WeakCache

public WeakCache()
Method Detail

setKeyRetained

public void setKeyRetained(boolean retained)
Sets whether keys are retained once the reference to the corresponding value is cleared.


isKeyRetained

public boolean isKeyRetained()
Gets whether keys are retained once the reference to the corresponding values is cleared.


containsKey

public boolean containsKey(java.lang.Object key)

get

public java.lang.Object get(java.lang.Object key)
Gets a value corresponding to a key from this cache, or null if the key is not present or the reference to the value has been cleared. If the keyRetained property is false, the key is also removed from the cache.


put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Puts a value corresponding to a key into this cache. The value is held with a weak reference.

Parameters:
key -
value -
Returns:
the old value corresponding to the key, or null if the key was not present, the value was null, or the reference to the value was cleared.

remove

public java.lang.Object remove(java.lang.Object key)
Removes a key and the corresponding value from this cache.

Parameters:
key - The key to remove.
Returns:
The value removed, or null if the key is not present or the reference to the value was cleared.

keys

public java.util.Set keys()
Gets a set containing the keys of this cache. Note that this set is not backed by the cache.


iterator

public java.util.Iterator iterator()
Creates an iterator over the values of this map. The iterator strongly references the values.


entries

public java.util.List entries()
Creates a list of the key/value pairs of this map. The list strongly references the values. Note that this list is not backed by the cache.

Returns:
a List of WeakCache.Entry objects.

clear

public void clear()
Clear all keys and values from this cache.


Extension SDK

 

Copyright © 1997, 2004, Oracle. All rights reserved.