Package com.google.common.collect
Class ForwardingDeque<E>
-
- com.google.common.collect.ForwardingObject
-
- com.google.common.collect.ForwardingCollection<E>
-
- com.google.common.collect.ForwardingQueue<E>
-
- com.google.common.collect.ForwardingDeque<E>
-
- All Implemented Interfaces:
<E>
,<E>
,<E>
,<E>
- Direct Known Subclasses:
ForwardingBlockingDeque
,ForwardingBlockingDeque
@GwtIncompatible public abstract class ForwardingDeque<E> extends ForwardingQueue<E> implements <E>
A deque which forwards all its method calls to another deque. Subclasses should override one or more methods to modify the behavior of the backing deque as desired per the .Warning: The methods of
ForwardingDeque
forward indiscriminately to the methods of the delegate. For example, overridingForwardingCollection.add(E)
alone will not change the behavior ofForwardingQueue.offer(E)
which can lead to unexpected behavior. In this case, you should overrideoffer
as well.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 theForwardingDeque
.- Since:
- 12.0
- Author:
- Kurt Alfred Kluever
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ForwardingDeque()
Constructor for use by subclasses.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addFirst(E e)
Inserts the specified element at the front of this deque if it is possible to do so immediately without violating capacity restrictions, throwing anIllegalStateException
if no space is currently available.void
addLast(E e)
Inserts the specified element at the end of this deque if it is possible to do so immediately without violating capacity restrictions, throwing anIllegalStateException
if no space is currently available.protected abstract <E>
delegate()
Returns the backing delegate instance that methods are forwarded to.<E>
descendingIterator()
Returns an iterator over the elements in this deque in reverse sequential order.E
getFirst()
Retrieves, but does not remove, the first element of this deque.E
getLast()
Retrieves, but does not remove, the last element of this deque.boolean
offerFirst(E e)
Inserts the specified element at the front of this deque unless it would violate capacity restrictions.boolean
offerLast(E e)
Inserts the specified element at the end of this deque unless it would violate capacity restrictions.E
peekFirst()
Retrieves, but does not remove, the first element of this deque, or returnsnull
if this deque is empty.E
peekLast()
Retrieves, but does not remove, the last element of this deque, or returnsnull
if this deque is empty.E
pollFirst()
Retrieves and removes the first element of this deque, or returnsnull
if this deque is empty.E
pollLast()
Retrieves and removes the last element of this deque, or returnsnull
if this deque is empty.E
pop()
Pops an element from the stack represented by this deque.void
push(E e)
Pushes an element onto the stack represented by this deque (in other words, at the head of this deque) if it is possible to do so immediately without violating capacity restrictions, throwing anIllegalStateException
if no space is currently available.E
removeFirst()
Retrieves and removes the first element of this deque.boolean
o)
Removes the first occurrence of the specified element from this deque.E
removeLast()
Retrieves and removes the last element of this deque.boolean
o)
Removes the last occurrence of the specified element from this deque.-
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
-
-
-
-
Constructor Detail
-
ForwardingDeque
protected ForwardingDeque()
Constructor for use by subclasses.
-
-
Method Detail
-
delegate
protected abstract <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 classForwardingQueue<E>
-
addFirst
public void addFirst(E e)
Description copied from interface:Inserts the specified element at the front of this deque if it is possible to do so immediately without violating capacity restrictions, throwing anIllegalStateException
if no space is currently available. When using a capacity-restricted deque, it is generally preferable to use method .- Specified by:
in interface
<E>
- Parameters:
e
- the element to add
-
addLast
public void addLast(E e)
Description copied from interface:Inserts the specified element at the end of this deque if it is possible to do so immediately without violating capacity restrictions, throwing anIllegalStateException
if no space is currently available. When using a capacity-restricted deque, it is generally preferable to use method .This method is equivalent to .
- Specified by:
in interface
<E>
- Parameters:
e
- the element to add
-
descendingIterator
public <E> descendingIterator()
Description copied from interface:Returns an iterator over the elements in this deque in reverse sequential order. The elements will be returned in order from last (tail) to first (head).- Specified by:
in interface
<E>
- Returns:
- an iterator over the elements in this deque in reverse sequence
-
getFirst
public E getFirst()
Description copied from interface:Retrieves, but does not remove, the first element of this deque. This method differs from only in that it throws an exception if this deque is empty.- Specified by:
in interface
<E>
- Returns:
- the head of this deque
-
getLast
public E getLast()
Description copied from interface:Retrieves, but does not remove, the last element of this deque. This method differs from only in that it throws an exception if this deque is empty.- Specified by:
in interface
<E>
- Returns:
- the tail of this deque
-
offerFirst
public boolean offerFirst(E e)
Description copied from interface:Inserts the specified element at the front of this deque unless it would violate capacity restrictions. When using a capacity-restricted deque, this method is generally preferable to the method, which can fail to insert an element only by throwing an exception.- Specified by:
in interface
<E>
- Parameters:
e
- the element to add- Returns:
true
if the element was added to this deque, elsefalse
-
offerLast
public boolean offerLast(E e)
Description copied from interface:Inserts the specified element at the end of this deque unless it would violate capacity restrictions. When using a capacity-restricted deque, this method is generally preferable to the method, which can fail to insert an element only by throwing an exception.- Specified by:
in interface
<E>
- Parameters:
e
- the element to add- Returns:
true
if the element was added to this deque, elsefalse
-
peekFirst
public E peekFirst()
Description copied from interface:Retrieves, but does not remove, the first element of this deque, or returnsnull
if this deque is empty.- Specified by:
in interface
<E>
- Returns:
- the head of this deque, or
null
if this deque is empty
-
peekLast
public E peekLast()
Description copied from interface:Retrieves, but does not remove, the last element of this deque, or returnsnull
if this deque is empty.- Specified by:
in interface
<E>
- Returns:
- the tail of this deque, or
null
if this deque is empty
-
pollFirst
public E pollFirst()
Description copied from interface:Retrieves and removes the first element of this deque, or returnsnull
if this deque is empty.- Specified by:
in interface
<E>
- Returns:
- the head of this deque, or
null
if this deque is empty
-
pollLast
public E pollLast()
Description copied from interface:Retrieves and removes the last element of this deque, or returnsnull
if this deque is empty.- Specified by:
in interface
<E>
- Returns:
- the tail of this deque, or
null
if this deque is empty
-
pop
public E pop()
Description copied from interface:Pops an element from the stack represented by this deque. In other words, removes and returns the first element of this deque.This method is equivalent to .
- Specified by:
in interface
<E>
- Returns:
- the element at the front of this deque (which is the top of the stack represented by this deque)
-
push
public void push(E e)
Description copied from interface:Pushes an element onto the stack represented by this deque (in other words, at the head of this deque) if it is possible to do so immediately without violating capacity restrictions, throwing anIllegalStateException
if no space is currently available.This method is equivalent to .
- Specified by:
in interface
<E>
- Parameters:
e
- the element to push
-
removeFirst
public E removeFirst()
Description copied from interface:Retrieves and removes the first element of this deque. This method differs from only in that it throws an exception if this deque is empty.- Specified by:
in interface
<E>
- Returns:
- the head of this deque
-
removeLast
public E removeLast()
Description copied from interface:Retrieves and removes the last element of this deque. This method differs from only in that it throws an exception if this deque is empty.- Specified by:
in interface
<E>
- Returns:
- the tail of this deque
-
removeFirstOccurrence
public boolean o)
Description copied from interface:Removes the first occurrence of the specified element from this deque. If the deque does not contain the element, it is unchanged. More formally, removes the first elemente
such thatObjects.equals(o, e)
(if such an element exists). Returnstrue
if this deque contained the specified element (or equivalently, if this deque changed as a result of the call).- Specified by:
in interface
<E>
- Parameters:
o
- element to be removed from this deque, if present- Returns:
true
if an element was removed as a result of this call
-
removeLastOccurrence
public boolean o)
Description copied from interface:Removes the last occurrence of the specified element from this deque. If the deque does not contain the element, it is unchanged. More formally, removes the last elemente
such thatObjects.equals(o, e)
(if such an element exists). Returnstrue
if this deque contained the specified element (or equivalently, if this deque changed as a result of the call).- Specified by:
in interface
<E>
- Parameters:
o
- element to be removed from this deque, if present- Returns:
true
if an element was removed as a result of this call
-
-