Removes and returns the value associated with key. If key is not in the map, this method has no effect and returns zero.
(K key)
| 254 | */ |
| 255 | |
| 256 | @CanIgnoreReturnValue |
| 257 | public long remove(K key) { |
| 258 | AtomicLong atomic = map.get(key); |
| 259 | if (atomic == null) { |
| 260 | return 0L; |
| 261 | } |
| 262 | |
| 263 | while (true) { |
| 264 | long oldValue = atomic.get(); |
| 265 | if (oldValue == 0L || atomic.compareAndSet(oldValue, 0L)) { |
| 266 | // only remove after setting to zero, to avoid concurrent updates |
| 267 | map.remove(key, atomic); |
| 268 | // succeed even if the remove fails, since the value was already adjusted |
| 269 | return oldValue; |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * Removes all mappings from this map whose values are zero. |
nothing calls this directly
no test coverage detected