net.yudichev.jiotty.common.lang.ConflatingInbox Maven / Gradle / Ivy
package net.yudichev.jiotty.common.lang;
import javax.annotation.concurrent.ThreadSafe;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import static com.google.common.base.Preconditions.checkNotNull;
@ThreadSafe
public final class ConflatingInbox {
private final AtomicReference pendingValue = new AtomicReference<>();
public boolean add(T value) {
return pendingValue.getAndSet(checkNotNull(value)) == null;
}
public Optional get() {
return Optional.ofNullable(pendingValue.getAndSet(null));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy