If (key, expectedOldValue) is currently in the map, this method replaces expectedOldValue with newValue and returns true; otherwise, this method returns false. If expectedOldValue is zero, this method will succeed if (key, zero) is currently in the map, or
(K key, long expectedOldValue, long newValue)
| 434 | */ |
| 435 | |
| 436 | boolean replace(K key, long expectedOldValue, long newValue) { |
| 437 | if (expectedOldValue == 0L) { |
| 438 | return putIfAbsent(key, newValue) == 0L; |
| 439 | } else { |
| 440 | AtomicLong atomic = map.get(key); |
| 441 | return (atomic == null) ? false : atomic.compareAndSet(expectedOldValue, newValue); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | /** |
| 446 | * If {@code (key, value)} is currently in the map, this method removes it and returns true; |
no test coverage detected