All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.yudichev.jiotty.common.lang.ConflatingInbox Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
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