001/*
002 * Copyright (C) 2009 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.google.common.util.concurrent;
018
019import com.google.common.annotations.Beta;
020import com.google.common.annotations.GwtCompatible;
021
022import javax.annotation.Nullable;
023
024/**
025 * A {@link ListenableFuture} whose result may be set by a {@link #set(Object)},
026 * {@link #setException(Throwable)} or {@link #setFuture(ListenableFuture)} call. 
027 * It may also be cancelled.
028 *
029 * @author Sven Mawson
030 * @since 9.0 (in 1.0 as {@code ValueFuture})
031 */
032@GwtCompatible
033public final class SettableFuture<V> extends AbstractFuture.TrustedFuture<V> {
034
035  /**
036   * Creates a new {@code SettableFuture} in the default state.
037   */
038  public static <V> SettableFuture<V> create() {
039    return new SettableFuture<V>();
040  }
041
042  /**
043   * Explicit private constructor, use the {@link #create} factory method to
044   * create instances of {@code SettableFuture}.
045   */
046  private SettableFuture() {}
047
048  @Override public boolean set(@Nullable V value) {
049    return super.set(value);
050  }
051
052  @Override public boolean setException(Throwable throwable) {
053    return super.setException(throwable);
054  }
055
056  @Beta
057  @Override
058  public boolean setFuture(ListenableFuture<? extends V> future) {
059    return super.setFuture(future);
060  }
061}