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

org.zalando.riptide.capture.DefaultCapture Maven / Gradle / Ivy

package org.zalando.riptide.capture;

import javax.annotation.Nullable;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;

final class DefaultCapture implements Capture {

    /**
     * A reference holding the captured value. It can represent three different states:
     * 
    *
  1. {@code null}: not captured
  2. *
  3. {@code Optional.empty()}: captured null
  4. *
  5. {@code Optional.of(..)}: captured non-null
  6. *
*/ private final AtomicReference> reference = new AtomicReference<>(); @Override public void tryAccept(@Nullable final T input) { // TODO fail on second capture? reference.compareAndSet(null, Optional.ofNullable(input)); } @Override public T apply(final Void result) { final Optional value = reference.get(); if (value == null) { // TODO throw specific exception? throw new NoSuchElementException("No value present"); } return value.orElse(null); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy