/** * Increments by one the value currently associated with {@code key}, and returns the old value. */ @CanIgnoreReturnValue public long getAndIncrement(K key) { return getAndAdd(key, 1); }
/** * Decrements by one the value currently associated with {@code key}, and returns the old value. */ @CanIgnoreReturnValue public long getAndDecrement(K key) { return getAndAdd(key, -1); }
/** * Increments by one the value currently associated with {@code key}, and returns the old value. */ @CanIgnoreReturnValue public long getAndIncrement(K key) { return getAndAdd(key, 1); }
/** * Decrements by one the value currently associated with {@code key}, and returns the old value. */ @CanIgnoreReturnValue public long getAndDecrement(K key) { return getAndAdd(key, -1); }
@Override public long getAndAdd(long delta) { return getIncrement(increments.getAndAdd(localMemberId, delta)); }
public void testGetAndAdd_zero() { AtomicLongMap<String> map = AtomicLongMap.create(); String key = "key"; long value = random.nextInt(MAX_ADDEND); assertEquals(0L, map.get(key)); assertFalse(map.containsKey(key)); assertEquals(0L, map.getAndAdd(key, value)); assertEquals(value, map.get(key)); assertEquals(value, map.getAndAdd(key, -1 * value)); assertEquals(0L, map.get(key)); assertTrue(map.containsKey(key)); assertEquals(0L, map.getAndAdd(key, value)); assertEquals(value, map.get(key)); }
break; case 5: map.getAndAdd(key, delta); threadSum += delta; break;
public void testGetAndAdd() { AtomicLongMap<String> map = AtomicLongMap.create(); String key = "key"; long addend = random.nextInt(MAX_ADDEND); for (int i = 0; i < ITERATIONS; i++) { long before = map.get(key); long result = map.getAndAdd(key, addend); long after = map.get(key); assertEquals(before + addend, after); assertEquals(before, result); addend = after; } assertEquals(1, map.size()); assertTrue(!map.isEmpty()); assertTrue(map.containsKey(key)); }
/** * Increments by one the value currently associated with {@code key}, and returns the old value. */ public long getAndIncrement(K key) { return getAndAdd(key, 1); }
/** * Increments by one the value currently associated with {@code key}, and returns the old value. */ public long getAndIncrement(K key) { return getAndAdd(key, 1); }
/** * Decrements by one the value currently associated with {@code key}, and returns the old value. */ public long getAndDecrement(K key) { return getAndAdd(key, -1); }
/** * Increments by one the value currently associated with {@code key}, and returns the old value. */ public long getAndIncrement(K key) { return getAndAdd(key, 1); }
/** * Increments by one the value currently associated with {@code key}, and returns the old value. */ public long getAndIncrement(K key) { return getAndAdd(key, 1); }
/** * Increments by one the value currently associated with {@code key}, and returns the old value. */ public long getAndIncrement(K key) { return getAndAdd(key, 1); }
/** * Decrements by one the value currently associated with {@code key}, and returns the old value. */ public long getAndDecrement(K key) { return getAndAdd(key, -1); }
/** * Decrements by one the value currently associated with {@code key}, and returns the old value. */ public long getAndDecrement(K key) { return getAndAdd(key, -1); }
/** * Decrements by one the value currently associated with {@code key}, and returns the old value. */ public long getAndDecrement(K key) { return getAndAdd(key, -1); }
/** * Increments by one the value currently associated with {@code key}, and returns the old value. */ public long getAndIncrement(K key) { return getAndAdd(key, 1); }
/** * Increments by one the value currently associated with {@code key}, and returns the old value. */ @CanIgnoreReturnValue public long getAndIncrement(K key) { return getAndAdd(key, 1); }
/** * Increments by one the value currently associated with {@code key}, and returns the old value. */ @CanIgnoreReturnValue public long getAndIncrement(K key) { return getAndAdd(key, 1); }