/** * Returns the entry associated with the specified key in the HashMap. Returns null if the * HashMap contains no mapping for this key. * * @param key * @return The Entry object for the given hash key */ Entry getEntry(int key) { int i = indexFor(key, table.length); Entry e = table[i]; while (e != null && !(key == e.key)) { e = e.next; } return e; }
/** * Returns the entry associated with the specified key in the HashMap. Returns null if the * HashMap contains no mapping for this key. * * @param key * @return The Entry object for the given hash key */ Entry<V> getEntry(final int key) { int i = indexFor(key, table.length); Entry<V> e = table[i]; while ((e != null) && !(key == e.key)) { e = e.next; } return e; }
/** * Returns the entry associated with the specified key in the HashMap. Returns null if the * HashMap contains no mapping for this key. * * @param key * @return The Entry object for the given hash key */ Entry<V> getEntry(int key) { int i = indexFor(key, table.length); Entry<V> e = table[i]; while (e != null && !(key == e.key)) { e = e.next; } return e; }
/** * Returns <tt>true</tt> if this map contains a mapping for the specified key. * * @param key * The key whose presence in this map is to be tested * @return <tt>true</tt> if this map contains a mapping for the specified key. */ public boolean containsKey(final int key) { int i = indexFor(key, table.length); Entry<V> e = table[i]; while (e != null) { if (key == e.key) { return true; } e = e.next; } return false; }
/** * Returns <tt>true</tt> if this map contains a mapping for the specified key. * * @param key * The key whose presence in this map is to be tested * @return <tt>true</tt> if this map contains a mapping for the specified key. */ public boolean containsKey(int key) { int i = indexFor(key, table.length); Entry<V> e = table[i]; while (e != null) { if (key == e.key) { return true; } e = e.next; } return false; }
/** * Returns <tt>true</tt> if this map contains a mapping for the specified key. * * @param key * The key whose presence in this map is to be tested * @return <tt>true</tt> if this map contains a mapping for the specified key. */ public boolean containsKey(int key) { int i = indexFor(key, table.length); Entry e = table[i]; while (e != null) { if (key == e.key) { return true; } e = e.next; } return false; }
/** * Transfer all entries from current table to newTable. * * @param newTable */ void transfer(final Entry<V>[] newTable) { Entry<V>[] src = table; int newCapacity = newTable.length; for (int j = 0; j < src.length; j++) { Entry<V> e = src[j]; if (e != null) { src[j] = null; do { Entry<V> next = e.next; int i = indexFor(e.key, newCapacity); e.next = newTable[i]; newTable[i] = e; e = next; } while (e != null); } } }
/** * Returns the value to which the specified key is mapped in this identity hash map, or * <tt>null</tt> if the map contains no mapping for this key. A return value of <tt>null</tt> * does not <i>necessarily</i> indicate that the map contains no mapping for the key; it is * also possible that the map explicitly maps the key to <tt>null</tt>. The * <tt>containsKey</tt> method may be used to distinguish these two cases. * * @param key * the key whose associated value is to be returned. * @return the value to which this map maps the specified key, or <tt>null</tt> if the map * contains no mapping for this key. * @see #put(int, Object) */ public Object get(int key) { int i = indexFor(key, table.length); Entry e = table[i]; while (true) { if (e == null) { return e; } if (key == e.key) { return e.value; } e = e.next; } }
/** * Returns the value to which the specified key is mapped in this identity hash map, or * <tt>null</tt> if the map contains no mapping for this key. A return value of <tt>null</tt> * does not <i>necessarily</i> indicate that the map contains no mapping for the key; it is also * possible that the map explicitly maps the key to <tt>null</tt>. The <tt>containsKey</tt> * method may be used to distinguish these two cases. * * @param key * the key whose associated value is to be returned. * @return the value to which this map maps the specified key, or <tt>null</tt> if the map * contains no mapping for this key. * @see #put(int, Object) */ public V get(int key) { int i = indexFor(key, table.length); Entry<V> e = table[i]; while (true) { if (e == null) { return null; } if (key == e.key) { return e.value; } e = e.next; } }
/** * Transfer all entries from current table to newTable. * * @param newTable */ void transfer(Entry<V>[] newTable) { Entry<V>[] src = table; int newCapacity = newTable.length; for (int j = 0; j < src.length; j++) { Entry<V> e = src[j]; if (e != null) { src[j] = null; do { Entry<V> next = e.next; int i = indexFor(e.key, newCapacity); e.next = newTable[i]; newTable[i] = e; e = next; } while (e != null); } } }
/** * Transfer all entries from current table to newTable. * * @param newTable */ void transfer(Entry[] newTable) { Entry[] src = table; int newCapacity = newTable.length; for (int j = 0; j < src.length; j++) { Entry e = src[j]; if (e != null) { src[j] = null; do { Entry next = e.next; int i = indexFor(e.key, newCapacity); e.next = newTable[i]; newTable[i] = e; e = next; } while (e != null); } } }
/** * Returns the value to which the specified key is mapped in this identity hash map, or * <tt>null</tt> if the map contains no mapping for this key. A return value of <tt>null</tt> * does not <i>necessarily</i> indicate that the map contains no mapping for the key; it is also * possible that the map explicitly maps the key to <tt>null</tt>. The <tt>containsKey</tt> * method may be used to distinguish these two cases. * * @param key * the key whose associated value is to be returned. * @return the value to which this map maps the specified key, or <tt>null</tt> if the map * contains no mapping for this key. * @see #put(int, Object) */ public V get(final int key) { int i = indexFor(key, table.length); Entry<V> e = table[i]; while (true) { if (e == null) { return null; } if (key == e.key) { return e.value; } e = e.next; } }
int i = indexFor(key, table.length); Entry<V> prev = table[i]; Entry<V> e = prev;
int i = indexFor(key, table.length); Entry<V> prev = table[i]; Entry<V> e = prev;
/** * Associates the specified value with the specified key in this map. If the map previously * contained a mapping for this key, the old value is replaced. * * @param key * key with which the specified value is to be associated. * @param value * value to be associated with the specified key. * @return previous value associated with specified key, or <tt>null</tt> if there was no * mapping for key. A <tt>null</tt> return can also indicate that the HashMap * previously associated <tt>null</tt> with the specified key. */ public Object put(int key, Object value) { int i = indexFor(key, table.length); for (Entry e = table[i]; e != null; e = e.next) { if (key == e.key) { Object oldValue = e.value; e.value = value; return oldValue; } } modCount++; addEntry(key, value, i); return null; }
/** * This method is used instead of put by constructors and pseudoconstructors (clone, * readObject). It does not resize the table, check for comodification, etc. It calls * createEntry rather than addEntry. * * @param key * @param value */ private void putForCreate(final int key, final V value) { int i = indexFor(key, table.length); /** * Look for preexisting entry for key. This will never happen for clone or deserialize. It * will only happen for construction if the input Map is a sorted map whose ordering is * inconsistent w/ equals. */ for (Entry<V> e = table[i]; e != null; e = e.next) { if (key == e.key) { e.value = value; return; } } createEntry(key, value, i); }
/** * Associates the specified value with the specified key in this map. If the map previously * contained a mapping for this key, the old value is replaced. * * @param key * key with which the specified value is to be associated. * @param value * value to be associated with the specified key. * @return previous value associated with specified key, or <tt>null</tt> if there was no * mapping for key. A <tt>null</tt> return can also indicate that the HashMap previously * associated <tt>null</tt> with the specified key. */ public V put(int key, V value) { int i = indexFor(key, table.length); for (Entry<V> e = table[i]; e != null; e = e.next) { if (key == e.key) { V oldValue = e.value; e.value = value; return oldValue; } } modCount++; addEntry(key, value, i); return null; }
/** * This method is used instead of put by constructors and pseudoconstructors (clone, * readObject). It does not resize the table, check for comodification, etc. It calls * createEntry rather than addEntry. * * @param key * @param value */ private void putForCreate(int key, V value) { int i = indexFor(key, table.length); /** * Look for preexisting entry for key. This will never happen for clone or deserialize. It * will only happen for construction if the input Map is a sorted map whose ordering is * inconsistent w/ equals. */ for (Entry<V> e = table[i]; e != null; e = e.next) { if (key == e.key) { e.value = value; return; } } createEntry(key, value, i); }
/** * This method is used instead of put by constructors and pseudoconstructors (clone, * readObject). It does not resize the table, check for comodification, etc. It calls * createEntry rather than addEntry. * * @param key * @param value */ private void putForCreate(int key, Object value) { int i = indexFor(key, table.length); /** * Look for preexisting entry for key. This will never happen for clone or deserialize. It * will only happen for construction if the input Map is a sorted map whose ordering is * inconsistent w/ equals. */ for (Entry e = table[i]; e != null; e = e.next) { if (key == e.key) { e.value = value; return; } } createEntry(key, value, i); }
/** * Associates the specified value with the specified key in this map. If the map previously * contained a mapping for this key, the old value is replaced. * * @param key * key with which the specified value is to be associated. * @param value * value to be associated with the specified key. * @return previous value associated with specified key, or <tt>null</tt> if there was no * mapping for key. A <tt>null</tt> return can also indicate that the HashMap previously * associated <tt>null</tt> with the specified key. */ public V put(final int key, final V value) { int i = indexFor(key, table.length); for (Entry<V> e = table[i]; e != null; e = e.next) { if (key == e.key) { V oldValue = e.value; e.value = value; return oldValue; } } modCount.incrementAndGet(); addEntry(key, value, i); return null; }