Skip to content

Commit

Permalink
Remove private method
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Jul 14, 2024
1 parent 70daade commit f0e4253
Showing 1 changed file with 10 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -585,31 +585,7 @@ protected AbstractHashedMap(final int initialCapacity, final float loadFactor, f
*/
protected AbstractHashedMap(final Map<? extends K, ? extends V> map) {
this(Math.max(2 * map.size(), DEFAULT_CAPACITY), DEFAULT_LOAD_FACTOR);
_putAll(map);
}

/**
* Puts all the values from the specified map into this map.
* <p>
* This implementation iterates around the specified map and
* uses {@link #put(Object, Object)}.
* <p>
* It is private to allow the constructor to still call it
* even when putAll is overridden.
*
* @param map the map to add
* @throws NullPointerException if the map is null
*/
private void _putAll(final Map<? extends K, ? extends V> map) {
final int mapSize = map.size();
if (mapSize == 0) {
return;
}
final int newSize = (int) ((size + mapSize) / loadFactor + 1);
ensureCapacity(calculateNewCapacity(newSize));
for (final Map.Entry<? extends K, ? extends V> entry: map.entrySet()) {
put(entry.getKey(), entry.getValue());
}
putAll(map);
}

/**
Expand Down Expand Up @@ -1280,7 +1256,15 @@ public V put(final K key, final V value) {
*/
@Override
public void putAll(final Map<? extends K, ? extends V> map) {
_putAll(map);
final int mapSize = map.size();
if (mapSize == 0) {
return;
}
final int newSize = (int) ((size + mapSize) / loadFactor + 1);
ensureCapacity(calculateNewCapacity(newSize));
for (final Map.Entry<? extends K, ? extends V> entry: map.entrySet()) {
put(entry.getKey(), entry.getValue());
}
}

/**
Expand Down

0 comments on commit f0e4253

Please sign in to comment.