src/share/classes/java/util/Hashtable.java
Print this page
rev 7313 : 8016446: Improve forEach/replaceAll for Map, HashMap, Hashtable, IdentityHashMap, WeakHashMap, TreeMap
Reviewed-by: forax, duigou
Contributed-by: Mike Duigou <mike.duigou@oracle.com>, Remi Forax <forax@univ-mlv.fr>
*** 942,952 ****
}
@Override
public synchronized void replaceAll(
BiFunction<? super K, ? super V, ? extends V> function) {
! Map.super.replaceAll(function);
}
@Override
public synchronized V putIfAbsent(K key, V value) {
Objects.requireNonNull(value);
--- 942,961 ----
}
@Override
public synchronized void replaceAll(
BiFunction<? super K, ? super V, ? extends V> function) {
! Objects.requireNonNull(function); // explicit check required in case
! // table is empty.
! Entry<K,V>[] tab = (Entry<K,V>[]) table;
! for (Entry<K,V> entry : tab) {
! while (entry != null) {
! entry.value = Objects.requireNonNull(
! function.apply(entry.key, entry.value));
! entry = entry.next;
! }
! }
}
@Override
public synchronized V putIfAbsent(K key, V value) {
Objects.requireNonNull(value);
*** 1056,1066 ****
return newValue;
}
@Override
! public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
Objects.requireNonNull(remappingFunction);
Entry<?,?> tab[] = table;
int hash = hash(key);
int index = (hash & 0x7FFFFFFF) % tab.length;
--- 1065,1075 ----
return newValue;
}
@Override
! public synchronized V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
Objects.requireNonNull(remappingFunction);
Entry<?,?> tab[] = table;
int hash = hash(key);
int index = (hash & 0x7FFFFFFF) % tab.length;
*** 1085,1095 ****
}
return null;
}
@Override
! public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
Objects.requireNonNull(remappingFunction);
Entry<?,?> tab[] = table;
int hash = hash(key);
int index = (hash & 0x7FFFFFFF) % tab.length;
--- 1094,1104 ----
}
return null;
}
@Override
! public synchronized V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
Objects.requireNonNull(remappingFunction);
Entry<?,?> tab[] = table;
int hash = hash(key);
int index = (hash & 0x7FFFFFFF) % tab.length;
*** 1120,1130 ****
return newValue;
}
@Override
! public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
Objects.requireNonNull(remappingFunction);
Entry<?,?> tab[] = table;
int hash = hash(key);
int index = (hash & 0x7FFFFFFF) % tab.length;
--- 1129,1139 ----
return newValue;
}
@Override
! public synchronized V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
Objects.requireNonNull(remappingFunction);
Entry<?,?> tab[] = table;
int hash = hash(key);
int index = (hash & 0x7FFFFFFF) % tab.length;