public final long updateAndGet(LongUnaryOperator updateFunction) { int expectedVersion; long newValue; do { expectedVersion = version; newValue = updateFunction.applyAsLong(value); } while (expectedVersion != version); ++version; value = newValue; return newValue; }
public final long getAndUpdate(LongUnaryOperator updateFunction) { int expectedVersion; long result; long newValue; do { expectedVersion = version; result = value; newValue = updateFunction.applyAsLong(value); } while (expectedVersion != version); ++version; value = newValue; return result; }
public static long apply(LongUnaryOperator longUnaryOperator, long value) { return longUnaryOperator.applyAsLong(value); } }
/** * Updates the value currently associated with {@code key} with the specified function, and * returns the new value. If there is not currently a value associated with {@code key}, the * function is applied to {@code 0L}. * * @since 21.0 */ @CanIgnoreReturnValue public long updateAndGet(K key, LongUnaryOperator updaterFunction) { checkNotNull(updaterFunction); return map.compute( key, (k, value) -> updaterFunction.applyAsLong((value == null) ? 0L : value.longValue())); }
/** * Updates the value currently associated with {@code key} with the specified function, and * returns the old value. If there is not currently a value associated with {@code key}, the * function is applied to {@code 0L}. * * @since 21.0 */ @CanIgnoreReturnValue public long getAndUpdate(K key, LongUnaryOperator updaterFunction) { checkNotNull(updaterFunction); AtomicLong holder = new AtomicLong(); map.compute( key, (k, value) -> { long oldValue = (value == null) ? 0L : value.longValue(); holder.set(oldValue); return updaterFunction.applyAsLong(oldValue); }); return holder.get(); }
@Override public ToLongNullable<T> mapIfPresent(LongUnaryOperator mapper) { return t -> isNull.test(t) ? null : mapper.applyAsLong(original.applyAsLong(t)); }
@Override public long applyAsLong(T object) throws NullPointerException { return mapper.applyAsLong(delegate.applyAsLong(object)); }
@Override public long applyAsLong(T object) { return this.mapper.applyAsLong(this.inner.applyAsLong(object)); }
@Override public boolean next(LongPredicate consumer) { while (true) { long valueToReport = value; value = f.applyAsLong(value); if (!consumer.test(valueToReport)) { return true; } } } }
@Override protected LongPredicate wrap(LongPredicate consumer) { return t -> consumer.test(mapper.applyAsLong(t)); }
/** * Updates the value currently associated with {@code key} with the specified function, and * returns the old value. If there is not currently a value associated with {@code key}, the * function is applied to {@code 0L}. * * @since 21.0 */ @CanIgnoreReturnValue public long getAndUpdate(K key, LongUnaryOperator updaterFunction) { checkNotNull(updaterFunction); AtomicLong holder = new AtomicLong(); map.compute( key, (k, value) -> { long oldValue = (value == null) ? 0L : value.longValue(); holder.set(oldValue); return updaterFunction.applyAsLong(oldValue); }); return holder.get(); }
/** * Updates the value currently associated with {@code key} with the specified function, and * returns the new value. If there is not currently a value associated with {@code key}, the * function is applied to {@code 0L}. * * @since 21.0 */ @CanIgnoreReturnValue public long updateAndGet(K key, LongUnaryOperator updaterFunction) { checkNotNull(updaterFunction); return map.compute( key, (k, value) -> updaterFunction.applyAsLong((value == null) ? 0L : value.longValue())); }
/** * Updates the value currently associated with {@code key} with the specified function, and * returns the new value. If there is not currently a value associated with {@code key}, the * function is applied to {@code 0L}. * * @since 21.0 */ @CanIgnoreReturnValue public long updateAndGet(K key, LongUnaryOperator updaterFunction) { checkNotNull(updaterFunction); return map.compute( key, (k, value) -> updaterFunction.applyAsLong((value == null) ? 0L : value.longValue())); }
/** * Updates the value currently associated with {@code key} with the specified function, and * returns the old value. If there is not currently a value associated with {@code key}, the * function is applied to {@code 0L}. * * @since 21.0 */ @CanIgnoreReturnValue public long getAndUpdate(K key, LongUnaryOperator updaterFunction) { checkNotNull(updaterFunction); AtomicLong holder = new AtomicLong(); map.compute( key, (k, value) -> { long oldValue = (value == null) ? 0L : value.longValue(); holder.set(oldValue); return updaterFunction.applyAsLong(oldValue); }); return holder.get(); }
@Override public ToLong<T> orElse(Long value) { return object -> delegate.isNull(object) ? value : mapper.applyAsLong(delegate.applyAsLong(object)); }
@Override public Long apply(T object) { return delegate.isNull(object) ? null : mapper.applyAsLong(delegate.applyAsLong(object)); }
/** * Atomically update the current value using the given {@link LongUnaryOperator update function}. * * @param updateFunction the function which calculates the value to set. Should be a pure function (no side effects), * because it will be applied several times if update attempts fail due to concurrent calls. * @return the updated value. * @since 2.2 */ public long updateAndGet(LongUnaryOperator updateFunction) { Assert.notNull(updateFunction, "Update function must not be null!"); long previousValue, newValue; do { previousValue = get(); newValue = updateFunction.applyAsLong(previousValue); } while (!compareAndSet(previousValue, newValue)); return newValue; }
/** * Atomically update the current value using the given {@link LongUnaryOperator update function}. * * @param updateFunction the function which calculates the value to set. Should be a pure function (no side effects), * because it will be applied several times if update attempts fail due to concurrent calls. * @return the previous value. * @since 2.2 */ public long getAndUpdate(LongUnaryOperator updateFunction) { Assert.notNull(updateFunction, "Update function must not be null!"); long previousValue, newValue; do { previousValue = get(); newValue = updateFunction.applyAsLong(previousValue); } while (!compareAndSet(previousValue, newValue)); return previousValue; }
@Override public ToLong<T> orElseGet(ToLong<T> getter) { return object -> delegate.isNull(object) ? getter.applyAsLong(object) : mapper.applyAsLong(delegate.applyAsLong(object)); }
@Override public MutableLong set(final long value) { host.set(fn.applyAsLong(value)); return this; }