+
+ /**
+ * Complete target {@link CompletableFuture} either successfully or exceptionally based on the state of this object.
+ *
+ * @param future Future to complete
+ * @return True if this call has transitioned the future to a completed state, false otherwise.
+ * @throws NullPointerException if {code future} is null
+ */
+ public boolean completeFuture(final CompletableFuture<T> future) {
+ return isFirst() ? future.complete(first()) : future.completeExceptionally(second());
+ }
+
+ /**
+ * Complete target {@link SettableFuture} either successfully or exceptionally based on the state of this object.
+ *
+ * @param future Future to complete
+ * @return True if this call has transitioned the future to a completed state, false otherwise.
+ * @throws NullPointerException if {code future} is null
+ */
+ public boolean completeFuture(final SettableFuture<T> future) {
+ return isFirst() ? future.set(first()) : future.setException(second());
+ }
+
+ /**
+ * Transform this object into an immediately-completed {@link CompletableFuture}. The future will be successful
+ * if this object has a contained value or unsuccessful if this objects contains an exception.
+ *
+ * @return A {@link CompletableFuture}.
+ */
+ public CompletableFuture<T> toCompletableFuture() {
+ if (isFirst()) {
+ return CompletableFuture.completedFuture(first());
+ }
+ // FIXME: Java 9: use CompletableFuture.failedFuture()
+ final CompletableFuture<T> future = new CompletableFuture<>();
+ future.completeExceptionally(second());
+ return future;
+ }
+
+ /**
+ * Transform this object into an immediately-completed {@link FluentFuture}. The future will be successful
+ * if this object has a contained value or unsuccessful if this objects contains an exception.
+ *
+ * @return A {@link FluentFuture}.
+ */
+ public FluentFuture<T> toFluentFuture() {
+ final ListenableFuture<T> future;
+ if (isFirst()) {
+ future = Futures.immediateFuture(first());
+ } else {
+ future = Futures.immediateFailedFuture(second());
+ }
+ return FluentFuture.from(future);
+ }