FileDocCategorySizeDatePackage
WeakIdentityHashMap.javaAPI DocJava SE 6 API3511Tue Jun 10 00:22:04 BST 2008com.sun.jmx.mbeanserver

WeakIdentityHashMap

public class WeakIdentityHashMap extends Object

A map where keys are compared using identity comparison (like IdentityHashMap) but where the presence of an object as a key in the map does not prevent it being garbage collected (like WeakHashMap). This class does not implement the Map interface because it is difficult to ensure correct semantics for iterators over the entrySet().

Because we do not implement Map, we do not copy the questionable interface where you can call get(k) or remove(k) for any type of k, which of course can only have an effect if k is of type K.

This map does not support null keys.

Fields Summary
private Map
map
private ReferenceQueue
refQueue
Constructors Summary
private WeakIdentityHashMap()

Methods Summary
private voidexpunge()

	Reference<? extends K> ref;
	while ((ref = refQueue.poll()) != null)
	    map.remove(ref);
    
Vget(K key)

	expunge();
	WeakReference<K> keyref = makeReference(key);
	return map.get(keyref);
    
static com.sun.jmx.mbeanserver.WeakIdentityHashMapmake()

        return new WeakIdentityHashMap<K, V>();
    
private java.lang.ref.WeakReferencemakeReference(K referent)

	return new IdentityWeakReference<K>(referent);
    
private java.lang.ref.WeakReferencemakeReference(K referent, java.lang.ref.ReferenceQueue q)

	return new IdentityWeakReference<K>(referent, q);
    
public Vput(K key, V value)

	expunge();
	if (key == null)
	    throw new IllegalArgumentException("Null key");
	WeakReference<K> keyref = makeReference(key, refQueue);
	return map.put(keyref, value);
    
public Vremove(K key)

	expunge();
	WeakReference<K> keyref = makeReference(key);
	return map.remove(keyref);