IDeque Interface

Definition

A linear collection that supports element insertion and removal at both ends.

[Android.Runtime.Register("java/util/Deque", "", "Java.Util.IDequeInvoker")]
[Java.Interop.JavaTypeParameters(new System.String[] { "E" })]
public interface IDeque : IDisposable, Java.Interop.IJavaPeerable, Java.Util.IQueue
[<Android.Runtime.Register("java/util/Deque", "", "Java.Util.IDequeInvoker")>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "E" })>]
type IDeque = interface
    interface IQueue
    interface ICollection
    interface IIterable
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
Derived
Attributes
Implements

Remarks

A linear collection that supports element insertion and removal at both ends. The name deque is short for "double ended queue" and is usually pronounced "deck". Most Deque implementations place no fixed limits on the number of elements they may contain, but this interface supports capacity-restricted deques as well as those with no fixed size limit.

This interface defines methods to access the elements at both ends of the deque. Methods are provided to insert, remove, and examine the element. Each of these methods exists in two forms: one throws an exception if the operation fails, the other returns a special value (either null or false, depending on the operation). The latter form of the insert operation is designed specifically for use with capacity-restricted Deque implementations; in most implementations, insert operations cannot fail.

The twelve methods described above are summarized in the following table:

<table class="striped"> <caption>Summary of Deque methods</caption> <thead> <tr> <td rowspan="2"></td> <th scope="col" colspan="2"> First Element (Head)</th> <th scope="col" colspan="2"> Last Element (Tail)</th> </tr> <tr> <th scope="col" style="font-weight:normal; font-style:italic">Throws exception</th> <th scope="col" style="font-weight:normal; font-style:italic">Special value</th> <th scope="col" style="font-weight:normal; font-style:italic">Throws exception</th> <th scope="col" style="font-weight:normal; font-style:italic">Special value</th> </tr> </thead> <tbody> <tr> <th scope="row">Insert</th> <td>#addFirst(Object) addFirst(e)</td> <td>#offerFirst(Object) offerFirst(e)</td> <td>#addLast(Object) addLast(e)</td> <td>#offerLast(Object) offerLast(e)</td> </tr> <tr> <th scope="row">Remove</th> <td>#removeFirst() removeFirst()</td> <td>#pollFirst() pollFirst()</td> <td>#removeLast() removeLast()</td> <td>#pollLast() pollLast()</td> </tr> <tr> <th scope="row">Examine</th> <td>#getFirst() getFirst()</td> <td>#peekFirst() peekFirst()</td> <td>#getLast() getLast()</td> <td>#peekLast() peekLast()</td> </tr> </tbody> </table>

This interface extends the Queue interface. When a deque is used as a queue, FIFO (First-In-First-Out) behavior results. Elements are added at the end of the deque and removed from the beginning. The methods inherited from the Queue interface are precisely equivalent to Deque methods as indicated in the following table:

<table class="striped"> <caption>Comparison of Queue and Deque methods</caption> <thead> <tr> <th scope="col"> Queue Method</th> <th scope="col"> Equivalent Deque Method</th> </tr> </thead> <tbody> <tr> <th scope="row">#add(Object) add(e)</th> <td>#addLast(Object) addLast(e)</td> </tr> <tr> <th scope="row">#offer(Object) offer(e)</th> <td>#offerLast(Object) offerLast(e)</td> </tr> <tr> <th scope="row">#remove() remove()</th> <td>#removeFirst() removeFirst()</td> </tr> <tr> <th scope="row">#poll() poll()</th> <td>#pollFirst() pollFirst()</td> </tr> <tr> <th scope="row">#element() element()</th> <td>#getFirst() getFirst()</td> </tr> <tr> <th scope="row">#peek() peek()</th> <td>#peekFirst() peekFirst()</td> </tr> </tbody> </table>

Deques can also be used as LIFO (Last-In-First-Out) stacks. This interface should be used in preference to the legacy Stack class. When a deque is used as a stack, elements are pushed and popped from the beginning of the deque. Stack methods are equivalent to Deque methods as indicated in the table below:

<table class="striped"> <caption>Comparison of Stack and Deque methods</caption> <thead> <tr> <th scope="col"> Stack Method</th> <th scope="col"> Equivalent Deque Method</th> </tr> </thead> <tbody> <tr> <th scope="row">#push(Object) push(e)</th> <td>#addFirst(Object) addFirst(e)</td> </tr> <tr> <th scope="row">#pop() pop()</th> <td>#removeFirst() removeFirst()</td> </tr> <tr> <th scope="row">#peek() peek()</th> <td>#getFirst() getFirst()</td> </tr> </tbody> </table>

Note that the #peek peek method works equally well when a deque is used as a queue or a stack; in either case, elements are drawn from the beginning of the deque.

This interface provides two methods to remove interior elements, #removeFirstOccurrence removeFirstOccurrence and #removeLastOccurrence removeLastOccurrence.

Unlike the List interface, this interface does not provide support for indexed access to elements.

While Deque implementations are not strictly required to prohibit the insertion of null elements, they are strongly encouraged to do so. Users of any Deque implementations that do allow null elements are strongly encouraged not to take advantage of the ability to insert nulls. This is so because null is used as a special return value by various methods to indicate that the deque is empty.

Deque implementations generally do not define element-based versions of the equals and hashCode methods, but instead inherit the identity-based versions from class Object.

