@Test public void testPutGet2() { final Map<Integer, String> tested = new HashMap<>(); for (int i = 0; i < 1000; ++i) { tested.put(i - 500, Integer.toString(i)); } Assert.assertEquals(1000, tested.size()); for (int i = 0; i < 1000; ++i) { Assert.assertEquals(Integer.toString(i), tested.get(i - 500)); } for (int i = 0; i < 1000; ++i) { Assert.assertEquals(Integer.toString(i), tested.put(i - 500, Integer.toString(i + 1))); } Assert.assertEquals(1000, tested.size()); for (int i = 0; i < 1000; ++i) { Assert.assertEquals(Integer.toString(i + 1), tested.get(i - 500)); } }
@Override public V put(@Nullable final K key, final V value) { if (key == null) { if (nullEntry == null) { _size += 1; nullEntry = new Entry<>(null, value); return null; } return nullEntry.setValue(value); } final Entry<K, V>[] table = this.table; final int hash = key.hashCode(); final int index = HashUtil.indexFor(hash, table.length, mask); for (Entry<K, V> e = table[index]; e != null; e = e.hashNext) { final K entryKey; if ((entryKey = e.key) == key || entryKey.equals(key)) { return e.setValue(value); } } final Entry<K, V> e = new Entry<>(key, value); e.hashNext = table[index]; table[index] = e; _size += 1; if (_size > capacity) { rehash(HashUtil.nextCapacity(capacity)); } return null; }
HashMap extends AbstractHashMap<K, V> implements Serializable { @Override public V put(@Nullable final K key, final V value) { if (key == null) { if (nullEntry == null) { _size += 1; nullEntry = new Entry<>(null, value); return null; } return nullEntry.setValue(value); } final Entry<K, V>[] table = this.table; final int hash = key.hashCode(); final int index = HashUtil.indexFor(hash, table.length, mask); for (Entry<K, V> e = table[index]; e != null; e = e.hashNext) { final K entryKey; if ((entryKey = e.key) == key || entryKey.equals(key)) { return e.setValue(value); } } final Entry<K, V> e = new Entry<>(key, value); e.hashNext = table[index]; table[index] = e; _size += 1; if (_size > capacity) { rehash(HashUtil.nextCapacity(capacity)); } return null; } }
HashMap extends AbstractHashMap<K, V> implements Serializable { @Override public V put(@Nullable final K key, final V value) { if (key == null) { if (nullEntry == null) { _size += 1; nullEntry = new Entry<>(null, value); return null; } return nullEntry.setValue(value); } final Entry<K, V>[] table = this.table; final int hash = key.hashCode(); final int index = HashUtil.indexFor(hash, table.length, mask); for (Entry<K, V> e = table[index]; e != null; e = e.hashNext) { final K entryKey; if ((entryKey = e.key) == key || entryKey.equals(key)) { return e.setValue(value); } } final Entry<K, V> e = new Entry<>(key, value); e.hashNext = table[index]; table[index] = e; _size += 1; if (_size > capacity) { rehash(HashUtil.nextCapacity(capacity)); } return null; } HashMap();  HashMap(int capacity);  HashMap(int capacity, float loadFactor);  HashMap(HashMap<K, V> copy); protected  HashMap(int capacity, int size, float loadFactor, int tableSize, int mask); }
HashMap extends AbstractHashMap<K, V> implements Serializable { @Override public V put(@Nullable final K key, final V value) { if (key == null) { if (nullEntry == null) { _size += 1; nullEntry = new Entry<>(null, value); return null; } return nullEntry.setValue(value); } final Entry<K, V>[] table = this.table; final int hash = key.hashCode(); final int index = HashUtil.indexFor(hash, table.length, mask); for (Entry<K, V> e = table[index]; e != null; e = e.hashNext) { final K entryKey; if ((entryKey = e.key) == key || entryKey.equals(key)) { return e.setValue(value); } } final Entry<K, V> e = new Entry<>(key, value); e.hashNext = table[index]; table[index] = e; _size += 1; if (_size > capacity) { rehash(HashUtil.nextCapacity(capacity)); } return null; } HashMap();  HashMap(int capacity);  HashMap(int capacity, float loadFactor);  HashMap(HashMap<K, V> copy); protected  HashMap(int capacity, int size, float loadFactor, int tableSize, int mask); @Override V put(@Nullable final K key, final V value); @Override V remove(final Object key); }
HashMap extends AbstractHashMap<K, V> implements Serializable { @Override public V put(@Nullable final K key, final V value) { if (key == null) { if (nullEntry == null) { _size += 1; nullEntry = new Entry<>(null, value); return null; } return nullEntry.setValue(value); } final Entry<K, V>[] table = this.table; final int hash = key.hashCode(); final int index = HashUtil.indexFor(hash, table.length, mask); for (Entry<K, V> e = table[index]; e != null; e = e.hashNext) { final K entryKey; if ((entryKey = e.key) == key || entryKey.equals(key)) { return e.setValue(value); } } final Entry<K, V> e = new Entry<>(key, value); e.hashNext = table[index]; table[index] = e; _size += 1; if (_size > capacity) { rehash(HashUtil.nextCapacity(capacity)); } return null; } HashMap();  HashMap(int capacity);  HashMap(int capacity, float loadFactor);  HashMap(HashMap<K, V> copy); protected  HashMap(int capacity, int size, float loadFactor, int tableSize, int mask); @Override V put(@Nullable final K key, final V value); @Override V remove(final Object key);  }