8023306: Add replace() implementations to TreeMap
Reviewed-by: psandoz, alanb, chegar, bpb
--- a/jdk/src/share/classes/java/util/TreeMap.java Wed Aug 21 17:19:46 2013 +0200
+++ b/jdk/src/share/classes/java/util/TreeMap.java Wed Aug 21 12:03:19 2013 -0700
@@ -973,6 +973,27 @@
}
@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
public void forEach(BiConsumer<? super K, ? super V> action) {
Objects.requireNonNull(action);
int expectedModCount = modCount;