8247402: Documentation for Map::compute contains confusing implementation requirements

Reviewed-by: prappo, martin
This commit is contained in:
John Lin 2020-12-11 00:26:10 +00:00 committed by Pavel Rappo
parent d4282b0cfc
commit 37dc675cd0

View file

@ -1109,23 +1109,17 @@ public interface Map<K, V> {
*
* @implSpec
* The default implementation is equivalent to performing the following
* steps for this {@code map}, then returning the current value or
* {@code null} if absent:
* steps for this {@code map}:
*
* <pre> {@code
* V oldValue = map.get(key);
* V newValue = remappingFunction.apply(key, oldValue);
* if (oldValue != null) {
* if (newValue != null)
* map.put(key, newValue);
* else
* map.remove(key);
* } else {
* if (newValue != null)
* map.put(key, newValue);
* else
* return null;
* if (newValue != null) {
* map.put(key, newValue);
* } else if (oldValue != null || map.containsKey(key)) {
* map.remove(key);
* }
* return newValue;
* }</pre>
*
* <p>The default implementation makes no guarantees about detecting if the