Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.5.0)

E13403-06


oracle.javatools.util
Class WeakCache<K,V>

java.lang.Object
  extended by oracle.javatools.util.WeakCache<K,V>


public class WeakCache<K,V>
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<K,V>
          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<WeakCache.Entry<K,V>> entries()
          Creates a list of the key/value pairs of this map.
 V get(K 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<V> iterator()
          Creates an iterator over the values of this map.
 java.util.Set<K> keys()
          Gets a set containing the keys of this cache.
 V put(K key, V value)
          Puts a value corresponding to a key into this cache.
 V remove(K 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 V get(K 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 V put(K key,
             V 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 V remove(K 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<K> 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<V> iterator()
Creates an iterator over the values of this map. The iterator strongly references the values.
Returns:
an iterator over the map values. The returned iterator is non-modifiable. Calling Iterator.remove() on the returned Iterator will throw UnsupportedOperationException.

entries

public java.util.List<WeakCache.Entry<K,V>> 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.

Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.5.0)

E13403-06


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