Package com.google.common.collect
Class ForwardingDeque<E extends @Nullable Object>
- 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>
-
- All Implemented Interfaces:
Iterable<E>,Collection<E>,Deque<E>,Queue<E>
- Direct Known Subclasses:
ForwardingBlockingDeque,ForwardingBlockingDeque
@GwtIncompatible public abstract class ForwardingDeque<E extends @Nullable Object> extends ForwardingQueue<E> implements Deque<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 decorator pattern.Warning: The methods of
ForwardingDequeforward 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 overrideofferas well.defaultmethod warning: This class does not forward calls todefaultmethods. 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 protectedForwardingDeque()Constructor for use by subclasses.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddFirst(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 anIllegalStateExceptionif no space is currently available.voidaddLast(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 anIllegalStateExceptionif no space is currently available.protected abstract Deque<E>delegate()Returns the backing delegate instance that methods are forwarded to.Iterator<E>descendingIterator()Returns an iterator over the elements in this deque in reverse sequential order.EgetFirst()Retrieves, but does not remove, the first element of this deque.EgetLast()Retrieves, but does not remove, the last element of this deque.booleanofferFirst(E e)Inserts the specified element at the front of this deque unless it would violate capacity restrictions.booleanofferLast(E e)Inserts the specified element at the end of this deque unless it would violate capacity restrictions.EpeekFirst()Retrieves, but does not remove, the first element of this deque, or returnsnullif this deque is empty.EpeekLast()Retrieves, but does not remove, the last element of this deque, or returnsnullif this deque is empty.EpollFirst()Retrieves and removes the first element of this deque, or returnsnullif this deque is empty.EpollLast()Retrieves and removes the last element of this deque, or returnsnullif this deque is empty.Epop()Pops an element from the stack represented by this deque.voidpush(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 anIllegalStateExceptionif no space is currently available.EremoveFirst()Retrieves and removes the first element of this deque.booleanremoveFirstOccurrence(Object o)Removes the first occurrence of the specified element from this deque.EremoveLast()Retrieves and removes the last element of this deque.booleanremoveLastOccurrence(Object 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
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
clear, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArray
-
-
-
-
Constructor Detail
-
ForwardingDeque
protected ForwardingDeque()
Constructor for use by subclasses.
-
-
Method Detail
-
delegate
protected abstract Deque<E> delegate()
Description copied from class:ForwardingObjectReturns 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:
delegatein classForwardingQueue<E extends @Nullable Object>
-
addFirst
public void addFirst(E e)
Description copied from interface:java.util.DequeInserts the specified element at the front of this deque if it is possible to do so immediately without violating capacity restrictions, throwing anIllegalStateExceptionif no space is currently available. When using a capacity-restricted deque, it is generally preferable to use methodDeque.offerFirst(E).
-
addLast
public void addLast(E e)
Description copied from interface:java.util.DequeInserts the specified element at the end of this deque if it is possible to do so immediately without violating capacity restrictions, throwing anIllegalStateExceptionif no space is currently available. When using a capacity-restricted deque, it is generally preferable to use methodDeque.offerLast(E).This method is equivalent to
Deque.add(E).
-
descendingIterator
public Iterator<E> descendingIterator()
Description copied from interface:java.util.DequeReturns 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:
descendingIteratorin interfaceDeque<E extends @Nullable Object>- Returns:
- an iterator over the elements in this deque in reverse sequence
-
getFirst
public E getFirst()
Description copied from interface:java.util.DequeRetrieves, but does not remove, the first element of this deque. This method differs frompeekFirstonly in that it throws an exception if this deque is empty.
-
getLast
public E getLast()
Description copied from interface:java.util.DequeRetrieves, but does not remove, the last element of this deque. This method differs frompeekLastonly in that it throws an exception if this deque is empty.
-
offerFirst
@CanIgnoreReturnValue public boolean offerFirst(E e)
Description copied from interface:java.util.DequeInserts 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 theDeque.addFirst(E)method, which can fail to insert an element only by throwing an exception.- Specified by:
offerFirstin interfaceDeque<E extends @Nullable Object>- Parameters:
e- the element to add- Returns:
trueif the element was added to this deque, elsefalse
-
offerLast
@CanIgnoreReturnValue public boolean offerLast(E e)
Description copied from interface:java.util.DequeInserts 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 theDeque.addLast(E)method, which can fail to insert an element only by throwing an exception.
-
peekFirst
@CheckForNull public E peekFirst()
Description copied from interface:java.util.DequeRetrieves, but does not remove, the first element of this deque, or returnsnullif this deque is empty.
-
peekLast
@CheckForNull public E peekLast()
Description copied from interface:java.util.DequeRetrieves, but does not remove, the last element of this deque, or returnsnullif this deque is empty.
-
pollFirst
@CanIgnoreReturnValue @CheckForNull public E pollFirst()
Description copied from interface:java.util.DequeRetrieves and removes the first element of this deque, or returnsnullif this deque is empty.
-
pollLast
@CanIgnoreReturnValue @CheckForNull public E pollLast()
Description copied from interface:java.util.DequeRetrieves and removes the last element of this deque, or returnsnullif this deque is empty.
-
pop
@CanIgnoreReturnValue public E pop()
Description copied from interface:java.util.DequePops 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
Deque.removeFirst().
-
push
public void push(E e)
Description copied from interface:java.util.DequePushes 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 anIllegalStateExceptionif no space is currently available.This method is equivalent to
Deque.addFirst(E).
-
removeFirst
@CanIgnoreReturnValue public E removeFirst()
Description copied from interface:java.util.DequeRetrieves and removes the first element of this deque. This method differs frompollFirstonly in that it throws an exception if this deque is empty.- Specified by:
removeFirstin interfaceDeque<E extends @Nullable Object>- Returns:
- the head of this deque
-
removeLast
@CanIgnoreReturnValue public E removeLast()
Description copied from interface:java.util.DequeRetrieves and removes the last element of this deque. This method differs frompollLastonly in that it throws an exception if this deque is empty.- Specified by:
removeLastin interfaceDeque<E extends @Nullable Object>- Returns:
- the tail of this deque
-
removeFirstOccurrence
@CanIgnoreReturnValue public boolean removeFirstOccurrence(@CheckForNull Object o)
Description copied from interface:java.util.DequeRemoves 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 elementesuch thatObjects.equals(o, e)(if such an element exists). Returnstrueif this deque contained the specified element (or equivalently, if this deque changed as a result of the call).- Specified by:
removeFirstOccurrencein interfaceDeque<E extends @Nullable Object>- Parameters:
o- element to be removed from this deque, if present- Returns:
trueif an element was removed as a result of this call
-
removeLastOccurrence
@CanIgnoreReturnValue public boolean removeLastOccurrence(@CheckForNull Object o)
Description copied from interface:java.util.DequeRemoves 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 elementesuch thatObjects.equals(o, e)(if such an element exists). Returnstrueif this deque contained the specified element (or equivalently, if this deque changed as a result of the call).- Specified by:
removeLastOccurrencein interfaceDeque<E extends @Nullable Object>- Parameters:
o- element to be removed from this deque, if present- Returns:
trueif an element was removed as a result of this call
-
-