MCPcopy Create free account
hub / github.com/antlr/codebuff / put

Method put

output/java_guava/1.4.19/AtomicLongMap.java:206–235  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 1

putAllMethod · 0.95

Calls 4

getMethod · 0.65
putIfAbsentMethod · 0.45
replaceMethod · 0.45
compareAndSetMethod · 0.45

Tested by

no test coverage detected