A version of Map#computeIfAbsent(Object, Function) that allows mappingFunction to update map.
(
Map<K, V> map, K key, Function<? super K, ? extends V> mappingFunction)
| 88 | * to update {@code map}. |
| 89 | */ |
| 90 | static <K, V> V reentrantComputeIfAbsent( |
| 91 | Map<K, V> map, K key, Function<? super K, ? extends V> mappingFunction) { |
| 92 | V value = map.get(key); |
| 93 | if (value == null) { |
| 94 | value = mappingFunction.apply(key); |
| 95 | if (value != null) { |
| 96 | map.put(key, value); |
| 97 | } |
| 98 | } |
| 99 | return value; |
| 100 | } |
| 101 | |
| 102 | private Util() {} |
| 103 | } |
no test coverage detected