A variant of java.util.HashMap that uses System#identityHashCode(Object) for hashing, and reference comparison instead of Object#equals(Object). Note that this applies only to keys, and not to values, i.e. #containsValue(Object) still uses {@link Object#equals(Object)
| 70 | * @author Attila Szegedi |
| 71 | */ |
| 72 | public class IdentityHashMap |
| 73 | extends AbstractMap |
| 74 | implements Map, Cloneable, java.io.Serializable |
| 75 | { |
| 76 | |
| 77 | public static final long serialVersionUID = 362498820763181265L; |
| 78 | /** |
| 79 | * The hash table data. |
| 80 | */ |
| 81 | private transient Entry table[]; |
| 82 | |
| 83 | /** |
| 84 | * The total number of mappings in the hash table. |
| 85 | */ |
| 86 | private transient int count; |
| 87 | |
| 88 | /** |
| 89 | * The table is rehashed when its size exceeds this threshold. (The |
| 90 | * value of this field is (int)(capacity * loadFactor).) |
| 91 | * |
| 92 | * @serial |
| 93 | */ |
| 94 | private int threshold; |
| 95 | |
| 96 | /** |
| 97 | * The load factor for the hashtable. |
| 98 | * |
| 99 | * @serial |
| 100 | */ |
| 101 | private float loadFactor; |
| 102 | |
| 103 | /** |
| 104 | * The number of times this IdentityHashMap has been structurally modified |
| 105 | * Structural modifications are those that change the number of mappings in |
| 106 | * the IdentityHashMap or otherwise modify its internal structure (e.g., |
| 107 | * rehash). This field is used to make iterators on Collection-views of |
| 108 | * the IdentityHashMap fail-fast. (See ConcurrentModificationException). |
| 109 | */ |
| 110 | private transient int modCount = 0; |
| 111 | |
| 112 | /** |
| 113 | * Constructs a new, empty map with the specified initial |
| 114 | * capacity and the specified load factor. |
| 115 | * |
| 116 | * @param initialCapacity the initial capacity of the IdentityHashMap. |
| 117 | * @param loadFactor the load factor of the IdentityHashMap |
| 118 | * @throws IllegalArgumentException if the initial capacity is less |
| 119 | * than zero, or if the load factor is nonpositive. |
| 120 | */ |
| 121 | public IdentityHashMap(int initialCapacity, float loadFactor) |
| 122 | { |
| 123 | if (initialCapacity < 0) |
| 124 | throw new IllegalArgumentException( |
| 125 | "Illegal Initial Capacity: " + initialCapacity); |
| 126 | if (loadFactor <= 0 || Float.isNaN(loadFactor)) |
| 127 | throw new IllegalArgumentException( |
| 128 | "Illegal Load factor: " + loadFactor); |
| 129 | if (initialCapacity == 0) |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…