Associates newValue with key in this map, and returns the value previously associated with key, or zero if there was no such value.
(K key, long newValue)
| 204 | */ |
| 205 | |
| 206 | @CanIgnoreReturnValue |
| 207 | public long put(K key, long newValue) { |
| 208 | outer: |
| 209 | while (true) { |
| 210 | AtomicLong atomic = map.get(key); |
| 211 | if (atomic == null) { |
| 212 | atomic = map.putIfAbsent(key, new AtomicLong(newValue)); |
| 213 | if (atomic == null) { |
| 214 | return 0L; |
| 215 | } |
| 216 | // atomic is now non-null; fall through |
| 217 | } |
| 218 | |
| 219 | while (true) { |
| 220 | long oldValue = atomic.get(); |
| 221 | if (oldValue == 0L) { |
| 222 | // don't compareAndSet a zero |
| 223 | if (map.replace(key, atomic, new AtomicLong(newValue))) { |
| 224 | return 0L; |
| 225 | } |
| 226 | // atomic replaced |
| 227 | continue outer; |
| 228 | } |
| 229 | if (atomic.compareAndSet(oldValue, newValue)) { |
| 230 | return oldValue; |
| 231 | } |
| 232 | // value changed |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Copies all of the mappings from the specified map to this map. The effect of this call is |
no test coverage detected