Top Description Constructors Methods
com.google.common.collect

public abstract Class ForwardingQueue<E extends @Nullable Object>

extends ForwardingCollection<E extends @Nullable Object>
implements Queue<E extends @Nullable Object>
Class Inheritance
All Implemented Interfaces
java.util.Queue, java.util.Collection, java.lang.Iterable
Known Direct Subclasses
com.google.common.util.concurrent.ForwardingBlockingQueue, com.google.common.collect.EvictingQueue, com.google.common.collect.ForwardingDeque
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Imports
com.google.common.annotations.GwtCompatible, com.google.errorprone.annotations.CanIgnoreReturnValue, java.util.NoSuchElementException, .Queue, javax.annotation.CheckForNull, org.checkerframework.checker.nullness.qual.Nullable

A queue which forwards all its method calls to another queue. Subclasses should override one or more methods to modify the behavior of the backing queue as desired per the decorator pattern.

Warning

The methods of ForwardingQueue forward indiscriminately to the methods of the delegate. For example, overriding add alone will not change the behavior of offer which can lead to unexpected behavior. In this case, you should override offer as well, either providing your own implementation, or delegating to the provided standardOffer method.

default method warning: This class does not forward calls to default methods. Instead, it inherits their default implementations. When those implementations invoke methods, they invoke methods on the ForwardingQueue.

The standard methods are not guaranteed to be thread-safe, even when all of the methods that they depend on are thread-safe.

Authors
Mike Bostock, Louis Wasserman
Since
2.0

Constructor Summary

AccessConstructor and Description
protected
ForwardingQueue()

Constructor for use by subclasses.

Method Summary

Modifier and TypeMethod and Description
protected abstract Queue<E>
delegate()

Implements abstract com.google.common.collect.ForwardingCollection.delegate.

Returns the backing delegate instance that methods are forwarded to.
public E
element()

Implements java.util.Queue.element.

Retrieves, but does not remove, the head of this queue.
public boolean
offer(E
the element to add
o
)

Implements java.util.Queue.offer.

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions.
public E
peek()

Implements java.util.Queue.peek.

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.
public E
poll()

Implements java.util.Queue.poll.

Retrieves and removes the head of this queue, or returns null if this queue is empty.
public E
remove()

Implements java.util.Queue.remove.

Retrieves and removes the head of this queue.
protected boolean
standardOffer(E e)

A sensible definition of offer in terms of add.

protected E
standardPeek()

A sensible definition of peek in terms of element.

protected E
standardPoll()

A sensible definition of poll in terms of remove.

Inherited from com.google.common.collect.ForwardingCollection:
addaddAllclearcontainscontainsAllisEmptyiteratorremoveremoveAllretainAllsizestandardAddAllstandardClearstandardContainsstandardContainsAllstandardIsEmptystandardRemovestandardRemoveAllstandardRetainAllstandardToArraystandardToArraystandardToStringtoArraytoArray

Constructor Detail

ForwardingQueueback to summary
protected ForwardingQueue()

Constructor for use by subclasses.

Method Detail

delegateback to summary
protected abstract Queue<E> delegate()

Implements abstract com.google.common.collect.ForwardingCollection.delegate.

Doc from com.google.common.collect.ForwardingObject.delegate.

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 as ForwardingSet#delegate. Concrete subclasses override this method to supply the instance being decorated.

Annotations
@Override
elementback to summary
public E element()

Implements java.util.Queue.element.

Doc from java.util.Queue.element.

Retrieves, but does not remove, the head of this queue. This method differs from peek only in that it throws an exception if this queue is empty.

Returns:E

the head of this queue

Annotations
@Override
@ParametricNullness
offerback to summary
public boolean offer(E o)

Implements java.util.Queue.offer.

Doc from java.util.Queue.offer.

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions. When using a capacity-restricted queue, this method is generally preferable to add, which can fail to insert an element only by throwing an exception.

Parameters
o:E

the element to add

Returns:boolean

true if the element was added to this queue, else false

Annotations
@CanIgnoreReturnValue
@Override
peekback to summary
public E peek()

Implements java.util.Queue.peek.

Doc from java.util.Queue.peek.

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.

Returns:E

the head of this queue, or null if this queue is empty

Annotations
@Override
@CheckForNull
pollback to summary
public E poll()

Implements java.util.Queue.poll.

Doc from java.util.Queue.poll.

Retrieves and removes the head of this queue, or returns null if this queue is empty.

Returns:E

the head of this queue, or null if this queue is empty

Annotations
@CanIgnoreReturnValue
@Override
@CheckForNull
removeback to summary
public E remove()

Implements java.util.Queue.remove.

Doc from java.util.Queue.remove.

Retrieves and removes the head of this queue. This method differs from poll() only in that it throws an exception if this queue is empty.

Returns:E

the head of this queue

Annotations
@CanIgnoreReturnValue
@Override
@ParametricNullness
standardOfferback to summary
protected boolean standardOffer(E e)

A sensible definition of offer in terms of add. If you override add, you may wish to override offer to forward to this implementation.

Since
7.0
standardPeekback to summary
protected E standardPeek()

A sensible definition of peek in terms of element. If you override element, you may wish to override peek to forward to this implementation.

Annotations
@CheckForNull
Since
7.0
standardPollback to summary
protected E standardPoll()

A sensible definition of poll in terms of remove. If you override remove, you may wish to override poll to forward to this implementation.

Annotations
@CheckForNull
Since
7.0