public class


extends Object
   ↳ com.pnfsoftware.jeb.util.collect.WeakIdentityHashMap<K, V>

Class Overview

A pseudo 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(). This map does not support null keys.

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.

Implementation note: The approach is to wrap each key in a WeakReference and use the wrapped value as a key in an ordinary HashMap. The WeakReference has to be a subclass IdentityWeakReference (IWR) where two IWRs are equal if they refer to the same object. This enables us to find the entry again.

Forked from


Public Constructors
WeakIdentityHashMap(int initialCapacity, float loadFactor)
WeakIdentityHashMap(int initialCapacity)
Public Methods
Set<Entry<K, V>> entrySet()
V get(K key)
boolean isEmpty()
Set<K> keySet()
V put(K key, V value)
V putUnsafe(K key, V value)
V remove(K key)
int size()
String toString()
Collection<V> values()
Inherited Methods
From class java.lang.Object

Public Constructors

public WeakIdentityHashMap (int initialCapacity, float loadFactor)

public WeakIdentityHashMap (int initialCapacity)

public WeakIdentityHashMap ()

Public Methods

public Set<Entry<K, V>> entrySet ()

public V get (K key)

public boolean isEmpty ()

public Set<K> keySet ()

public V put (K key, V value)

public V putUnsafe (K key, V value)

public V remove (K key)

public int size ()

public String toString ()

public Collection<V> values ()