java.util

Class IdentityHashMap<K,V>

Implemented Interfaces:
Cloneable, Map<K,V>, Serializable

public class IdentityHashMap<K,V>
extends AbstractMap<K,V>
implements Map<K,V>, Serializable, Cloneable

This class implements the Map interface with a hash table, using reference-equality in place of object-equality when comparing keys (and values). In other words, in an IdentityHashMap, two keys k1 and k2 are considered equal if and only if (k1==k2). (In normal Map implementations (like HashMap) two keys k1 and k2 are considered equal if and only if (k1==null ? k2==null : k1.equals(k2)).)

This class is not a general-purpose Map implementation! While this class implements the Map interface, it intentionally violates Map's general contract, which mandates the use of the equals method when comparing objects. This class is designed for use only in the rare cases wherein reference-equality semantics are required.

A typical use of this class is topology-preserving object graph transformations, such as serialization or deep-copying. To perform such a transformation, a program must maintain a "node table" that keeps track of all the object references that have already been processed. The node table must not equate distinct objects even if they happen to be equal. Another typical use of this class is to maintain proxy objects. For example, a debugging facility might wish to maintain a proxy object for each object in the program being debugged.

This class provides all of the optional map operations, and permits null values and the null key. This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.

This class provides constant-time performance for the basic operations (get and put), assuming the system identity hash function (System.identityHashCode(Object)) disperses elements properly among the buckets.

This class has one tuning parameter (which affects performance but not semantics): expected maximum size. This parameter is the maximum number of key-value mappings that the map is expected to hold. Internally, this parameter is used to determine the number of buckets initially comprising the hash table. The precise relationship between the expected maximum size and the number of buckets is unspecified.

If the size of the map (the number of key-value mappings) sufficiently exceeds the expected maximum size, the number of buckets is increased Increasing the number of buckets ("rehashing") may be fairly expensive, so it pays to create identity hash maps with a sufficiently large expected maximum size. On the other hand, iteration over collection views requires time proportional to the number of buckets in the hash table, so it pays not to set the expected maximum size too high if you are especially concerned with iteration performance or memory usage.

Note that this implementation is not synchronized. If multiple threads access this map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more mappings; merely changing the value associated with a key that an instance already contains is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the map. If no such object exists, the map should be "wrapped" using the Collections.synchronizedMap method. This is best done at creation time, to prevent accidental unsynchronized access to the map:

     Map m = Collections.synchronizedMap(new HashMap(...));
 

The iterators returned by all of this class's "collection view methods" are fail-fast: if the map is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.

Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification. Fail-fast iterators throw ConcurrentModificationException on a best-effort basis. Therefore, it would be wrong to write a program that depended on this exception for its correctness: fail-fast iterators should be used only to detect bugs.

Implementation note: This is a simple linear-probe hash table, as described for example in texts by Sedgewick and Knuth. The array alternates holding keys and values. (This has better locality for large tables than does using separate arrays.) For many JRE implementations and operation mixes, this class will yield better performance than HashMap (which uses chaining rather than linear-probing).

This class is a member of the ../../../guide/collections/index.html"> Java Collections Framework.

Since:
1.4
See Also:
System.identityHashCode(Object), Object.hashCode(), Collection, Map, HashMap, TreeMap, Serialized Form

Constructor Summary

IdentityHashMap()
Constructs a new, empty identity hash map with a default expected maximum size (21).
IdentityHashMap(extends K, V> m)
Constructs a new identity hash map containing the keys-value mappings in the specified map.
IdentityHashMap(int expectedMaxSize)
Constructs a new, empty map with the specified expected maximum size.

Method Summary

void
clear()
Removes all mappings from this map.
Object
clone()
Returns a shallow copy of this identity hash map: the keys and values themselves are not cloned.
boolean
containsKey(Object key)
Tests whether the specified object reference is a key in this identity hash map.
boolean
containsValue(Object value)
Tests whether the specified object reference is a value in this identity hash map.
Set>
entrySet()
Returns a set view of the mappings contained in this map.
boolean
equals(Object o)
Compares the specified object with this map for equality.
V
get(Object key)
Returns the value to which the specified key is mapped in this identity hash map, or null if the map contains no mapping for this key.
int
hashCode()
Returns the hash code value for this map.
boolean
isEmpty()
Returns true if this identity hash map contains no key-value mappings.
Set
keySet()
Returns an identity-based set view of the keys contained in this map.
V
put(K key, V value)
Associates the specified value with the specified key in this identity hash map.
void
putAll(extends K, V> t)
Copies all of the mappings from the specified map to this map These mappings will replace any mappings that this map had for any of the keys currently in the specified map.
V
remove(Object key)
Removes the mapping for this key from this map if present.
int
size()
Returns the number of key-value mappings in this identity hash map.
Collection
values()
Returns a collection view of the values contained in this map.

