8023306: Add replace() implementations to TreeMap
Reviewed-by: psandoz, alanb, chegar, bpb
This commit is contained in:
parent
01ba926ba1
commit
8a3c65febe
@ -972,6 +972,27 @@ public class TreeMap<K,V>
|
|||||||
return tailMap(fromKey, true);
|
return tailMap(fromKey, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean replace(K key, V oldValue, V newValue) {
|
||||||
|
Entry<K,V> p = getEntry(key);
|
||||||
|
if (p!=null && Objects.equals(oldValue, p.value)) {
|
||||||
|
p.value = newValue;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public V replace(K key, V value) {
|
||||||
|
Entry<K,V> p = getEntry(key);
|
||||||
|
if (p!=null) {
|
||||||
|
V oldValue = p.value;
|
||||||
|
p.value = value;
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forEach(BiConsumer<? super K, ? super V> action) {
|
public void forEach(BiConsumer<? super K, ? super V> action) {
|
||||||
Objects.requireNonNull(action);
|
Objects.requireNonNull(action);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user