// Path: agera/src/main/java/com/google/android/agera/Result.java
// @NonNull
// public static <T> Result<T> absentIfNull(@Nullable final T value) {
//   return value == null ? Result.<T>absent() : present(value);
// }


import static com.google.android.agera.Preconditions.checkNotNull;
import static com.google.android.agera.Result.absentIfNull;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.ArrayDeque;
import java.util.PriorityQueue;
import java.util.Queue;

    private SynchronizedReservoir(@NonNull final Queue<T> queue) {
      this.queue = checkNotNull(queue);
    }

    @Override
    public void accept(@NonNull T value) {
      boolean shouldDispatchUpdate;
      synchronized (queue) {
        boolean wasEmpty = queue.isEmpty();
        boolean added = queue.offer(value);
        shouldDispatchUpdate = wasEmpty && added;
      }
      if (shouldDispatchUpdate) {
        dispatchUpdate();
      }
    }

    @NonNull
    @Override
    public Result<T> get() {
      T nullableValue;
      boolean shouldDispatchUpdate;
      synchronized (queue) {
        nullableValue = queue.poll();
        shouldDispatchUpdate = !queue.isEmpty();
      }
      if (shouldDispatchUpdate) {
        dispatchUpdate();
      }
// Path: agera/src/main/java/com/google/android/agera/Result.java
// @NonNull
// public static <T> Result<T> absentIfNull(@Nullable final T value) {
//   return value == null ? Result.<T>absent() : present(value);
// }


// Path: agera/src/main/java/com/google/android/agera/Reservoirs.java
import static com.google.android.agera.Preconditions.checkNotNull;
import static com.google.android.agera.Result.absentIfNull;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.ArrayDeque;
import java.util.PriorityQueue;
import java.util.Queue;


    private SynchronizedReservoir(@NonNull final Queue<T> queue) {
      this.queue = checkNotNull(queue);
    }

    @Override
    public void accept(@NonNull T value) {
      boolean shouldDispatchUpdate;
      synchronized (queue) {
        boolean wasEmpty = queue.isEmpty();
        boolean added = queue.offer(value);
        shouldDispatchUpdate = wasEmpty && added;
      }
      if (shouldDispatchUpdate) {
        dispatchUpdate();
      }
    }

    @NonNull
    @Override
    public Result<T> get() {
      T nullableValue;
      boolean shouldDispatchUpdate;
      synchronized (queue) {
        nullableValue = queue.poll();
        shouldDispatchUpdate = !queue.isEmpty();
      }
      if (shouldDispatchUpdate) {
        dispatchUpdate();
      }
      return absentIfNull(nullableValue);