99 |
|
* If the specified key is not already associated |
100 |
|
* with a value, associate it with the given value. |
101 |
|
* This is equivalent to |
102 |
< |
* <pre> {@code |
102 |
> |
* <pre> {@code |
103 |
|
* if (!map.containsKey(key)) |
104 |
|
* return map.put(key, value); |
105 |
|
* else |
106 |
< |
* return map.get(key); |
107 |
< |
* }</pre> |
106 |
> |
* return map.get(key);}</pre> |
107 |
|
* |
108 |
|
* except that the action is performed atomically. |
109 |
|
* |
131 |
|
/** |
132 |
|
* Removes the entry for a key only if currently mapped to a given value. |
133 |
|
* This is equivalent to |
134 |
< |
* <pre> {@code |
134 |
> |
* <pre> {@code |
135 |
|
* if (map.containsKey(key) && Objects.equals(map.get(key), value)) { |
136 |
|
* map.remove(key); |
137 |
|
* return true; |
138 |
< |
* } else |
138 |
> |
* } else { |
139 |
|
* return false; |
140 |
< |
* }</pre> |
140 |
> |
* }}</pre> |
141 |
|
* |
142 |
|
* except that the action is performed atomically. |
143 |
|
* |
161 |
|
/** |
162 |
|
* Replaces the entry for a key only if currently mapped to a given value. |
163 |
|
* This is equivalent to |
164 |
< |
* <pre> {@code |
164 |
> |
* <pre> {@code |
165 |
|
* if (map.containsKey(key) && Objects.equals(map.get(key), oldValue)) { |
166 |
|
* map.put(key, newValue); |
167 |
|
* return true; |
168 |
< |
* } else |
168 |
> |
* } else { |
169 |
|
* return false; |
170 |
< |
* }</pre> |
170 |
> |
* }}</pre> |
171 |
|
* |
172 |
|
* except that the action is performed atomically. |
173 |
|
* |
192 |
|
/** |
193 |
|
* Replaces the entry for a key only if currently mapped to some value. |
194 |
|
* This is equivalent to |
195 |
< |
* <pre> {@code |
195 |
> |
* <pre> {@code |
196 |
|
* if (map.containsKey(key)) { |
197 |
|
* return map.put(key, value); |
198 |
< |
* } else |
198 |
> |
* } else { |
199 |
|
* return null; |
200 |
< |
* }</pre> |
200 |
> |
* }}</pre> |
201 |
|
* |
202 |
|
* except that the action is performed atomically. |
203 |
|
* |
274 |
|
* |
275 |
|
* <pre> {@code |
276 |
|
* if (map.get(key) == null) { |
277 |
< |
* V newValue = mappingFunction.apply(key); |
278 |
< |
* if (newValue != null) |
279 |
< |
* return map.putIfAbsent(key, newValue); |
280 |
< |
* } |
282 |
< |
* }</pre> |
277 |
> |
* V newValue = mappingFunction.apply(key); |
278 |
> |
* if (newValue != null) |
279 |
> |
* return map.putIfAbsent(key, newValue); |
280 |
> |
* }}</pre> |
281 |
|
* |
282 |
|
* The default implementation may retry these steps when multiple |
283 |
|
* threads attempt updates including potentially calling the mapping |
309 |
|
* @implSpec |
310 |
|
* The default implementation is equivalent to performing the following |
311 |
|
* steps for this {@code map}, then returning the current value or |
312 |
< |
* {@code null} if now absent. : |
312 |
> |
* {@code null} if now absent: |
313 |
|
* |
314 |
|
* <pre> {@code |
315 |
|
* if (map.get(key) != null) { |
316 |
< |
* V oldValue = map.get(key); |
317 |
< |
* V newValue = remappingFunction.apply(key, oldValue); |
318 |
< |
* if (newValue != null) |
319 |
< |
* map.replace(key, oldValue, newValue); |
320 |
< |
* else |
321 |
< |
* map.remove(key, oldValue); |
322 |
< |
* } |
325 |
< |
* }</pre> |
316 |
> |
* V oldValue = map.get(key); |
317 |
> |
* V newValue = remappingFunction.apply(key, oldValue); |
318 |
> |
* if (newValue != null) |
319 |
> |
* map.replace(key, oldValue, newValue); |
320 |
> |
* else |
321 |
> |
* map.remove(key, oldValue); |
322 |
> |
* }}</pre> |
323 |
|
* |
324 |
|
* The default implementation may retry these steps when multiple threads |
325 |
|
* attempt updates including potentially calling the remapping function |
363 |
|
* V oldValue = map.get(key); |
364 |
|
* V newValue = remappingFunction.apply(key, oldValue); |
365 |
|
* if (oldValue != null ) { |
366 |
< |
* if (newValue != null) |
367 |
< |
* map.replace(key, oldValue, newValue); |
368 |
< |
* else |
369 |
< |
* map.remove(key, oldValue); |
366 |
> |
* if (newValue != null) |
367 |
> |
* map.replace(key, oldValue, newValue); |
368 |
> |
* else |
369 |
> |
* map.remove(key, oldValue); |
370 |
|
* } else { |
371 |
< |
* if (newValue != null) |
372 |
< |
* map.putIfAbsent(key, newValue); |
373 |
< |
* else |
374 |
< |
* return null; |
375 |
< |
* } |
379 |
< |
* }</pre> |
371 |
> |
* if (newValue != null) |
372 |
> |
* map.putIfAbsent(key, newValue); |
373 |
> |
* else |
374 |
> |
* return null; |
375 |
> |
* }}</pre> |
376 |
|
* |
377 |
|
* The default implementation may retry these steps when multiple |
378 |
|
* threads attempt updates including potentially calling the remapping |
445 |
|
* <pre> {@code |
446 |
|
* V oldValue = map.get(key); |
447 |
|
* V newValue = (oldValue == null) ? value : |
448 |
< |
* remappingFunction.apply(oldValue, value); |
448 |
> |
* remappingFunction.apply(oldValue, value); |
449 |
|
* if (newValue == null) |
450 |
< |
* map.remove(key); |
450 |
> |
* map.remove(key); |
451 |
|
* else |
452 |
< |
* map.put(key, newValue); |
457 |
< |
* }</pre> |
452 |
> |
* map.put(key, newValue);}</pre> |
453 |
|
* |
454 |
|
* <p>The default implementation may retry these steps when multiple |
455 |
|
* threads attempt updates including potentially calling the remapping |