Coverage Summary for Class: ForwardingFuture (com.google.common.util.concurrent)
| Class | Method, % | Line, % |
|---|---|---|
| ForwardingFuture | 33.3% (2/6) | 33.3% (2/6) |
| ForwardingFuture$SimpleForwardingFuture | 0% (0/2) | 0% (0/3) |
| Total | 25% (2/8) | 22.2% (2/9) |
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.common.collect.ForwardingObject; 20 import com.google.errorprone.annotations.CanIgnoreReturnValue; 21 import java.util.concurrent.ExecutionException; 22 import java.util.concurrent.Future; 23 import java.util.concurrent.TimeUnit; 24 import java.util.concurrent.TimeoutException; 25 import org.checkerframework.checker.nullness.qual.Nullable; 26 27 /** 28 * A {@link Future} which forwards all its method calls to another future. Subclasses should 29 * override one or more methods to modify the behavior of the backing future as desired per the <a 30 * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>. 31 * 32 * <p>Most subclasses can just use {@link SimpleForwardingFuture}. 33 * 34 * @author Sven Mawson 35 * @since 1.0 36 */ 37 @CanIgnoreReturnValue // TODO(cpovirk): Consider being more strict. 38 @GwtCompatible 39 @ElementTypesAreNonnullByDefault 40 public abstract class ForwardingFuture<V extends @Nullable Object> extends ForwardingObject 41 implements Future<V> { 42 /** Constructor for use by subclasses. */ 43 protected ForwardingFuture() {} 44 45 @Override 46 protected abstract Future<? extends V> delegate(); 47 48 @Override 49 public boolean cancel(boolean mayInterruptIfRunning) { 50 return delegate().cancel(mayInterruptIfRunning); 51 } 52 53 @Override 54 public boolean isCancelled() { 55 return delegate().isCancelled(); 56 } 57 58 @Override 59 public boolean isDone() { 60 return delegate().isDone(); 61 } 62 63 @Override 64 @ParametricNullness 65 public V get() throws InterruptedException, ExecutionException { 66 return delegate().get(); 67 } 68 69 @Override 70 @ParametricNullness 71 public V get(long timeout, TimeUnit unit) 72 throws InterruptedException, ExecutionException, TimeoutException { 73 return delegate().get(timeout, unit); 74 } 75 76 // TODO(cpovirk): Use standard Javadoc form for SimpleForwarding* class and constructor 77 /** 78 * A simplified version of {@link ForwardingFuture} where subclasses can pass in an already 79 * constructed {@link Future} as the delegate. 80 * 81 * @since 9.0 82 */ 83 public abstract static class SimpleForwardingFuture<V extends @Nullable Object> 84 extends ForwardingFuture<V> { 85 private final Future<V> delegate; 86 87 protected SimpleForwardingFuture(Future<V> delegate) { 88 this.delegate = Preconditions.checkNotNull(delegate); 89 } 90 91 @Override 92 protected final Future<V> delegate() { 93 return delegate; 94 } 95 } 96 }