jaroslav@1890: /* jaroslav@1890: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jaroslav@1890: * jaroslav@1890: * This code is free software; you can redistribute it and/or modify it jaroslav@1890: * under the terms of the GNU General Public License version 2 only, as jaroslav@1890: * published by the Free Software Foundation. Oracle designates this jaroslav@1890: * particular file as subject to the "Classpath" exception as provided jaroslav@1890: * by Oracle in the LICENSE file that accompanied this code. jaroslav@1890: * jaroslav@1890: * This code is distributed in the hope that it will be useful, but WITHOUT jaroslav@1890: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jaroslav@1890: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jaroslav@1890: * version 2 for more details (a copy is included in the LICENSE file that jaroslav@1890: * accompanied this code). jaroslav@1890: * jaroslav@1890: * You should have received a copy of the GNU General Public License version jaroslav@1890: * 2 along with this work; if not, write to the Free Software Foundation, jaroslav@1890: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jaroslav@1890: * jaroslav@1890: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jaroslav@1890: * or visit www.oracle.com if you need additional information or have any jaroslav@1890: * questions. jaroslav@1890: */ jaroslav@1890: jaroslav@1890: /* jaroslav@1890: * This file is available under and governed by the GNU General Public jaroslav@1890: * License version 2 only, as published by the Free Software Foundation. jaroslav@1890: * However, the following notice accompanied the original version of this jaroslav@1890: * file: jaroslav@1890: * jaroslav@1890: * Written by Doug Lea with assistance from members of JCP JSR-166 jaroslav@1890: * Expert Group and released to the public domain, as explained at jaroslav@1890: * http://creativecommons.org/publicdomain/zero/1.0/ jaroslav@1890: */ jaroslav@1890: jaroslav@1890: package java.util.concurrent; jaroslav@1890: import java.util.*; jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * A {@link Deque} that additionally supports blocking operations that wait jaroslav@1890: * for the deque to become non-empty when retrieving an element, and wait for jaroslav@1890: * space to become available in the deque when storing an element. jaroslav@1890: * jaroslav@1890: *

BlockingDeque methods come in four forms, with different ways jaroslav@1890: * of handling operations that cannot be satisfied immediately, but may be jaroslav@1890: * satisfied at some point in the future: jaroslav@1890: * one throws an exception, the second returns a special value (either jaroslav@1890: * null or false, depending on the operation), the third jaroslav@1890: * blocks the current thread indefinitely until the operation can succeed, jaroslav@1890: * and the fourth blocks for only a given maximum time limit before giving jaroslav@1890: * up. These methods are summarized in the following table: jaroslav@1890: * jaroslav@1890: *

jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: *
First Element (Head)
Throws exceptionSpecial valueBlocksTimes out
Insert{@link #addFirst addFirst(e)}{@link #offerFirst(Object) offerFirst(e)}{@link #putFirst putFirst(e)}{@link #offerFirst(Object, long, TimeUnit) offerFirst(e, time, unit)}
Remove{@link #removeFirst removeFirst()}{@link #pollFirst pollFirst()}{@link #takeFirst takeFirst()}{@link #pollFirst(long, TimeUnit) pollFirst(time, unit)}
Examine{@link #getFirst getFirst()}{@link #peekFirst peekFirst()}not applicablenot applicable
Last Element (Tail)
Throws exceptionSpecial valueBlocksTimes out
Insert{@link #addLast addLast(e)}{@link #offerLast(Object) offerLast(e)}{@link #putLast putLast(e)}{@link #offerLast(Object, long, TimeUnit) offerLast(e, time, unit)}
Remove{@link #removeLast() removeLast()}{@link #pollLast() pollLast()}{@link #takeLast takeLast()}{@link #pollLast(long, TimeUnit) pollLast(time, unit)}
Examine{@link #getLast getLast()}{@link #peekLast peekLast()}not applicablenot applicable
jaroslav@1890: * jaroslav@1890: *

Like any {@link BlockingQueue}, a BlockingDeque is thread safe, jaroslav@1890: * does not permit null elements, and may (or may not) be jaroslav@1890: * capacity-constrained. jaroslav@1890: * jaroslav@1890: *

A BlockingDeque implementation may be used directly as a FIFO jaroslav@1890: * BlockingQueue. The methods inherited from the jaroslav@1890: * BlockingQueue interface are precisely equivalent to jaroslav@1890: * BlockingDeque methods as indicated in the following table: jaroslav@1890: * jaroslav@1890: *

jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: * jaroslav@1890: *
BlockingQueue Method Equivalent BlockingDeque Method
Insert
{@link #add(Object) add(e)}{@link #addLast(Object) addLast(e)}
{@link #offer(Object) offer(e)}{@link #offerLast(Object) offerLast(e)}
{@link #put(Object) put(e)}{@link #putLast(Object) putLast(e)}
{@link #offer(Object, long, TimeUnit) offer(e, time, unit)}{@link #offerLast(Object, long, TimeUnit) offerLast(e, time, unit)}
Remove
{@link #remove() remove()}{@link #removeFirst() removeFirst()}
{@link #poll() poll()}{@link #pollFirst() pollFirst()}
{@link #take() take()}{@link #takeFirst() takeFirst()}
{@link #poll(long, TimeUnit) poll(time, unit)}{@link #pollFirst(long, TimeUnit) pollFirst(time, unit)}
Examine
{@link #element() element()}{@link #getFirst() getFirst()}
{@link #peek() peek()}{@link #peekFirst() peekFirst()}
jaroslav@1890: * jaroslav@1890: *

Memory consistency effects: As with other concurrent jaroslav@1890: * collections, actions in a thread prior to placing an object into a jaroslav@1890: * {@code BlockingDeque} jaroslav@1890: * happen-before jaroslav@1890: * actions subsequent to the access or removal of that element from jaroslav@1890: * the {@code BlockingDeque} in another thread. jaroslav@1890: * jaroslav@1890: *

This interface is a member of the jaroslav@1890: * jaroslav@1890: * Java Collections Framework. jaroslav@1890: * jaroslav@1890: * @since 1.6 jaroslav@1890: * @author Doug Lea jaroslav@1890: * @param the type of elements held in this collection jaroslav@1890: */ jaroslav@1890: public interface BlockingDeque extends BlockingQueue, Deque { jaroslav@1890: /* jaroslav@1890: * We have "diamond" multiple interface inheritance here, and that jaroslav@1890: * introduces ambiguities. Methods might end up with different jaroslav@1890: * specs depending on the branch chosen by javadoc. Thus a lot of jaroslav@1890: * methods specs here are copied from superinterfaces. jaroslav@1890: */ jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Inserts the specified element at the front of this deque if it is jaroslav@1890: * possible to do so immediately without violating capacity restrictions, jaroslav@1890: * throwing an IllegalStateException if no space is currently jaroslav@1890: * available. When using a capacity-restricted deque, it is generally jaroslav@1890: * preferable to use {@link #offerFirst(Object) offerFirst}. jaroslav@1890: * jaroslav@1890: * @param e the element to add jaroslav@1890: * @throws IllegalStateException {@inheritDoc} jaroslav@1890: * @throws ClassCastException {@inheritDoc} jaroslav@1890: * @throws NullPointerException if the specified element is null jaroslav@1890: * @throws IllegalArgumentException {@inheritDoc} jaroslav@1890: */ jaroslav@1890: void addFirst(E e); jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Inserts the specified element at the end of this deque if it is jaroslav@1890: * possible to do so immediately without violating capacity restrictions, jaroslav@1890: * throwing an IllegalStateException if no space is currently jaroslav@1890: * available. When using a capacity-restricted deque, it is generally jaroslav@1890: * preferable to use {@link #offerLast(Object) offerLast}. jaroslav@1890: * jaroslav@1890: * @param e the element to add jaroslav@1890: * @throws IllegalStateException {@inheritDoc} jaroslav@1890: * @throws ClassCastException {@inheritDoc} jaroslav@1890: * @throws NullPointerException if the specified element is null jaroslav@1890: * @throws IllegalArgumentException {@inheritDoc} jaroslav@1890: */ jaroslav@1890: void addLast(E e); jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Inserts the specified element at the front of this deque if it is jaroslav@1890: * possible to do so immediately without violating capacity restrictions, jaroslav@1890: * returning true upon success and false if no space is jaroslav@1890: * currently available. jaroslav@1890: * When using a capacity-restricted deque, this method is generally jaroslav@1890: * preferable to the {@link #addFirst(Object) addFirst} method, which can jaroslav@1890: * fail to insert an element only by throwing an exception. jaroslav@1890: * jaroslav@1890: * @param e the element to add jaroslav@1890: * @throws ClassCastException {@inheritDoc} jaroslav@1890: * @throws NullPointerException if the specified element is null jaroslav@1890: * @throws IllegalArgumentException {@inheritDoc} jaroslav@1890: */ jaroslav@1890: boolean offerFirst(E e); jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Inserts the specified element at the end of this deque if it is jaroslav@1890: * possible to do so immediately without violating capacity restrictions, jaroslav@1890: * returning true upon success and false if no space is jaroslav@1890: * currently available. jaroslav@1890: * When using a capacity-restricted deque, this method is generally jaroslav@1890: * preferable to the {@link #addLast(Object) addLast} method, which can jaroslav@1890: * fail to insert an element only by throwing an exception. jaroslav@1890: * jaroslav@1890: * @param e the element to add jaroslav@1890: * @throws ClassCastException {@inheritDoc} jaroslav@1890: * @throws NullPointerException if the specified element is null jaroslav@1890: * @throws IllegalArgumentException {@inheritDoc} jaroslav@1890: */ jaroslav@1890: boolean offerLast(E e); jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Inserts the specified element at the front of this deque, jaroslav@1890: * waiting if necessary for space to become available. jaroslav@1890: * jaroslav@1890: * @param e the element to add jaroslav@1890: * @throws InterruptedException if interrupted while waiting jaroslav@1890: * @throws ClassCastException if the class of the specified element jaroslav@1890: * prevents it from being added to this deque jaroslav@1890: * @throws NullPointerException if the specified element is null jaroslav@1890: * @throws IllegalArgumentException if some property of the specified jaroslav@1890: * element prevents it from being added to this deque jaroslav@1890: */ jaroslav@1890: void putFirst(E e) throws InterruptedException; jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Inserts the specified element at the end of this deque, jaroslav@1890: * waiting if necessary for space to become available. jaroslav@1890: * jaroslav@1890: * @param e the element to add jaroslav@1890: * @throws InterruptedException if interrupted while waiting jaroslav@1890: * @throws ClassCastException if the class of the specified element jaroslav@1890: * prevents it from being added to this deque jaroslav@1890: * @throws NullPointerException if the specified element is null jaroslav@1890: * @throws IllegalArgumentException if some property of the specified jaroslav@1890: * element prevents it from being added to this deque jaroslav@1890: */ jaroslav@1890: void putLast(E e) throws InterruptedException; jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Inserts the specified element at the front of this deque, jaroslav@1890: * waiting up to the specified wait time if necessary for space to jaroslav@1890: * become available. jaroslav@1890: * jaroslav@1890: * @param e the element to add jaroslav@1890: * @param timeout how long to wait before giving up, in units of jaroslav@1890: * unit jaroslav@1890: * @param unit a TimeUnit determining how to interpret the jaroslav@1890: * timeout parameter jaroslav@1890: * @return true if successful, or false if jaroslav@1890: * the specified waiting time elapses before space is available jaroslav@1890: * @throws InterruptedException if interrupted while waiting jaroslav@1890: * @throws ClassCastException if the class of the specified element jaroslav@1890: * prevents it from being added to this deque jaroslav@1890: * @throws NullPointerException if the specified element is null jaroslav@1890: * @throws IllegalArgumentException if some property of the specified jaroslav@1890: * element prevents it from being added to this deque jaroslav@1890: */ jaroslav@1890: boolean offerFirst(E e, long timeout, TimeUnit unit) jaroslav@1890: throws InterruptedException; jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Inserts the specified element at the end of this deque, jaroslav@1890: * waiting up to the specified wait time if necessary for space to jaroslav@1890: * become available. jaroslav@1890: * jaroslav@1890: * @param e the element to add jaroslav@1890: * @param timeout how long to wait before giving up, in units of jaroslav@1890: * unit jaroslav@1890: * @param unit a TimeUnit determining how to interpret the jaroslav@1890: * timeout parameter jaroslav@1890: * @return true if successful, or false if jaroslav@1890: * the specified waiting time elapses before space is available jaroslav@1890: * @throws InterruptedException if interrupted while waiting jaroslav@1890: * @throws ClassCastException if the class of the specified element jaroslav@1890: * prevents it from being added to this deque jaroslav@1890: * @throws NullPointerException if the specified element is null jaroslav@1890: * @throws IllegalArgumentException if some property of the specified jaroslav@1890: * element prevents it from being added to this deque jaroslav@1890: */ jaroslav@1890: boolean offerLast(E e, long timeout, TimeUnit unit) jaroslav@1890: throws InterruptedException; jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Retrieves and removes the first element of this deque, waiting jaroslav@1890: * if necessary until an element becomes available. jaroslav@1890: * jaroslav@1890: * @return the head of this deque jaroslav@1890: * @throws InterruptedException if interrupted while waiting jaroslav@1890: */ jaroslav@1890: E takeFirst() throws InterruptedException; jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Retrieves and removes the last element of this deque, waiting jaroslav@1890: * if necessary until an element becomes available. jaroslav@1890: * jaroslav@1890: * @return the tail of this deque jaroslav@1890: * @throws InterruptedException if interrupted while waiting jaroslav@1890: */ jaroslav@1890: E takeLast() throws InterruptedException; jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Retrieves and removes the first element of this deque, waiting jaroslav@1890: * up to the specified wait time if necessary for an element to jaroslav@1890: * become available. jaroslav@1890: * jaroslav@1890: * @param timeout how long to wait before giving up, in units of jaroslav@1890: * unit jaroslav@1890: * @param unit a TimeUnit determining how to interpret the jaroslav@1890: * timeout parameter jaroslav@1890: * @return the head of this deque, or null if the specified jaroslav@1890: * waiting time elapses before an element is available jaroslav@1890: * @throws InterruptedException if interrupted while waiting jaroslav@1890: */ jaroslav@1890: E pollFirst(long timeout, TimeUnit unit) jaroslav@1890: throws InterruptedException; jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Retrieves and removes the last element of this deque, waiting jaroslav@1890: * up to the specified wait time if necessary for an element to jaroslav@1890: * become available. jaroslav@1890: * jaroslav@1890: * @param timeout how long to wait before giving up, in units of jaroslav@1890: * unit jaroslav@1890: * @param unit a TimeUnit determining how to interpret the jaroslav@1890: * timeout parameter jaroslav@1890: * @return the tail of this deque, or null if the specified jaroslav@1890: * waiting time elapses before an element is available jaroslav@1890: * @throws InterruptedException if interrupted while waiting jaroslav@1890: */ jaroslav@1890: E pollLast(long timeout, TimeUnit unit) jaroslav@1890: throws InterruptedException; jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Removes the first occurrence of the specified element from this deque. jaroslav@1890: * If the deque does not contain the element, it is unchanged. jaroslav@1890: * More formally, removes the first element e such that jaroslav@1890: * o.equals(e) (if such an element exists). jaroslav@1890: * Returns true if this deque contained the specified element jaroslav@1890: * (or equivalently, if this deque changed as a result of the call). jaroslav@1890: * jaroslav@1890: * @param o element to be removed from this deque, if present jaroslav@1890: * @return true if an element was removed as a result of this call jaroslav@1890: * @throws ClassCastException if the class of the specified element jaroslav@1890: * is incompatible with this deque jaroslav@1890: * (optional) jaroslav@1890: * @throws NullPointerException if the specified element is null jaroslav@1890: * (optional) jaroslav@1890: */ jaroslav@1890: boolean removeFirstOccurrence(Object o); jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Removes the last occurrence of the specified element from this deque. jaroslav@1890: * If the deque does not contain the element, it is unchanged. jaroslav@1890: * More formally, removes the last element e such that jaroslav@1890: * o.equals(e) (if such an element exists). jaroslav@1890: * Returns true if this deque contained the specified element jaroslav@1890: * (or equivalently, if this deque changed as a result of the call). jaroslav@1890: * jaroslav@1890: * @param o element to be removed from this deque, if present jaroslav@1890: * @return true if an element was removed as a result of this call jaroslav@1890: * @throws ClassCastException if the class of the specified element jaroslav@1890: * is incompatible with this deque jaroslav@1890: * (optional) jaroslav@1890: * @throws NullPointerException if the specified element is null jaroslav@1890: * (optional) jaroslav@1890: */ jaroslav@1890: boolean removeLastOccurrence(Object o); jaroslav@1890: jaroslav@1890: // *** BlockingQueue methods *** jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Inserts the specified element into the queue represented by this deque jaroslav@1890: * (in other words, at the tail of this deque) if it is possible to do so jaroslav@1890: * immediately without violating capacity restrictions, returning jaroslav@1890: * true upon success and throwing an jaroslav@1890: * IllegalStateException if no space is currently available. jaroslav@1890: * When using a capacity-restricted deque, it is generally preferable to jaroslav@1890: * use {@link #offer(Object) offer}. jaroslav@1890: * jaroslav@1890: *

This method is equivalent to {@link #addLast(Object) addLast}. jaroslav@1890: * jaroslav@1890: * @param e the element to add jaroslav@1890: * @throws IllegalStateException {@inheritDoc} jaroslav@1890: * @throws ClassCastException if the class of the specified element jaroslav@1890: * prevents it from being added to this deque jaroslav@1890: * @throws NullPointerException if the specified element is null jaroslav@1890: * @throws IllegalArgumentException if some property of the specified jaroslav@1890: * element prevents it from being added to this deque jaroslav@1890: */ jaroslav@1890: boolean add(E e); jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Inserts the specified element into the queue represented by this deque jaroslav@1890: * (in other words, at the tail of this deque) if it is possible to do so jaroslav@1890: * immediately without violating capacity restrictions, returning jaroslav@1890: * true upon success and false if no space is currently jaroslav@1890: * available. When using a capacity-restricted deque, this method is jaroslav@1890: * generally preferable to the {@link #add} method, which can fail to jaroslav@1890: * insert an element only by throwing an exception. jaroslav@1890: * jaroslav@1890: *

This method is equivalent to {@link #offerLast(Object) offerLast}. jaroslav@1890: * jaroslav@1890: * @param e the element to add jaroslav@1890: * @throws ClassCastException if the class of the specified element jaroslav@1890: * prevents it from being added to this deque jaroslav@1890: * @throws NullPointerException if the specified element is null jaroslav@1890: * @throws IllegalArgumentException if some property of the specified jaroslav@1890: * element prevents it from being added to this deque jaroslav@1890: */ jaroslav@1890: boolean offer(E e); jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Inserts the specified element into the queue represented by this deque jaroslav@1890: * (in other words, at the tail of this deque), waiting if necessary for jaroslav@1890: * space to become available. jaroslav@1890: * jaroslav@1890: *

This method is equivalent to {@link #putLast(Object) putLast}. jaroslav@1890: * jaroslav@1890: * @param e the element to add jaroslav@1890: * @throws InterruptedException {@inheritDoc} jaroslav@1890: * @throws ClassCastException if the class of the specified element jaroslav@1890: * prevents it from being added to this deque jaroslav@1890: * @throws NullPointerException if the specified element is null jaroslav@1890: * @throws IllegalArgumentException if some property of the specified jaroslav@1890: * element prevents it from being added to this deque jaroslav@1890: */ jaroslav@1890: void put(E e) throws InterruptedException; jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Inserts the specified element into the queue represented by this deque jaroslav@1890: * (in other words, at the tail of this deque), waiting up to the jaroslav@1890: * specified wait time if necessary for space to become available. jaroslav@1890: * jaroslav@1890: *

This method is equivalent to jaroslav@1890: * {@link #offerLast(Object,long,TimeUnit) offerLast}. jaroslav@1890: * jaroslav@1890: * @param e the element to add jaroslav@1890: * @return true if the element was added to this deque, else jaroslav@1890: * false jaroslav@1890: * @throws InterruptedException {@inheritDoc} jaroslav@1890: * @throws ClassCastException if the class of the specified element jaroslav@1890: * prevents it from being added to this deque jaroslav@1890: * @throws NullPointerException if the specified element is null jaroslav@1890: * @throws IllegalArgumentException if some property of the specified jaroslav@1890: * element prevents it from being added to this deque jaroslav@1890: */ jaroslav@1890: boolean offer(E e, long timeout, TimeUnit unit) jaroslav@1890: throws InterruptedException; jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Retrieves and removes the head of the queue represented by this deque jaroslav@1890: * (in other words, the first element of this deque). jaroslav@1890: * This method differs from {@link #poll poll} only in that it jaroslav@1890: * throws an exception if this deque is empty. jaroslav@1890: * jaroslav@1890: *

This method is equivalent to {@link #removeFirst() removeFirst}. jaroslav@1890: * jaroslav@1890: * @return the head of the queue represented by this deque jaroslav@1890: * @throws NoSuchElementException if this deque is empty jaroslav@1890: */ jaroslav@1890: E remove(); jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Retrieves and removes the head of the queue represented by this deque jaroslav@1890: * (in other words, the first element of this deque), or returns jaroslav@1890: * null if this deque is empty. jaroslav@1890: * jaroslav@1890: *

This method is equivalent to {@link #pollFirst()}. jaroslav@1890: * jaroslav@1890: * @return the head of this deque, or null if this deque is empty jaroslav@1890: */ jaroslav@1890: E poll(); jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Retrieves and removes the head of the queue represented by this deque jaroslav@1890: * (in other words, the first element of this deque), waiting if jaroslav@1890: * necessary until an element becomes available. jaroslav@1890: * jaroslav@1890: *

This method is equivalent to {@link #takeFirst() takeFirst}. jaroslav@1890: * jaroslav@1890: * @return the head of this deque jaroslav@1890: * @throws InterruptedException if interrupted while waiting jaroslav@1890: */ jaroslav@1890: E take() throws InterruptedException; jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Retrieves and removes the head of the queue represented by this deque jaroslav@1890: * (in other words, the first element of this deque), waiting up to the jaroslav@1890: * specified wait time if necessary for an element to become available. jaroslav@1890: * jaroslav@1890: *

This method is equivalent to jaroslav@1890: * {@link #pollFirst(long,TimeUnit) pollFirst}. jaroslav@1890: * jaroslav@1890: * @return the head of this deque, or null if the jaroslav@1890: * specified waiting time elapses before an element is available jaroslav@1890: * @throws InterruptedException if interrupted while waiting jaroslav@1890: */ jaroslav@1890: E poll(long timeout, TimeUnit unit) jaroslav@1890: throws InterruptedException; jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Retrieves, but does not remove, the head of the queue represented by jaroslav@1890: * this deque (in other words, the first element of this deque). jaroslav@1890: * This method differs from {@link #peek peek} only in that it throws an jaroslav@1890: * exception if this deque is empty. jaroslav@1890: * jaroslav@1890: *

This method is equivalent to {@link #getFirst() getFirst}. jaroslav@1890: * jaroslav@1890: * @return the head of this deque jaroslav@1890: * @throws NoSuchElementException if this deque is empty jaroslav@1890: */ jaroslav@1890: E element(); jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Retrieves, but does not remove, the head of the queue represented by jaroslav@1890: * this deque (in other words, the first element of this deque), or jaroslav@1890: * returns null if this deque is empty. jaroslav@1890: * jaroslav@1890: *

This method is equivalent to {@link #peekFirst() peekFirst}. jaroslav@1890: * jaroslav@1890: * @return the head of this deque, or null if this deque is empty jaroslav@1890: */ jaroslav@1890: E peek(); jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Removes the first occurrence of the specified element from this deque. jaroslav@1890: * If the deque does not contain the element, it is unchanged. jaroslav@1890: * More formally, removes the first element e such that jaroslav@1890: * o.equals(e) (if such an element exists). jaroslav@1890: * Returns true if this deque contained the specified element jaroslav@1890: * (or equivalently, if this deque changed as a result of the call). jaroslav@1890: * jaroslav@1890: *

This method is equivalent to jaroslav@1890: * {@link #removeFirstOccurrence(Object) removeFirstOccurrence}. jaroslav@1890: * jaroslav@1890: * @param o element to be removed from this deque, if present jaroslav@1890: * @return true if this deque changed as a result of the call jaroslav@1890: * @throws ClassCastException if the class of the specified element jaroslav@1890: * is incompatible with this deque jaroslav@1890: * (optional) jaroslav@1890: * @throws NullPointerException if the specified element is null jaroslav@1890: * (optional) jaroslav@1890: */ jaroslav@1890: boolean remove(Object o); jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Returns true if this deque contains the specified element. jaroslav@1890: * More formally, returns true if and only if this deque contains jaroslav@1890: * at least one element e such that o.equals(e). jaroslav@1890: * jaroslav@1890: * @param o object to be checked for containment in this deque jaroslav@1890: * @return true if this deque contains the specified element jaroslav@1890: * @throws ClassCastException if the class of the specified element jaroslav@1890: * is incompatible with this deque jaroslav@1890: * (optional) jaroslav@1890: * @throws NullPointerException if the specified element is null jaroslav@1890: * (optional) jaroslav@1890: */ jaroslav@1890: public boolean contains(Object o); jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Returns the number of elements in this deque. jaroslav@1890: * jaroslav@1890: * @return the number of elements in this deque jaroslav@1890: */ jaroslav@1890: public int size(); jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Returns an iterator over the elements in this deque in proper sequence. jaroslav@1890: * The elements will be returned in order from first (head) to last (tail). jaroslav@1890: * jaroslav@1890: * @return an iterator over the elements in this deque in proper sequence jaroslav@1890: */ jaroslav@1890: Iterator iterator(); jaroslav@1890: jaroslav@1890: // *** Stack methods *** jaroslav@1890: jaroslav@1890: /** jaroslav@1890: * Pushes an element onto the stack represented by this deque. In other jaroslav@1890: * words, inserts the element at the front of this deque unless it would jaroslav@1890: * violate capacity restrictions. jaroslav@1890: * jaroslav@1890: *

This method is equivalent to {@link #addFirst(Object) addFirst}. jaroslav@1890: * jaroslav@1890: * @throws IllegalStateException {@inheritDoc} jaroslav@1890: * @throws ClassCastException {@inheritDoc} jaroslav@1890: * @throws NullPointerException if the specified element is null jaroslav@1890: * @throws IllegalArgumentException {@inheritDoc} jaroslav@1890: */ jaroslav@1890: void push(E e); jaroslav@1890: }