Methods inherited from class java.util.AbstractMap<K,V>

clear, clone, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, toString, values

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

IdentityHashMap

public IdentityHashMap()
Constructs a new, empty identity hash map with a default expected maximum size (21).
Usages and Demos :

View More Examples of IdentityHashMap()
   1: public class MemorySizes {
   2:   private final Map primitiveSizes = new IdentityHashMap() {
   3:     {
   4:       put(boolean.class, new Integer(1));
   5:       put(byte.class, new Integer(1));

View Full Code Here
   1: public class MemorySizes {
   2:   private final Map primitiveSizes = new IdentityHashMap() {
   3:     {
   4:       put(boolean.class, new Integer(1));
   5:       put(byte.class, new Integer(1));

View Full Code Here
   1: {
   2:     private final Map delegate = new IdentityHashMap();
   3: 
   4:     public IdentityHashSet()
   5:     {

View Full Code Here
   1:     
   2:     protected Map target2model = new IdentityHashMap(); 
   3:     
   4:     public IObject map(ModelBased source){
   5:         

View Full Code Here
   1:     private ClassLoader classLoader;
   2:     private Map assignments = new IdentityHashMap();
   3:     private Map registrations = new HashMap();
   4:     private long nextId = 3;

View Full Code Here

IdentityHashMap

public IdentityHashMap(extends K,
                       V> m)
Constructs a new identity hash map containing the keys-value mappings in the specified map.
Parameters:
m - the map whose mappings are to be placed into this map.
Throws:
NullPointerException - if the specified map is null.

IdentityHashMap

public IdentityHashMap(int expectedMaxSize)
Constructs a new, empty map with the specified expected maximum size. Putting more than the expected number of key-value mappings into the map may cause the internal data structure to grow, which may be somewhat time-consuming.
Parameters:
expectedMaxSize - the expected maximum size of the map.
Throws:
IllegalArgumentException - if expectedMaxSize is negative
Usages and Demos :

View More Examples of IdentityHashMap(int expectedMaxSize)
   1:   public IdentityHashSet(int initialCapacity) {
   2:     map = new IdentityHashMap(initialCapacity);
   3:   }
   4:   public IdentityHashSet(Collection c) {
   5:     this(Math.max((int) (c.size()*1.1) + 1, 16));

View Full Code Here
   1:         this.resource = resource;
   2:         this.associatedHandles = new IdentityHashMap(10);
   3:         this.poolMgr = Switch.getSwitch().getPoolManager();
   4:     }

View Full Code Here
   1:     public IdentityHashSet(Collection c) {
   2:         map = new IdentityHashMap(Math.max((c.size()*4)/3, 16));
   3:         addAll(c);
   4:         ...
   5:     public IdentityHashSet(int expectedMaxSize) {
   6:         map = new IdentityHashMap(expectedMaxSize);
   7:     }
   8:         ...
   9: 
  10:         map = new IdentityHashMap((size*4)/3);

View Full Code Here
   1:     
   2:     private Map nodeMap = new IdentityHashMap(113);
   3:     
   4:     
   5:     public ConversionContext() {

View Full Code Here
   1:         private static Map createIdentityHashMap(int initialCapacity) {
   2:             return new IdentityHashMap(initialCapacity);
   3:         }
   4:     }

View Full Code Here

Method Details

clear

public void clear()
Removes all mappings from this map.
Specified by:
clear in interface Map<K,V>
Overrides:
clear in interface AbstractMap<K,V>
Usages and Demos :

View More Examples of clear()
   1: import java.util.AbstractSet;
   2: import java.util.IdentityHashMap;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6:     private transient IdentityHashMap map;
   7: 
   8:         ...
   9:     public IdentityHashSet() {
  10:         map = new IdentityHashMap();
  11:     }
  12:         ...
  13:     public void clear() {
  14:         map.clear();

View Full Code Here
   1: import java.util.HashSet;
   2: import java.util.IdentityHashMap;
   3: import java.util.Iterator;
   4:         ...
   5:         }
   6:         holder.stores.clear();
   7:         holder.currentThread = null;
   8:         ...
   9:     final static class PoolableHolder implements HttpSessionBindingListener{
  10:         private final IdentityHashMap map = new IdentityHashMap();
  11:         
  12:         ...
  13:             }
  14:             map.clear();

View Full Code Here
   1: import java.io.OutputStream;
   2: import java.util.IdentityHashMap;
   3: 
   4:         ...
   5:   protected OutputStream os;
   6:   private IdentityHashMap _refs;
   7:   private int _version = 1;
   8:         ...
   9:     if (_refs == null)
  10:       _refs = new IdentityHashMap();
  11: 
  12:         ...
  13:     if (_refs != null)
  14:       _refs.clear();

View Full Code Here
   1: import java.util.HashMap;
   2: import java.util.IdentityHashMap;
   3: import java.util.Iterator;
   4:         ...
   5:   private int fTotalTokenCharsWritten;
   6:   private IdentityHashMap fAlreadyEncodedObjects = new IdentityHashMap();
   7:   private ArrayList fAlreadyDecodedObjects = new ArrayList();
   8:         ...
   9:   public void prepareToRead(String encodedTokens) {
  10:     fAlreadyEncodedObjects.clear();
  11:         ...
  12:     fAlreadyDecodedObjects.clear();

View Full Code Here
   1: import java.util.HashMap;
   2: import java.util.IdentityHashMap;
   3: import java.util.List;
   4:         ...
   5: 
   6:   IdentityHashMap objects = new IdentityHashMap();
   7:   
   8:         ...
   9:   {
  10:     objects.clear();

View Full Code Here

clone

public Object clone()
Returns a shallow copy of this identity hash map: the keys and values themselves are not cloned.
Overrides:
clone in interface AbstractMap<K,V>
Returns:
a shallow copy of this map.
Usages and Demos :

View More Examples of clone()
   1: import java.util.AbstractSet;
   2: import java.util.IdentityHashMap;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6:     private transient IdentityHashMap map;
   7: 
   8:         ...
   9:     public IdentityHashSet() {
  10:         map = new IdentityHashMap();
  11:     }
  12:         ...
  13:         try { 
  14:             IdentityHashSet newSet = (IdentityHashSet)super.clone();

View Full Code Here

containsKey

public boolean containsKey(Object key)
Tests whether the specified object reference is a key in this identity hash map.
Specified by:
containsKey in interface Map<K,V>
Overrides:
containsKey in interface AbstractMap<K,V>
Parameters:
key - possible key.
Returns:
true if the specified object reference is a key in this map.
Usages and Demos :

View More Examples of containsKey(Object key)
   1: import java.util.AbstractSet;
   2: import java.util.IdentityHashMap;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6:     private transient IdentityHashMap map;
   7: 
   8:         ...
   9:     public IdentityHashSet() {
  10:         map = new IdentityHashMap();
  11:     }
  12:         ...
  13:     public boolean contains(Object o) {
  14:         return map.containsKey(o);

View Full Code Here
   1: 
   2: import java.util.IdentityHashMap;
   3: import java.util.List;
   4:         ...
   5: 
   6:     private final IdentityHashMap interceptors = new IdentityHashMap();
   7: 
   8:         ...
   9:     public boolean isProxy(Object proxy) {
  10:         return interceptors.containsKey(proxy);
  11:     }

View Full Code Here

containsValue

public boolean containsValue(Object value)
Tests whether the specified object reference is a value in this identity hash map.
Specified by:
containsValue in interface Map<K,V>
Overrides:
containsValue in interface AbstractMap<K,V>
Parameters:
value - value whose presence in this map is to be tested.
Returns:
true if this map maps one or more keys to the specified object reference.

entrySet

public Set> entrySet()
Returns a set view of the mappings contained in this map. Each element in the returned set is a reference-equality-based Map.Entry. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear methods. It does not support the add or addAll methods.

Like the backing map, the Map.Entry objects in the set returned by this method define key and value equality as reference-equality rather than object-equality. This affects the behavior of the equals and hashCode methods of these Map.Entry objects. A reference-equality based Map.Entry e is equal to an object o if and only if o is a Map.Entry and e.getKey()==o.getKey() && e.getValue()==o.getValue(). To accommodate these equals semantics, the hashCode method returns System.identityHashCode(e.getKey()) ^ System.identityHashCode(e.getValue()).

Owing to the reference-equality-based semantics of the Map.Entry instances in the set returned by this method, it is possible that the symmetry and transitivity requirements of the Object.equals(Object) contract may be violated if any of the entries in the set is compared to a normal map entry, or if the set returned by this method is compared to a set of normal map entries (such as would be returned by a call to this method on a normal map). However, the Object.equals contract is guaranteed to hold among identity-based map entries, and among sets of such entries.

Overrides:
entrySet in interface AbstractMap<K,V>
Returns:
a set view of the identity-mappings contained in this map.

equals

public boolean equals(Object o)
Compares the specified object with this map for equality. Returns true if the given object is also a map and the two maps represent identical object-reference mappings. More formally, this map is equal to another map m if and only if map this.entrySet().equals(m.entrySet()).

Owing to the reference-equality-based semantics of this map it is possible that the symmetry and transitivity requirements of the Object.equals contract may be violated if this map is compared to a normal map. However, the Object.equals contract is guaranteed to hold among IdentityHashMap instances.

Specified by:
equals in interface Map<K,V>
Overrides:
equals in interface AbstractMap<K,V>
Parameters:
o - object to be compared for equality with this map.
Returns:
true if the specified object is equal to this map.

get

public V get(Object key)
Returns the value to which the specified key is mapped in this identity hash map, or null if the map contains no mapping for this key. A return value of null does not necessarily indicate that the map contains no mapping for the key; it is also possible that the map explicitly maps the key to null. The containsKey method may be used to distinguish these two cases.
Specified by:
get in interface Map<K,V>
Overrides:
get in interface AbstractMap<K,V>
Parameters:
key - the key whose associated value is to be returned.
Returns:
the value to which this map maps the specified key, or null if the map contains no mapping for this key.
See Also:
put(Object, Object)
Usages and Demos :

View More Examples of get(Object key)
   1: import java.util.TreeMap;
   2: import java.util.IdentityHashMap;
   3: import java.util.SortedMap;
   4:         ...
   5:       {
   6:     return (MethodRef) map.get(addr);
   7:       }
   8:         ...
   9:   private static native MethodRef getCompiledMethodRef(RawData addr);
  10:   private static IdentityHashMap map = new IdentityHashMap();

View Full Code Here
   1: import java.util.HashMap;
   2: import java.util.IdentityHashMap;
   3: import java.util.Map;
   4:         ...
   5: 
   6:     private static java.util.IdentityHashMap    PRIMITIVE_WRAPPER_CLASSES = new IdentityHashMap();
   7:     private java.util.IdentityHashMap           seenGetMethods = new java.util.IdentityHashMap();
   8:         ...
   9:     {
  10:         return (Class)PRIMITIVE_WRAPPER_CLASSES.get(primitiveClass);
  11:     }
  12:         ...
  13:         {
  14:             ClassPool               pool = (ClassPool)pools.get(context.getClassResolver());

View Full Code Here
   1: 
   2: import java.util.IdentityHashMap;
   3: import java.util.List;
   4:         ...
   5: 
   6:     private final IdentityHashMap interceptors = new IdentityHashMap();
   7: 
   8:         ...
   9:     public synchronized ObjectName getProxyTarget(Object proxy) {
  10:         MethodInterceptor methodInterceptor = (MethodInterceptor) interceptors.get(proxy);
  11:         if (methodInterceptor == null) {

View Full Code Here
   1: import java.util.Enumeration;
   2: import java.util.IdentityHashMap;
   3: import java.util.ListIterator;
   4:         ...
   5:         Hashtable oldListIndexValue = new Hashtable();
   6:         IdentityHashMap oldListValueIndex = new IdentityHashMap();
   7:         IdentityHashMap objectsToAdd = new IdentityHashMap();
   8:         ...
   9:                     if (oldListValueIndex.containsKey(currentObject)) {
  10:                         int oldIndex = ((Integer) oldListValueIndex.get(currentObject)).intValue();
  11:                         oldListValueIndex.remove(currentObject);
  12:         ...
  13:                                     if (newListValueIndex.containsKey(oldObject)) {
  14:                                         if ((((Integer) newListValueIndex.get(oldObject)).intValue() - index) > 1) {

View Full Code Here
   1:     
   2:     public void addAdditionChange(IdentityHashMap objectChanges, UnitOfWorkChangeSet changeSet, AbstractSession session) {
   3:         Iterator enumtr = objectChanges.keySet().iterator();
   4:         ...
   5:             getOrderedAddObjects().add(change);
   6:             getOrderedAddObjectIndices().put(change, (Integer) objectChangesIndices.get(object));
   7:         }
   8:         ...
   9:             Integer index = (Integer) e.nextElement();
  10:             Object object = objectChanges.get(index);
  11:             ObjectChangeSet change = session.getDescriptor(object.getClass()).getObjectBuilder().createObjectChangeSet(object, changeSet, session);
  12:         ...
  13: 
  14:     public void addRemoveChange(IdentityHashMap objectChanges, UnitOfWorkChangeSet changeSet, AbstractSession session) {

View Full Code Here

hashCode

public int hashCode()
Returns the hash code value for this map. The hash code of a map is defined to be the sum of the hashcode of each entry in the map's entrySet view. This ensures that t1.equals(t2) implies that t1.hashCode()==t2.hashCode() for any two IdentityHashMap instances t1 and t2, as required by the general contract of Object.hashCode().

Owing to the reference-equality-based semantics of the Map.Entry instances in the set returned by this map's entrySet method, it is possible that the contractual requirement of Object.hashCode mentioned in the previous paragraph will be violated if one of the two objects being compared is an IdentityHashMap instance and the other is a normal map.

Specified by:
hashCode in interface Map<K,V>
Overrides:
hashCode in interface AbstractMap<K,V>
Returns:
the hash code value for this map.

isEmpty

public boolean isEmpty()
Returns true if this identity hash map contains no key-value mappings.
Specified by:
isEmpty in interface Map<K,V>
Overrides:
isEmpty in interface AbstractMap<K,V>
Returns:
true if this identity hash map contains no key-value mappings.
Usages and Demos :

View More Examples of isEmpty()
   1: import java.util.AbstractSet;
   2: import java.util.IdentityHashMap;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6:     private transient IdentityHashMap map;
   7: 
   8:         ...
   9:     public IdentityHashSet() {
  10:         map = new IdentityHashMap();
  11:     }
  12:         ...
  13:     public boolean isEmpty() {
  14:         return map.isEmpty();

View Full Code Here

keySet

public Set keySet()
Returns an identity-based set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll retainAll, and clear methods. It does not support the add or addAll methods.

While the object returned by this method implements the Set interface, it does not obey Set's general contract. Like its backing map, the set returned by this method defines element equality as reference-equality rather than object-equality. This affects the behavior of its contains, remove, containsAll, equals, and hashCode methods.

The equals method of the returned set returns true only if the specified object is a set containing exactly the same object references as the returned set. The symmetry and transitivity requirements of the Object.equals contract may be violated if the set returned by this method is compared to a normal set. However, the Object.equals contract is guaranteed to hold among sets returned by this method.

The hashCode method of the returned set returns the sum of the identity hashcodes of the elements in the set, rather than the sum of their hashcodes. This is mandated by the change in the semantics of the equals method, in order to enforce the general contract of the Object.hashCode method among sets returned by this method.

Specified by:
keySet in interface Map<K,V>
Overrides:
keySet in interface AbstractMap<K,V>
Returns:
an identity-based set view of the keys contained in this map.
Usages and Demos :

View More Examples of keySet()
   1: import java.util.AbstractSet;
   2: import java.util.IdentityHashMap;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6:     private transient IdentityHashMap map;
   7: 
   8:         ...
   9:     public IdentityHashSet() {
  10:         map = new IdentityHashMap();
  11:     }
  12:         ...
  13:     public Iterator iterator() {
  14:         return map.keySet().iterator();

View Full Code Here
   1: import java.util.HashSet;
   2: import java.util.IdentityHashMap;
   3: import java.util.Iterator;
   4:         ...
   5:     final static class PoolableHolder implements HttpSessionBindingListener{
   6:         private final IdentityHashMap map = new IdentityHashMap();
   7:         
   8:         ...
   9:         private void returnToPool(){
  10:             Iterator it = map.keySet().iterator();
  11:             while (it.hasNext())

View Full Code Here
   1:     
   2:     public void addAdditionChange(IdentityHashMap objectChanges, UnitOfWorkChangeSet changeSet, AbstractSession session) {
   3:         ...
   4:         Iterator enumtr = objectChanges.keySet().iterator();
   5:         while (enumtr.hasNext()) {
   6:         ...
   7: 
   8:     public void addRemoveChange(IdentityHashMap objectChanges, UnitOfWorkChangeSet changeSet, AbstractSession session) {
   9:         ...
  10:         Iterator enumtr = objectChanges.keySet().iterator();

View Full Code Here

put

public V put(K key,
             V value)
Associates the specified value with the specified key in this identity hash map. If the map previously contained a mapping for this key, the old value is replaced.
Specified by:
put in interface Map<K,V>
Overrides:
put in interface AbstractMap<K,V>
Parameters:
key - the key with which the specified value is to be associated.
value - the value to be associated with the specified key.
Returns:
the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with the specified key.)
Usages and Demos :

View More Examples of put(K key,V value)
   1: 
   2:     private IdentityHashMap associatedHandles;
   3: 
   4:         ...
   5:         this.resource = resource;
   6:         this.associatedHandles = new IdentityHashMap(10);
   7:         this.poolMgr = Switch.getSwitch().getPoolManager();
   8:         ...
   9:     public void associateHandle(Object c, ResourceHandle h) {
  10:         associatedHandles.put(c, h);
  11:     }

View Full Code Here
   1: import java.util.AbstractSet;
   2: import java.util.IdentityHashMap;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6:     private transient IdentityHashMap map;
   7: 
   8:         ...
   9:     public IdentityHashSet() {
  10:         map = new IdentityHashMap();
  11:     }
  12:         ...
  13:     public boolean add(Object o) {
  14:         return map.put(o, Objects.UNKNOWN)==null;

View Full Code Here
   1: 
   2:   private final java.util.IdentityHashMap h = 
   3:         ...
   4:   new java.util.IdentityHashMap();
   5: 
   6:         ...
   7:     int savedDepth = depth;
   8:     h.put(O, O);
   9:     try

View Full Code Here
   1: import java.util.HashMap;
   2: import java.util.IdentityHashMap;
   3: import java.util.Map;
   4:         ...
   5:     
   6:     private final IdentityHashMap referenceableToID;
   7:     
   8:         ...
   9:         idToReferenceable = new HashMap();
  10:         referenceableToID = new IdentityHashMap();
  11:         
  12:         ...
  13:                     aReference.getClass().getInterfaces(), refID.intValue());
  14:                 idToReferenceable.put(refID, aReference);

View Full Code Here
   1: import java.util.HashMap;
   2: import java.util.IdentityHashMap;
   3: import java.util.Map;
   4:         ...
   5: 
   6:     private static java.util.IdentityHashMap    PRIMITIVE_WRAPPER_CLASSES = new IdentityHashMap();
   7:     private java.util.IdentityHashMap           seenGetMethods = new java.util.IdentityHashMap();
   8:         ...
   9:     {
  10:         PRIMITIVE_WRAPPER_CLASSES.put(Boolean.TYPE, Boolean.class);
  11:         ...
  12:         PRIMITIVE_WRAPPER_CLASSES.put(Boolean.class, Boolean.TYPE);

View Full Code Here

putAll

public void putAll(extends K,
                   V> t)
Copies all of the mappings from the specified map to this map These mappings will replace any mappings that this map had for any of the keys currently in the specified map.

Specified by:
putAll in interface Map<K,V>
Overrides:
putAll in interface AbstractMap<K,V>
Parameters:
t - mappings to be stored in this map.
Throws:
NullPointerException - if the specified map is null.

remove

public V remove(Object key)
Removes the mapping for this key from this map if present.
Specified by:
remove in interface Map<K,V>
Overrides:
remove in interface AbstractMap<K,V>
Parameters:
key - key whose mapping is to be removed from the map.
Returns:
previous value associated with specified key, or null if there was no entry for key. (A null return can also indicate that the map previously associated null with the specified key.)
Usages and Demos :

View More Examples of remove(Object key)
   1: 
   2:     private IdentityHashMap associatedHandles;
   3: 
   4:         ...
   5:         this.resource = resource;
   6:         this.associatedHandles = new IdentityHashMap(10);
   7:         this.poolMgr = Switch.getSwitch().getPoolManager();
   8:         ...
   9:     public void removeAssociation(Object c) {
  10:         associatedHandles.remove(c);
  11:     }

View Full Code Here
   1: import java.util.AbstractSet;
   2: import java.util.IdentityHashMap;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6:     private transient IdentityHashMap map;
   7: 
   8:         ...
   9:     public IdentityHashSet() {
  10:         map = new IdentityHashMap();
  11:     }
  12:         ...
  13:     public boolean remove(Object o) {
  14:         return map.remove(o)==Objects.UNKNOWN;

View Full Code Here
   1: import java.util.HashMap;
   2: import java.util.IdentityHashMap;
   3: import java.util.Map;
   4:         ...
   5:     
   6:     private final IdentityHashMap referenceableToID;
   7:     
   8:         ...
   9:         idToReferenceable = new HashMap();
  10:         referenceableToID = new IdentityHashMap();
  11:         
  12:         ...
  13:             idToReferenceable.remove(new Integer(aReferenceInfo.getRefID()));
  14:             referenceableToID.remove(aReferenceInfo);

View Full Code Here
   1: import java.util.HashSet;
   2: import java.util.IdentityHashMap;
   3: import java.util.Iterator;
   4:         ...
   5:     final static class PoolableHolder implements HttpSessionBindingListener{
   6:         private final IdentityHashMap map = new IdentityHashMap();
   7:         
   8:         ...
   9:         public void removeObject(IPoolable pA){
  10:             map.remove(pA);
  11:         }

View Full Code Here
   1: 
   2: import java.util.IdentityHashMap;
   3: import java.util.List;
   4:         ...
   5: 
   6:     private final IdentityHashMap interceptors = new IdentityHashMap();
   7: 
   8:         ...
   9: 
  10:         MethodInterceptor methodInterceptor = (MethodInterceptor) interceptors.remove(proxy);
  11:         if (methodInterceptor != null) {

View Full Code Here

size

public int size()
Returns the number of key-value mappings in this identity hash map.
Specified by:
size in interface Map<K,V>
Overrides:
size in interface AbstractMap<K,V>
Returns:
the number of key-value mappings in this map.
Usages and Demos :

View More Examples of size()
   1: import java.util.AbstractSet;
   2: import java.util.IdentityHashMap;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6:     private transient IdentityHashMap map;
   7: 
   8:         ...
   9:     public IdentityHashSet() {
  10:         map = new IdentityHashMap();
  11:     }
  12:         ...
  13:     public IdentityHashSet(Collection c) {
  14:         map = new IdentityHashMap(Math.max((c.size()*4)/3, 16));

View Full Code Here
   1:         int iters = 20;
   2:         timer.start("ContainsValue (/n)     ", iters * s.size());
   3:         int step = absentSize / iters;
   4:         ...
   5:     static void ittest4(Map s, int size, int pos) {
   6:         IdentityHashMap seen = new IdentityHashMap(size);
   7:         ...
   8:         reallyAssert (s.size() == size);
   9:         int sum = 0;
  10:         ...
  11: 
  12:         reallyAssert (s.size() == size-1);

View Full Code Here
   1: import java.util.Random;
   2: import java.util.IdentityHashMap;
   3: import java.util.Enumeration;
   4:         ...
   5:         int iters = 20;
   6:         timer.start("ContainsValue (/n)     ", iters * s.size());
   7:         int step = absentSize / iters;
   8:         ...
   9:     static void ittest4(Map s, int size, int pos) {
  10:         IdentityHashMap seen = new IdentityHashMap(size);
  11:         ...
  12:         reallyAssert (s.size() == size);

View Full Code Here

values

public Collection values()
Returns a collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress, the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear methods. It does not support the add or addAll methods.

While the object returned by this method implements the Collection interface, it does not obey Collection's general contract. Like its backing map, the collection returned by this method defines element equality as reference-equality rather than object-equality. This affects the behavior of its contains, remove and containsAll methods.

Specified by:
values in interface Map<K,V>
Overrides:
values in interface AbstractMap<K,V>
Returns:
a collection view of the values contained in this map.