/** Offloaded version of put for null keys */ private V putForNullKey(V value) { for (Entry<K, V> e = table[0]; e != null; e = e.next) { if (e.key == null) { V oldValue = e.value; e.value = value; e.recordAccess(this); return oldValue; } } modCount++; addEntry(0, null, value, 0); return null; }
public Object haeb(Key key, Object value) { int hash = hash(key.hashCode()); int i = indexFor(hash, table.length); for (Entry<Key, Object> e = table[i]; e != null; e = e.next) { Key k; if (e.hash == hash && ((k = e.key) == key || key.equalsIgnoreCase(k))) { Object oldValue = e.value; e.value = value; e.recordAccess(this); return oldValue; } } modCount++; addEntry(hash, key, value, i); return null; }
/** * Associates the specified value with the specified key in this map. If the map previously * contained a mapping for the 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 the previous value associated with <tt>key</tt>, or <tt>null</tt> if there was no * mapping for <tt>key</tt>. (A <tt>null</tt> return can also indicate that the map previously * associated <tt>null</tt> with <tt>key</tt>.) */ public V put(K key, V value) { if (key == null) return putForNullKey(value); int hash = hash(key); int i = indexFor(hash, table.length); for (Entry<K, V> e = table[i]; e != null; e = e.next) { Object k; if (e.hash == hash && ((k = e.key) == key || key.equals(k))) { V oldValue = e.value; e.value = value; e.recordAccess(this); return oldValue; } } modCount++; addEntry(hash, key, value, i); return null; }
/** * Returns the value to which the specified key is mapped, or {@code null} if this map contains no * mapping for the key. * * <p>More formally, if this map contains a mapping from a key {@code k} to a value {@code v} such * that {@code (key==null ? k==null : key.equals(k))}, then this method returns {@code v}; * otherwise it returns {@code null}. (There can be at most one such mapping.) * * <p>A return value of {@code null} does not <i>necessarily</i> indicate that the map contains no * mapping for the key; it's also possible that the map explicitly maps the key to {@code null}. * The {@link #containsKey containsKey} operation may be used to distinguish these two cases. */ public V get(Object key) { Entry<K, V> e = (Entry<K, V>) getEntry(key); if (e == null) return null; e.recordAccess(this); return e.value; }