1 /* 2 * Copyright (C) 2012 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.common.collect; 18 19 import com.google.common.annotations.GwtIncompatible; 20 import com.google.common.annotations.J2ktIncompatible; 21 import java.util.Collection; 22 import java.util.concurrent.BlockingDeque; 23 import java.util.concurrent.TimeUnit; 24 import javax.annotation.CheckForNull; 25 26 /** 27 * A {@link BlockingDeque} which forwards all its method calls to another {@code BlockingDeque}. 28 * Subclasses should override one or more methods to modify the behavior of the backing deque as 29 * desired per the <a href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>. 30 * 31 * <p><b>Warning:</b> The methods of {@code ForwardingBlockingDeque} forward <b>indiscriminately</b> 32 * to the methods of the delegate. For example, overriding {@link #add} alone <b>will not</b> change 33 * the behaviour of {@link #offer} which can lead to unexpected behaviour. In this case, you should 34 * override {@code offer} as well, either providing your own implementation, or delegating to the 35 * provided {@code standardOffer} method. 36 * 37 * <p><b>{@code default} method warning:</b> This class does <i>not</i> forward calls to {@code 38 * default} methods. Instead, it inherits their default implementations. When those implementations 39 * invoke methods, they invoke methods on the {@code ForwardingBlockingDeque}. 40 * 41 * <p>The {@code standard} methods are not guaranteed to be thread-safe, even when all of the 42 * methods that they depend on are thread-safe. 43 * 44 * @author Emily Soldal 45 * @since 14.0 46 * @deprecated This class has moved to {@code com.google.common.util.concurrent}. Please use {@link 47 * com.google.common.util.concurrent.ForwardingBlockingDeque} instead. 48 */ 49 @Deprecated 50 @J2ktIncompatible 51 @GwtIncompatible 52 @ElementTypesAreNonnullByDefault 53 public abstract class ForwardingBlockingDeque<E> extends ForwardingDeque<E> 54 implements BlockingDeque<E> { 55 56 /** Constructor for use by subclasses. */ ForwardingBlockingDeque()57 protected ForwardingBlockingDeque() {} 58 59 @Override delegate()60 protected abstract BlockingDeque<E> delegate(); 61 62 @Override remainingCapacity()63 public int remainingCapacity() { 64 return delegate().remainingCapacity(); 65 } 66 67 @Override putFirst(E e)68 public void putFirst(E e) throws InterruptedException { 69 delegate().putFirst(e); 70 } 71 72 @Override putLast(E e)73 public void putLast(E e) throws InterruptedException { 74 delegate().putLast(e); 75 } 76 77 @Override offerFirst(E e, long timeout, TimeUnit unit)78 public boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException { 79 return delegate().offerFirst(e, timeout, unit); 80 } 81 82 @Override offerLast(E e, long timeout, TimeUnit unit)83 public boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException { 84 return delegate().offerLast(e, timeout, unit); 85 } 86 87 @Override takeFirst()88 public E takeFirst() throws InterruptedException { 89 return delegate().takeFirst(); 90 } 91 92 @Override takeLast()93 public E takeLast() throws InterruptedException { 94 return delegate().takeLast(); 95 } 96 97 @Override 98 @CheckForNull pollFirst(long timeout, TimeUnit unit)99 public E pollFirst(long timeout, TimeUnit unit) throws InterruptedException { 100 return delegate().pollFirst(timeout, unit); 101 } 102 103 @Override 104 @CheckForNull pollLast(long timeout, TimeUnit unit)105 public E pollLast(long timeout, TimeUnit unit) throws InterruptedException { 106 return delegate().pollLast(timeout, unit); 107 } 108 109 @Override put(E e)110 public void put(E e) throws InterruptedException { 111 delegate().put(e); 112 } 113 114 @Override offer(E e, long timeout, TimeUnit unit)115 public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException { 116 return delegate().offer(e, timeout, unit); 117 } 118 119 @Override take()120 public E take() throws InterruptedException { 121 return delegate().take(); 122 } 123 124 @Override 125 @CheckForNull poll(long timeout, TimeUnit unit)126 public E poll(long timeout, TimeUnit unit) throws InterruptedException { 127 return delegate().poll(timeout, unit); 128 } 129 130 @Override drainTo(Collection<? super E> c)131 public int drainTo(Collection<? super E> c) { 132 return delegate().drainTo(c); 133 } 134 135 @Override drainTo(Collection<? super E> c, int maxElements)136 public int drainTo(Collection<? super E> c, int maxElements) { 137 return delegate().drainTo(c, maxElements); 138 } 139 } 140