@Override public synchronized Object computeIfPresent( Object key, BiFunction<? super Object, ? super Object, ? extends Object> remappingFunction ) { return storageMap.computeIfPresent( key, remappingFunction ); }
@Override public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { return map.computeIfPresent(key, typeChecked(remappingFunction)); }
private void removeIfExpired(K k) { map.computeIfPresent(k, (key, holder) -> holder.hasNotExpired() ? holder : null); }
@Override public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { return delegate().computeIfPresent(key, remappingFunction); } @Override public V compute(K key,
@Override public void removeIfPresent(K k, V v, Handler<AsyncResult<Boolean>> resultHandler) { AtomicBoolean result = new AtomicBoolean(); map.computeIfPresent(k, (key, holder) -> { if (holder.value.equals(v)) { result.compareAndSet(false, true); if (holder.expires()) { vertx.cancelTimer(holder.timerId); } return null; } return holder; }); resultHandler.handle(Future.succeededFuture(result.get())); }
private boolean unsubscribe(String queryName, QuerySubscription querySubscription) { subscriptions.computeIfPresent(queryName, (key, handlers) -> { handlers.remove(querySubscription); if (handlers.isEmpty()) { return null; } return handlers; }); return true; }
@Override public void untrackHashInvalidation(long chainKey) { getInvalidationMap().computeIfPresent(chainKey, (key, count) -> { if (count == 1) { return null; } return count - 1; }); }
@Override public void replaceIfPresent(K k, V oldValue, V newValue, Handler<AsyncResult<Boolean>> resultHandler) { Holder<V> h = new Holder<>(newValue); Holder<V> result = map.computeIfPresent(k, (key, holder) -> { if (holder.value.equals(oldValue)) { if (holder.expires()) { vertx.cancelTimer(holder.timerId); } return h; } return holder; }); resultHandler.handle(Future.succeededFuture(h == result)); }
private void checkSegmentCaughtUp(Segment segment, BlockingStream<TrackedEventMessage<?>> eventStream) { if (!eventStream.hasNextAvailable()) { activeSegments.computeIfPresent(segment.getSegmentId(), (k, v) -> v.caughtUp()); } }
public void testComputeIfPresent() { cache.put(key, "1"); // simultaneous update for same key, expect count successful updates doParallelCacheOp( count, n -> { cache.asMap().computeIfPresent(key, (k, v) -> v + delimiter + n); }); assertEquals(1, cache.size()); assertThat(cache.getIfPresent(key).split(delimiter)).hasLength(count + 1); }
cache.asMap().computeIfPresent(entry.getKey(), (k, expirable) -> { if (expirable == entry.getValue()) { dispatcher.publishExpired(this, entry.getKey(), entry.getValue().get());
/** * computeIfPresent does not replace if the key is already present */ public void testComputeIfPresent() { ConcurrentMap map = map5(); map.computeIfPresent(six, (x, y) -> "Z"); assertFalse(map.containsKey(six)); }
public void testComputeIfPresent() { cache.put(key, "1"); // simultaneous update for same key, expect count successful updates doParallelCacheOp(count, n -> { cache.asMap().computeIfPresent(key, (k, v) -> v + delimiter + n); }); assertEquals(1, cache.size()); assertThat(cache.getIfPresent(key).split(delimiter)).hasLength(count + 1); }
/** * computeIfPresent adds when the given key is not present */ public void testComputeIfPresent2() { ConcurrentMap map = map5(); assertEquals("Z", map.computeIfPresent(one, (x, y) -> "Z")); }
@Override public boolean containsKey(K key) { requireNotClosed(); Expirable<V> expirable = cache.getIfPresent(key); if (expirable == null) { return false; } if (!expirable.isEternal() && expirable.hasExpired(currentTimeMillis())) { cache.asMap().computeIfPresent(key, (k, e) -> { if (e == expirable) { dispatcher.publishExpired(this, key, expirable.get()); statistics.recordEvictions(1); return null; } return e; }); dispatcher.awaitSynchronous(); return false; } return true; }
/** * Removes the mapping from the cache without store-by-value copying nor waiting for synchronous * listeners to complete. * * @param key key whose mapping is to be removed from the cache * @return the old value */ private V removeNoCopyOrAwait(K key) { @SuppressWarnings("unchecked") V[] removed = (V[]) new Object[1]; cache.asMap().computeIfPresent(key, (k, expirable) -> { if (!expirable.isEternal() && expirable.hasExpired(currentTimeMillis())) { dispatcher.publishExpired(this, key, expirable.get()); statistics.recordEvictions(1L); return null; } dispatcher.publishRemoved(this, key, expirable.get()); removed[0] = expirable.get(); return null; }); return removed[0]; }
cache.asMap().computeIfPresent(key, (k, expirable) -> { long millis = expirable.isEternal() ? 0L
@SuppressWarnings("unchecked") V[] replaced = (V[]) new Object[1]; cache.asMap().computeIfPresent(key, (k, expirable) -> { if (!expirable.isEternal() && expirable.hasExpired(currentTimeMillis())) { dispatcher.publishExpired(this, key, expirable.get());
if (expirable.hasExpired(millis)) { Expirable<V> expired = expirable; cache.asMap().computeIfPresent(key, (k, e) -> { if (e == expired) { dispatcher.publishExpired(this, key, expired.get());
millis = nanosToMillis(start); if (expirable.hasExpired(millis)) { cache.asMap().computeIfPresent(key, (k, e) -> { if (e == expirable) { dispatcher.publishExpired(this, key, expirable.get());