Added in 1.6.

Java documentation for java.util.Deque.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Properties

First

Retrieves, but does not remove, the first element of this deque.

Handle

Gets the JNI value of the underlying Android object.

(Inherited from IJavaObject)
IsEmpty

Returns if this Collection contains no elements.

(Inherited from ICollection)
JniIdentityHashCode

Returns the value of java.lang.System.identityHashCode() for the wrapped instance.

(Inherited from IJavaPeerable)
JniManagedPeerState

State of the managed peer.

(Inherited from IJavaPeerable)
JniPeerMembers

Member access and invocation support.

(Inherited from IJavaPeerable)
Last

Retrieves, but does not remove, the last element of this deque.

PeerReference

Returns a JniObjectReference of the wrapped Java object instance.

(Inherited from IJavaPeerable)

Methods

Add(Object)

Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque) if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.

AddAll(ICollection)

Adds all of the elements in the specified collection to this collection (optional operation).

(Inherited from ICollection)
AddFirst(Object)

Inserts the specified element at the front of this deque if it is possible to do so immediately without violating capacity restrictions, throwing an IllegalStateException if no space is currently available.

AddLast(Object)

Inserts the specified element at the end of this deque if it is possible to do so immediately without violating capacity restrictions, throwing an IllegalStateException if no space is currently available.

Clear()

Removes all of the elements from this collection (optional operation).

(Inherited from ICollection)
Contains(Object)

Returns true if this deque contains the specified element.

ContainsAll(ICollection)

Returns true if this collection contains all of the elements in the specified collection.

(Inherited from ICollection)
DescendingIterator()

Returns an iterator over the elements in this deque in reverse sequential order.

Disposed()

Called when the instance has been disposed.

(Inherited from IJavaPeerable)
DisposeUnlessReferenced()

If there are no outstanding references to this instance, then calls Dispose(); otherwise, does nothing.

(Inherited from IJavaPeerable)
Element()

Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque).

Equals(Object)

Compares the specified object with this collection for equality.

(Inherited from ICollection)
Finalized()

Called when the instance has been finalized.

(Inherited from IJavaPeerable)
ForEach(IConsumer)

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.

(Inherited from IIterable)
GetHashCode()

Returns the hash code value for this collection.

(Inherited from ICollection)
Iterator()

Returns an iterator over the elements in this deque in proper sequence.

Offer(Object)

Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque) if it is possible to do so immediately without violating capacity restrictions, returning true upon success and false if no space is currently available.

OfferFirst(Object)

Inserts the specified element at the front of this deque unless it would violate capacity restrictions.

OfferLast(Object)

Inserts the specified element at the end of this deque unless it would violate capacity restrictions.

Peek()

Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque), or returns null if this deque is empty.

PeekFirst()

Retrieves, but does not remove, the first element of this deque, or returns null if this deque is empty.

PeekLast()

Retrieves, but does not remove, the last element of this deque, or returns null if this deque is empty.

Poll()

Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque), or returns null if this deque is empty.

PollFirst()

Retrieves and removes the first element of this deque, or returns null if this deque is empty.

PollLast()

Retrieves and removes the last element of this deque, or returns null if this deque is empty.

Pop()

Pops an element from the stack represented by this deque.

Push(Object)

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 an IllegalStateException if no space is currently available.

Remove()

Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque).

Remove(Object)

Removes the first occurrence of the specified element from this deque.

RemoveAll(ICollection)

Removes all of this collection's elements that are also contained in the specified collection (optional operation).

(Inherited from ICollection)
RemoveFirst()

Retrieves and removes the first element of this deque.

RemoveFirstOccurrence(Object)

Removes the first occurrence of the specified element from this deque.

RemoveIf(IPredicate)

Removes all of the elements of this collection that satisfy the given predicate.

(Inherited from ICollection)
RemoveLast()

Retrieves and removes the last element of this deque.

RemoveLastOccurrence(Object)

Removes the last occurrence of the specified element from this deque.

RetainAll(ICollection)

Retains only the elements in this collection that are contained in the specified collection (optional operation).

(Inherited from ICollection)
SetJniIdentityHashCode(Int32)

Set the value returned by JniIdentityHashCode.

(Inherited from IJavaPeerable)
SetJniManagedPeerState(JniManagedPeerStates) (Inherited from IJavaPeerable)
SetPeerReference(JniObjectReference)

Set the value returned by PeerReference.

(Inherited from IJavaPeerable)
Size()

Returns the number of elements in this deque.

Spliterator()

Creates a Spliterator over the elements described by this Iterable.

(Inherited from IIterable)
ToArray()

Returns an array containing all of the elements in this collection.

(Inherited from ICollection)
ToArray(IIntFunction)

Returns an array containing all of the elements in this collection, using the provided generator function to allocate the returned array.

(Inherited from ICollection)
ToArray(Object[])

Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.

(Inherited from ICollection)
UnregisterFromRuntime()

Unregister this instance so that the runtime will not return it from future Java.Interop.JniRuntime+JniValueManager.PeekValue invocations.

(Inherited from IJavaPeerable)

Explicit Interface Implementations

IIterable.Spliterator()

Creates a Spliterator over the elements in this collection.

(Inherited from ICollection)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)
ToEnumerable(IIterable)
ToEnumerable<T>(IIterable)

Applies to