org.cojen.util
Class WeakIdentityMap

java.lang.Object
  extended by java.util.AbstractMap
      extended by org.cojen.util.WeakIdentityMap
All Implemented Interfaces:
Cloneable, Map

public class WeakIdentityMap
extends AbstractMap
implements Map, Cloneable

WeakIdentityMap is like WeakHashMap, except it uses a key's identity hashcode and equals methods. WeakIdentityMap is not thread-safe and must be wrapped with Collections.synchronizedMap to be made thread-safe.

The documentation for WeakHashMap states that it is intended primarily for use with key objects whose equals methods test for object identity using the == operator. Because WeakIdentityMap strictly follows this behavior, it is better suited for this purpose.

Note: Weakly referenced entries may be automatically removed during either accessor or mutator operations, possibly causing a concurrent modification to be detected. Therefore, even if multiple threads are only accessing this map, be sure to synchronize this map first. Also, do not rely on the value returned by size() when using an iterator from this map. The iterators may return less entries than the amount reported by size().

Author:
Brian S O'Neill

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
WeakIdentityMap()
           
WeakIdentityMap(int initialCapacity)
           
WeakIdentityMap(int initialCapacity, float loadFactor)
           
WeakIdentityMap(Map t)
           
 
Method Summary
 void clear()
           
 Object clone()
           
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 Set entrySet()
           
 Object get(Object key)
           
 boolean isEmpty()
           
 Set keySet()
           
 Object put(Object key, Object value)
           
 void putAll(Map t)
           
 Object remove(Object key)
           
 int size()
           
 String toString()
          Gets the map as a String.
 Collection 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

WeakIdentityMap

public WeakIdentityMap(int initialCapacity,
                       float loadFactor)

WeakIdentityMap

public WeakIdentityMap(int initialCapacity)

WeakIdentityMap

public WeakIdentityMap()

WeakIdentityMap

public WeakIdentityMap(Map t)
Method Detail

size

public int size()
Specified by:
size in interface Map
Overrides:
size in class AbstractMap

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map
Overrides:
isEmpty in class AbstractMap

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map
Overrides:
containsValue in class AbstractMap

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map
Overrides:
containsKey in class AbstractMap

get

public Object get(Object key)
Specified by:
get in interface Map
Overrides:
get in class AbstractMap

put

public Object put(Object key,
                  Object value)
Specified by:
put in interface Map
Overrides:
put in class AbstractMap

remove

public Object remove(Object key)
Specified by:
remove in interface Map
Overrides:
remove in class AbstractMap

putAll

public void putAll(Map t)
Specified by:
putAll in interface Map
Overrides:
putAll in class AbstractMap

clear

public void clear()
Specified by:
clear in interface Map
Overrides:
clear in class AbstractMap

clone

public Object clone()
Overrides:
clone in class AbstractMap

keySet

public Set keySet()
Specified by:
keySet in interface Map
Overrides:
keySet in class AbstractMap

values

public Collection values()
Specified by:
values in interface Map
Overrides:
values in class AbstractMap

entrySet

public Set entrySet()
Specified by:
entrySet in interface Map
Specified by:
entrySet in class AbstractMap

toString

public String toString()
Gets the map as a String.

Overrides:
toString in class AbstractMap
Returns:
a string version of the map


Copyright © 2004-2011 Brian S O'Neill. All Rights Reserved.