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