提交 4685f55b 编写于 作者: M mduigou

8023306: Add replace() implementations to TreeMap

Reviewed-by: psandoz, alanb, chegar, bpb
上级 464de8ab
...@@ -972,6 +972,27 @@ public class TreeMap<K,V> ...@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册