001    /*
002     * Copyright (C) 2009 Google Inc.
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    
017    package com.google.common.util.concurrent;
018    
019    import com.google.common.collect.ForwardingObject;
020    
021    import java.util.concurrent.ExecutionException;
022    import java.util.concurrent.Future;
023    import java.util.concurrent.TimeUnit;
024    import java.util.concurrent.TimeoutException;
025    
026    /**
027     * A {@link Future} which forwards all its method calls to another future.
028     * Subclasses should override one or more methods to modify the behavior of
029     * the backing collection as desired per the <a
030     * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
031     *
032     * @author Sven Mawson
033     * @since 1
034     */
035    public abstract class ForwardingFuture<V> extends ForwardingObject
036        implements Future<V> {
037    
038      /** Constructor for use by subclasses. */
039      protected ForwardingFuture() {}
040    
041      @Override protected abstract Future<V> delegate();
042    
043      @Override
044      public boolean cancel(boolean mayInterruptIfRunning) {
045        return delegate().cancel(mayInterruptIfRunning);
046      }
047    
048      @Override
049      public boolean isCancelled() {
050        return delegate().isCancelled();
051      }
052    
053      @Override
054      public boolean isDone() {
055        return delegate().isDone();
056      }
057    
058      @Override
059      public V get() throws InterruptedException, ExecutionException {
060        return delegate().get();
061      }
062    
063      @Override
064      public V get(long timeout, TimeUnit unit)
065          throws InterruptedException, ExecutionException, TimeoutException {
066        return delegate().get(timeout, unit);
067      }
068    }