Coverage Summary for Class: ForwardingListenableFuture (com.google.common.util.concurrent)

Class Method, % Line, %
ForwardingListenableFuture 50% (1/2) 33.3% (1/3)
ForwardingListenableFuture$SimpleForwardingListenableFuture 100% (2/2) 100% (4/4)
Total 75% (3/4) 71.4% (5/7)


1 /* 2  * Copyright (C) 2009 The Guava Authors 3  * 4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5  * in compliance with the License. You may obtain a copy of the License at 6  * 7  * http://www.apache.org/licenses/LICENSE-2.0 8  * 9  * Unless required by applicable law or agreed to in writing, software distributed under the License 10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11  * or implied. See the License for the specific language governing permissions and limitations under 12  * the License. 13  */ 14  15 package com.google.common.util.concurrent; 16  17 import com.google.common.annotations.GwtCompatible; 18 import com.google.common.base.Preconditions; 19 import com.google.errorprone.annotations.CanIgnoreReturnValue; 20 import java.util.concurrent.Executor; 21 import org.checkerframework.checker.nullness.qual.Nullable; 22  23 /** 24  * A {@link ListenableFuture} which forwards all its method calls to another future. Subclasses 25  * should override one or more methods to modify the behavior of the backing future as desired per 26  * the <a href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>. 27  * 28  * <p>Most subclasses can just use {@link SimpleForwardingListenableFuture}. 29  * 30  * @author Shardul Deo 31  * @since 4.0 32  */ 33 @CanIgnoreReturnValue // TODO(cpovirk): Consider being more strict. 34 @GwtCompatible 35 @ElementTypesAreNonnullByDefault 36 public abstract class ForwardingListenableFuture<V extends @Nullable Object> 37  extends ForwardingFuture<V> implements ListenableFuture<V> { 38  39  /** Constructor for use by subclasses. */ 40  protected ForwardingListenableFuture() {} 41  42  @Override 43  protected abstract ListenableFuture<? extends V> delegate(); 44  45  @Override 46  public void addListener(Runnable listener, Executor exec) { 47  delegate().addListener(listener, exec); 48  } 49  50  // TODO(cpovirk): Use standard Javadoc form for SimpleForwarding* class and constructor 51  /** 52  * A simplified version of {@link ForwardingListenableFuture} where subclasses can pass in an 53  * already constructed {@link ListenableFuture} as the delegate. 54  * 55  * @since 9.0 56  */ 57  public abstract static class SimpleForwardingListenableFuture<V extends @Nullable Object> 58  extends ForwardingListenableFuture<V> { 59  private final ListenableFuture<V> delegate; 60  61  protected SimpleForwardingListenableFuture(ListenableFuture<V> delegate) { 62  this.delegate = Preconditions.checkNotNull(delegate); 63  } 64  65  @Override 66  protected final ListenableFuture<V> delegate() { 67  return delegate; 68  } 69  } 70 }