• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 java.util.Collection;
20 import java.util.concurrent.BlockingDeque;
21 import java.util.concurrent.TimeUnit;
22 
23 /**
24  * A {@link BlockingDeque} which forwards all its method calls to another {@code BlockingDeque}.
25  * Subclasses should override one or more methods to modify the behavior of the backing deque as
26  * desired per the <a href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
27  *
28  * <p><b>Warning:</b> The methods of {@code ForwardingBlockingDeque} forward
29  * <b>indiscriminately</b> to the methods of the delegate. For example, overriding {@link #add}
30  * alone <b>will not</b> change the behaviour of {@link #offer} which can lead to unexpected
31  * behaviour. In this case, you should override {@code offer} as well, either providing your own
32  * implementation, or delegating to the provided {@code standardOffer} method.
33  *
34  * <p>
35  * The {@code standard} methods are not guaranteed to be thread-safe, even when all of the methods
36  * that they depend on are thread-safe.
37  *
38  * @author Emily Soldal
39  * @since 14.0
40  */
41 public abstract class ForwardingBlockingDeque<E>
42     extends ForwardingDeque<E> implements BlockingDeque<E> {
43 
44   /** Constructor for use by subclasses. */
ForwardingBlockingDeque()45   protected ForwardingBlockingDeque() {}
46 
delegate()47   @Override protected abstract BlockingDeque<E> delegate();
48 
49   @Override
remainingCapacity()50   public int remainingCapacity() {
51     return delegate().remainingCapacity();
52   }
53 
54   @Override
putFirst(E e)55   public void putFirst(E e) throws InterruptedException {
56     delegate().putFirst(e);
57   }
58 
59   @Override
putLast(E e)60   public void putLast(E e) throws InterruptedException {
61     delegate().putLast(e);
62   }
63 
64   @Override
offerFirst(E e, long timeout, TimeUnit unit)65   public boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException {
66     return delegate().offerFirst(e, timeout, unit);
67   }
68 
69   @Override
offerLast(E e, long timeout, TimeUnit unit)70   public boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException {
71     return delegate().offerLast(e, timeout, unit);
72   }
73 
74   @Override
takeFirst()75   public E takeFirst() throws InterruptedException {
76     return delegate().takeFirst();
77   }
78 
79   @Override
takeLast()80   public E takeLast() throws InterruptedException {
81     return delegate().takeLast();
82   }
83 
84   @Override
pollFirst(long timeout, TimeUnit unit)85   public E pollFirst(long timeout, TimeUnit unit) throws InterruptedException {
86     return delegate().pollFirst(timeout, unit);
87   }
88 
89   @Override
pollLast(long timeout, TimeUnit unit)90   public E pollLast(long timeout, TimeUnit unit) throws InterruptedException {
91     return delegate().pollLast(timeout, unit);
92   }
93 
94   @Override
put(E e)95   public void put(E e) throws InterruptedException {
96     delegate().put(e);
97   }
98 
99   @Override
offer(E e, long timeout, TimeUnit unit)100   public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException {
101     return delegate().offer(e, timeout, unit);
102   }
103 
104   @Override
take()105   public E take() throws InterruptedException {
106     return delegate().take();
107   }
108 
109   @Override
poll(long timeout, TimeUnit unit)110   public E poll(long timeout, TimeUnit unit) throws InterruptedException {
111     return delegate().poll(timeout, unit);
112   }
113 
114   @Override
drainTo(Collection<? super E> c)115   public int drainTo(Collection<? super E> c) {
116     return delegate().drainTo(c);
117   }
118 
119   @Override
drainTo(Collection<? super E> c, int maxElements)120   public int drainTo(Collection<? super E> c, int maxElements) {
121     return delegate().drainTo(c, maxElements);
122   }
123 }
124