001/*
002 * Copyright (C) 2012 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.collect;
018
019import com.google.common.annotations.GwtIncompatible;
020import java.util.Collection;
021import java.util.concurrent.BlockingDeque;
022import java.util.concurrent.TimeUnit;
023import javax.annotation.CheckForNull;
024
025/**
026 * A {@link BlockingDeque} which forwards all its method calls to another {@code BlockingDeque}.
027 * Subclasses should override one or more methods to modify the behavior of the backing deque as
028 * desired per the <a href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
029 *
030 * <p><b>Warning:</b> The methods of {@code ForwardingBlockingDeque} forward <b>indiscriminately</b>
031 * to the methods of the delegate. For example, overriding {@link #add} alone <b>will not</b> change
032 * the behaviour of {@link #offer} which can lead to unexpected behaviour. In this case, you should
033 * override {@code offer} as well, either providing your own implementation, or delegating to the
034 * provided {@code standardOffer} method.
035 *
036 * <p><b>{@code default} method warning:</b> This class does <i>not</i> forward calls to {@code
037 * default} methods. Instead, it inherits their default implementations. When those implementations
038 * invoke methods, they invoke methods on the {@code ForwardingBlockingDeque}.
039 *
040 * <p>The {@code standard} methods are not guaranteed to be thread-safe, even when all of the
041 * methods that they depend on are thread-safe.
042 *
043 * @author Emily Soldal
044 * @since 14.0
045 * @deprecated This class has moved to {@code com.google.common.util.concurrent}. Please use {@link
046 *     com.google.common.util.concurrent.ForwardingBlockingDeque} instead.
047 */
048@Deprecated
049@GwtIncompatible
050@ElementTypesAreNonnullByDefault
051public abstract class ForwardingBlockingDeque<E> extends ForwardingDeque<E>
052    implements BlockingDeque<E> {
053
054  /** Constructor for use by subclasses. */
055  protected ForwardingBlockingDeque() {}
056
057  @Override
058  protected abstract BlockingDeque<E> delegate();
059
060  @Override
061  public int remainingCapacity() {
062    return delegate().remainingCapacity();
063  }
064
065  @Override
066  public void putFirst(E e) throws InterruptedException {
067    delegate().putFirst(e);
068  }
069
070  @Override
071  public void putLast(E e) throws InterruptedException {
072    delegate().putLast(e);
073  }
074
075  @Override
076  public boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException {
077    return delegate().offerFirst(e, timeout, unit);
078  }
079
080  @Override
081  public boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException {
082    return delegate().offerLast(e, timeout, unit);
083  }
084
085  @Override
086  public E takeFirst() throws InterruptedException {
087    return delegate().takeFirst();
088  }
089
090  @Override
091  public E takeLast() throws InterruptedException {
092    return delegate().takeLast();
093  }
094
095  @Override
096  @CheckForNull
097  public E pollFirst(long timeout, TimeUnit unit) throws InterruptedException {
098    return delegate().pollFirst(timeout, unit);
099  }
100
101  @Override
102  @CheckForNull
103  public E pollLast(long timeout, TimeUnit unit) throws InterruptedException {
104    return delegate().pollLast(timeout, unit);
105  }
106
107  @Override
108  public void put(E e) throws InterruptedException {
109    delegate().put(e);
110  }
111
112  @Override
113  public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException {
114    return delegate().offer(e, timeout, unit);
115  }
116
117  @Override
118  public E take() throws InterruptedException {
119    return delegate().take();
120  }
121
122  @Override
123  @CheckForNull
124  public E poll(long timeout, TimeUnit unit) throws InterruptedException {
125    return delegate().poll(timeout, unit);
126  }
127
128  @Override
129  public int drainTo(Collection<? super E> c) {
130    return delegate().drainTo(c);
131  }
132
133  @Override
134  public int drainTo(Collection<? super E> c, int maxElements) {
135    return delegate().drainTo(c, maxElements);
136  }
137}