edu.emory.mathcs.util.collections
Class AsyncWeakValueHashMap

java.lang.Object
  extended byjava.util.AbstractMap
      extended byedu.emory.mathcs.backport.java.util.AbstractMap
          extended byedu.emory.mathcs.util.collections.AsyncWeakValueMap
              extended byedu.emory.mathcs.util.collections.AsyncWeakValueHashMap
All Implemented Interfaces:
ConcurrentMap, java.util.Map

public class AsyncWeakValueHashMap
extends edu.emory.mathcs.util.collections.AsyncWeakValueMap

Hash map that refers to values via weak references, thus not keeping them from garbage collection, asynchronously removing entries which values have been unreferenced and garbage collected. This class is a companion to WeakHashMap.

Version:
1.0
Author:
Dawid Kurzyniec

Nested Class Summary
 
Nested classes inherited from class edu.emory.mathcs.backport.java.util.AbstractMap
AbstractMap.SimpleEntry, AbstractMap.SimpleImmutableEntry
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Constructor Summary
AsyncWeakValueHashMap()
          Creates new AsyncWeakValueHashMap with a default initial capacity and a default load factor.
AsyncWeakValueHashMap(int initialCapacity)
          Creates new AsyncWeakValueHashMap with specified initial capacity and a default load factor.
AsyncWeakValueHashMap(int initialCapacity, float loadFactor)
          Creates new AsyncWeakValueHashMap with specified initial capacity and load factor.
AsyncWeakValueHashMap(java.util.Map t)
          Creates new AsyncWeakValueHashMap with specified initial capacity and a default load factor, and copies to it all the mappings from the specified map.
 
Method Summary
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set entrySet()
           
 java.lang.Object get(java.lang.Object key)
           
 boolean isEmpty()
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 void putAll(java.util.Map t)
           
 java.lang.Object putIfAbsent(java.lang.Object key, java.lang.Object value)
          If the specified key is not already associated with a value, associate it with the given value.
 java.lang.Object remove(java.lang.Object key)
           
 boolean remove(java.lang.Object key, java.lang.Object value)
          Removes the entry for a key only if currently mapped to a given value.
 java.lang.Object replace(java.lang.Object key, java.lang.Object newVal)
          Replaces the entry for a key only if currently mapped to some value.
 boolean replace(java.lang.Object key, java.lang.Object oldVal, java.lang.Object newVal)
          Replaces the entry for a key only if currently mapped to a given value.
 int size()
           
 
Methods inherited from class edu.emory.mathcs.backport.java.util.AbstractMap
keySet
 
Methods inherited from class java.util.AbstractMap
clone, equals, hashCode, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode, keySet, values
 

Constructor Detail

AsyncWeakValueHashMap

public AsyncWeakValueHashMap(int initialCapacity,
                             float loadFactor)
Creates new AsyncWeakValueHashMap with specified initial capacity and load factor.

See Also:
java.util.HashMap(int,float)

AsyncWeakValueHashMap

public AsyncWeakValueHashMap(int initialCapacity)
Creates new AsyncWeakValueHashMap with specified initial capacity and a default load factor.

See Also:
java.util.HashMap(int)

AsyncWeakValueHashMap

public AsyncWeakValueHashMap()
Creates new AsyncWeakValueHashMap with a default initial capacity and a default load factor.

See Also:
java.util.HashMap(int)

AsyncWeakValueHashMap

public AsyncWeakValueHashMap(java.util.Map t)
Creates new AsyncWeakValueHashMap with specified initial capacity and a default load factor, and copies to it all the mappings from the specified map.

See Also:
java.util.HashMap(int)
Method Detail

size

public int size()
Specified by:
size in interface java.util.Map

clear

public void clear()
Specified by:
clear in interface java.util.Map

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map

putAll

public void putAll(java.util.Map t)
Specified by:
putAll in interface java.util.Map

entrySet

public java.util.Set entrySet()
Specified by:
entrySet in interface java.util.Map

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map

remove

public java.lang.Object remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map

remove

public boolean remove(java.lang.Object key,
                      java.lang.Object value)
Description copied from interface: ConcurrentMap
Removes the entry for a key only if currently mapped to a given value. This is equivalent to
   if (map.containsKey(key) && map.get(key).equals(value)) {
       map.remove(key);
       return true;
   } else return false;
except that the action is performed atomically.

Specified by:
remove in interface ConcurrentMap
Parameters:
key - key with which the specified value is associated
value - value expected to be associated with the specified key
Returns:
true if the value was removed

replace

public boolean replace(java.lang.Object key,
                       java.lang.Object oldVal,
                       java.lang.Object newVal)
Description copied from interface: ConcurrentMap
Replaces the entry for a key only if currently mapped to a given value. This is equivalent to
   if (map.containsKey(key) && map.get(key).equals(oldValue)) {
       map.put(key, newValue);
       return true;
   } else return false;
except that the action is performed atomically.

Specified by:
replace in interface ConcurrentMap
Parameters:
key - key with which the specified value is associated
oldVal - value expected to be associated with the specified key
newVal - value to be associated with the specified key
Returns:
true if the value was replaced

replace

public java.lang.Object replace(java.lang.Object key,
                                java.lang.Object newVal)
Description copied from interface: ConcurrentMap
Replaces the entry for a key only if currently mapped to some value. This is equivalent to
   if (map.containsKey(key)) {
       return map.put(key, value);
   } else return null;
except that the action is performed atomically.

Specified by:
replace in interface ConcurrentMap
Parameters:
key - key with which the specified value is associated
newVal - value to be associated with the specified key
Returns:
the previous value associated with the specified key, or null if there was no mapping for the key. (A null return can also indicate that the map previously associated null with the key, if the implementation supports null values.)

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Specified by:
put in interface java.util.Map

putIfAbsent

public java.lang.Object putIfAbsent(java.lang.Object key,
                                    java.lang.Object value)
Description copied from interface: ConcurrentMap
If the specified key is not already associated with a value, associate it with the given value. This is equivalent to
   if (!map.containsKey(key))
       return map.put(key, value);
   else
       return map.get(key);
except that the action is performed atomically.

Specified by:
putIfAbsent in interface ConcurrentMap
Parameters:
key - key with which the specified value is to be associated
value - value to be associated with the specified key
Returns:
the previous value associated with the specified key, or null if there was no mapping for the key. (A null return can also indicate that the map previously associated null with the key, if the implementation supports null values.)