Class ForwardingBlockingDeque<E>
- java.lang.Object
-
- com.google.common.collect.ForwardingObject
-
- com.google.common.collect.ForwardingCollection<E>
-
- com.google.common.collect.ForwardingQueue<E>
-
- com.google.common.collect.ForwardingDeque<E>
-
- com.google.common.util.concurrent.ForwardingBlockingDeque<E>
-
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,BlockingDeque<E>
,BlockingQueue<E>
,Deque<E>
,Queue<E>
@GwtIncompatible public abstract class ForwardingBlockingDeque<E> extends ForwardingDeque<E> implements BlockingDeque<E>
ABlockingDeque
which forwards all its method calls to anotherBlockingDeque
. Subclasses should override one or more methods to modify the behavior of the backing deque as desired per the decorator pattern.Warning: The methods of
ForwardingBlockingDeque
forward indiscriminately to the methods of the delegate. For example, overridingForwardingCollection.add(E)
alone will not change the behaviour ofoffer(E, long, java.util.concurrent.TimeUnit)
which can lead to unexpected behaviour. In this case, you should overrideoffer
as well, either providing your own implementation, or delegating to the providedstandardOffer
method.default
method warning: This class does not forward calls todefault
methods. Instead, it inherits their default implementations. When those implementations invoke methods, they invoke methods on theForwardingBlockingDeque
.The
standard
methods are not guaranteed to be thread-safe, even when all of the methods that they depend on are thread-safe.- Since:
- 21.0 (since 14.0 as
ForwardingBlockingDeque
) - Author:
- Emily Soldal
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ForwardingBlockingDeque()
Constructor for use by subclasses.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract BlockingDeque<E>
delegate()
Returns the backing delegate instance that methods are forwarded to.int
drainTo(Collection<? super E> c)
int
drainTo(Collection<? super E> c, int maxElements)
boolean
offer(E e, long timeout, TimeUnit unit)
boolean
offerFirst(E e, long timeout, TimeUnit unit)
boolean
offerLast(E e, long timeout, TimeUnit unit)
E
poll(long timeout, TimeUnit unit)
E
pollFirst(long timeout, TimeUnit unit)
E
pollLast(long timeout, TimeUnit unit)
void
put(E e)
void
putFirst(E e)
void
putLast(E e)
int
remainingCapacity()
E
take()
E
takeFirst()
E
takeLast()
-
Methods inherited from class com.google.common.collect.ForwardingDeque
addFirst, addLast, descendingIterator, getFirst, getLast, offerFirst, offerLast, peekFirst, peekLast, pollFirst, pollLast, pop, push, removeFirst, removeFirstOccurrence, removeLast, removeLastOccurrence
-
Methods inherited from class com.google.common.collect.ForwardingQueue
element, offer, peek, poll, remove, standardOffer, standardPeek, standardPoll
-
Methods inherited from class com.google.common.collect.ForwardingCollection
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, standardAddAll, standardClear, standardContains, standardContainsAll, standardIsEmpty, standardRemove, standardRemoveAll, standardRetainAll, standardToArray, standardToArray, standardToString, toArray, toArray
-
Methods inherited from class com.google.common.collect.ForwardingObject
toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.concurrent.BlockingDeque
add, addFirst, addLast, contains, element, iterator, offer, offerFirst, offerLast, peek, poll, push, remove, remove, removeFirstOccurrence, removeLastOccurrence, size
-
Methods inherited from interface java.util.Collection
clear, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArray
-
-
-
-
Constructor Detail
-
ForwardingBlockingDeque
protected ForwardingBlockingDeque()
Constructor for use by subclasses.
-
-
Method Detail
-
delegate
protected abstract BlockingDeque<E> delegate()
Description copied from class:ForwardingObject
Returns the backing delegate instance that methods are forwarded to. Abstract subclasses generally override this method with an abstract method that has a more specific return type, such asForwardingSet.delegate()
. Concrete subclasses override this method to supply the instance being decorated.- Specified by:
delegate
in classForwardingDeque<E>
-
remainingCapacity
public int remainingCapacity()
- Specified by:
remainingCapacity
in interfaceBlockingQueue<E>
-
putFirst
public void putFirst(E e) throws InterruptedException
- Specified by:
putFirst
in interfaceBlockingDeque<E>
- Throws:
InterruptedException
-
putLast
public void putLast(E e) throws InterruptedException
- Specified by:
putLast
in interfaceBlockingDeque<E>
- Throws:
InterruptedException
-
offerFirst
public boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
offerFirst
in interfaceBlockingDeque<E>
- Throws:
InterruptedException
-
offerLast
public boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
offerLast
in interfaceBlockingDeque<E>
- Throws:
InterruptedException
-
takeFirst
public E takeFirst() throws InterruptedException
- Specified by:
takeFirst
in interfaceBlockingDeque<E>
- Throws:
InterruptedException
-
takeLast
public E takeLast() throws InterruptedException
- Specified by:
takeLast
in interfaceBlockingDeque<E>
- Throws:
InterruptedException
-
pollFirst
@CheckForNull public E pollFirst(long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
pollFirst
in interfaceBlockingDeque<E>
- Throws:
InterruptedException
-
pollLast
@CheckForNull public E pollLast(long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
pollLast
in interfaceBlockingDeque<E>
- Throws:
InterruptedException
-
put
public void put(E e) throws InterruptedException
- Specified by:
put
in interfaceBlockingDeque<E>
- Specified by:
put
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
offer
public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
offer
in interfaceBlockingDeque<E>
- Specified by:
offer
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
take
public E take() throws InterruptedException
- Specified by:
take
in interfaceBlockingDeque<E>
- Specified by:
take
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
poll
@CheckForNull public E poll(long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
poll
in interfaceBlockingDeque<E>
- Specified by:
poll
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
drainTo
public int drainTo(Collection<? super E> c)
- Specified by:
drainTo
in interfaceBlockingQueue<E>
-
drainTo
public int drainTo(Collection<? super E> c, int maxElements)
- Specified by:
drainTo
in interfaceBlockingQueue<E>
-
-