rt/emul/compact/src/main/java/java/util/Queue.java
changeset 772 d382dacfd73f
parent 597 ee8a922f4268
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/rt/emul/compact/src/main/java/java/util/Queue.java	Tue Feb 26 16:54:16 2013 +0100
     1.3 @@ -0,0 +1,218 @@
     1.4 +/*
     1.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.6 + *
     1.7 + * This code is free software; you can redistribute it and/or modify it
     1.8 + * under the terms of the GNU General Public License version 2 only, as
     1.9 + * published by the Free Software Foundation.  Oracle designates this
    1.10 + * particular file as subject to the "Classpath" exception as provided
    1.11 + * by Oracle in the LICENSE file that accompanied this code.
    1.12 + *
    1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.16 + * version 2 for more details (a copy is included in the LICENSE file that
    1.17 + * accompanied this code).
    1.18 + *
    1.19 + * You should have received a copy of the GNU General Public License version
    1.20 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.22 + *
    1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.24 + * or visit www.oracle.com if you need additional information or have any
    1.25 + * questions.
    1.26 + */
    1.27 +
    1.28 +/*
    1.29 + * This file is available under and governed by the GNU General Public
    1.30 + * License version 2 only, as published by the Free Software Foundation.
    1.31 + * However, the following notice accompanied the original version of this
    1.32 + * file:
    1.33 + *
    1.34 + * Written by Doug Lea with assistance from members of JCP JSR-166
    1.35 + * Expert Group and released to the public domain, as explained at
    1.36 + * http://creativecommons.org/publicdomain/zero/1.0/
    1.37 + */
    1.38 +
    1.39 +package java.util;
    1.40 +
    1.41 +/**
    1.42 + * A collection designed for holding elements prior to processing.
    1.43 + * Besides basic {@link java.util.Collection Collection} operations,
    1.44 + * queues provide additional insertion, extraction, and inspection
    1.45 + * operations.  Each of these methods exists in two forms: one throws
    1.46 + * an exception if the operation fails, the other returns a special
    1.47 + * value (either <tt>null</tt> or <tt>false</tt>, depending on the
    1.48 + * operation).  The latter form of the insert operation is designed
    1.49 + * specifically for use with capacity-restricted <tt>Queue</tt>
    1.50 + * implementations; in most implementations, insert operations cannot
    1.51 + * fail.
    1.52 + *
    1.53 + * <p>
    1.54 + * <table BORDER CELLPADDING=3 CELLSPACING=1>
    1.55 + *  <tr>
    1.56 + *    <td></td>
    1.57 + *    <td ALIGN=CENTER><em>Throws exception</em></td>
    1.58 + *    <td ALIGN=CENTER><em>Returns special value</em></td>
    1.59 + *  </tr>
    1.60 + *  <tr>
    1.61 + *    <td><b>Insert</b></td>
    1.62 + *    <td>{@link #add add(e)}</td>
    1.63 + *    <td>{@link #offer offer(e)}</td>
    1.64 + *  </tr>
    1.65 + *  <tr>
    1.66 + *    <td><b>Remove</b></td>
    1.67 + *    <td>{@link #remove remove()}</td>
    1.68 + *    <td>{@link #poll poll()}</td>
    1.69 + *  </tr>
    1.70 + *  <tr>
    1.71 + *    <td><b>Examine</b></td>
    1.72 + *    <td>{@link #element element()}</td>
    1.73 + *    <td>{@link #peek peek()}</td>
    1.74 + *  </tr>
    1.75 + * </table>
    1.76 + *
    1.77 + * <p>Queues typically, but do not necessarily, order elements in a
    1.78 + * FIFO (first-in-first-out) manner.  Among the exceptions are
    1.79 + * priority queues, which order elements according to a supplied
    1.80 + * comparator, or the elements' natural ordering, and LIFO queues (or
    1.81 + * stacks) which order the elements LIFO (last-in-first-out).
    1.82 + * Whatever the ordering used, the <em>head</em> of the queue is that
    1.83 + * element which would be removed by a call to {@link #remove() } or
    1.84 + * {@link #poll()}.  In a FIFO queue, all new elements are inserted at
    1.85 + * the <em> tail</em> of the queue. Other kinds of queues may use
    1.86 + * different placement rules.  Every <tt>Queue</tt> implementation
    1.87 + * must specify its ordering properties.
    1.88 + *
    1.89 + * <p>The {@link #offer offer} method inserts an element if possible,
    1.90 + * otherwise returning <tt>false</tt>.  This differs from the {@link
    1.91 + * java.util.Collection#add Collection.add} method, which can fail to
    1.92 + * add an element only by throwing an unchecked exception.  The
    1.93 + * <tt>offer</tt> method is designed for use when failure is a normal,
    1.94 + * rather than exceptional occurrence, for example, in fixed-capacity
    1.95 + * (or &quot;bounded&quot;) queues.
    1.96 + *
    1.97 + * <p>The {@link #remove()} and {@link #poll()} methods remove and
    1.98 + * return the head of the queue.
    1.99 + * Exactly which element is removed from the queue is a
   1.100 + * function of the queue's ordering policy, which differs from
   1.101 + * implementation to implementation. The <tt>remove()</tt> and
   1.102 + * <tt>poll()</tt> methods differ only in their behavior when the
   1.103 + * queue is empty: the <tt>remove()</tt> method throws an exception,
   1.104 + * while the <tt>poll()</tt> method returns <tt>null</tt>.
   1.105 + *
   1.106 + * <p>The {@link #element()} and {@link #peek()} methods return, but do
   1.107 + * not remove, the head of the queue.
   1.108 + *
   1.109 + * <p>The <tt>Queue</tt> interface does not define the <i>blocking queue
   1.110 + * methods</i>, which are common in concurrent programming.  These methods,
   1.111 + * which wait for elements to appear or for space to become available, are
   1.112 + * defined in the {@link java.util.concurrent.BlockingQueue} interface, which
   1.113 + * extends this interface.
   1.114 + *
   1.115 + * <p><tt>Queue</tt> implementations generally do not allow insertion
   1.116 + * of <tt>null</tt> elements, although some implementations, such as
   1.117 + * {@link LinkedList}, do not prohibit insertion of <tt>null</tt>.
   1.118 + * Even in the implementations that permit it, <tt>null</tt> should
   1.119 + * not be inserted into a <tt>Queue</tt>, as <tt>null</tt> is also
   1.120 + * used as a special return value by the <tt>poll</tt> method to
   1.121 + * indicate that the queue contains no elements.
   1.122 + *
   1.123 + * <p><tt>Queue</tt> implementations generally do not define
   1.124 + * element-based versions of methods <tt>equals</tt> and
   1.125 + * <tt>hashCode</tt> but instead inherit the identity based versions
   1.126 + * from class <tt>Object</tt>, because element-based equality is not
   1.127 + * always well-defined for queues with the same elements but different
   1.128 + * ordering properties.
   1.129 + *
   1.130 + *
   1.131 + * <p>This interface is a member of the
   1.132 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   1.133 + * Java Collections Framework</a>.
   1.134 + *
   1.135 + * @see java.util.Collection
   1.136 + * @see LinkedList
   1.137 + * @see PriorityQueue
   1.138 + * @see java.util.concurrent.LinkedBlockingQueue
   1.139 + * @see java.util.concurrent.BlockingQueue
   1.140 + * @see java.util.concurrent.ArrayBlockingQueue
   1.141 + * @see java.util.concurrent.LinkedBlockingQueue
   1.142 + * @see java.util.concurrent.PriorityBlockingQueue
   1.143 + * @since 1.5
   1.144 + * @author Doug Lea
   1.145 + * @param <E> the type of elements held in this collection
   1.146 + */
   1.147 +public interface Queue<E> extends Collection<E> {
   1.148 +    /**
   1.149 +     * Inserts the specified element into this queue if it is possible to do so
   1.150 +     * immediately without violating capacity restrictions, returning
   1.151 +     * <tt>true</tt> upon success and throwing an <tt>IllegalStateException</tt>
   1.152 +     * if no space is currently available.
   1.153 +     *
   1.154 +     * @param e the element to add
   1.155 +     * @return <tt>true</tt> (as specified by {@link Collection#add})
   1.156 +     * @throws IllegalStateException if the element cannot be added at this
   1.157 +     *         time due to capacity restrictions
   1.158 +     * @throws ClassCastException if the class of the specified element
   1.159 +     *         prevents it from being added to this queue
   1.160 +     * @throws NullPointerException if the specified element is null and
   1.161 +     *         this queue does not permit null elements
   1.162 +     * @throws IllegalArgumentException if some property of this element
   1.163 +     *         prevents it from being added to this queue
   1.164 +     */
   1.165 +    boolean add(E e);
   1.166 +
   1.167 +    /**
   1.168 +     * Inserts the specified element into this queue if it is possible to do
   1.169 +     * so immediately without violating capacity restrictions.
   1.170 +     * When using a capacity-restricted queue, this method is generally
   1.171 +     * preferable to {@link #add}, which can fail to insert an element only
   1.172 +     * by throwing an exception.
   1.173 +     *
   1.174 +     * @param e the element to add
   1.175 +     * @return <tt>true</tt> if the element was added to this queue, else
   1.176 +     *         <tt>false</tt>
   1.177 +     * @throws ClassCastException if the class of the specified element
   1.178 +     *         prevents it from being added to this queue
   1.179 +     * @throws NullPointerException if the specified element is null and
   1.180 +     *         this queue does not permit null elements
   1.181 +     * @throws IllegalArgumentException if some property of this element
   1.182 +     *         prevents it from being added to this queue
   1.183 +     */
   1.184 +    boolean offer(E e);
   1.185 +
   1.186 +    /**
   1.187 +     * Retrieves and removes the head of this queue.  This method differs
   1.188 +     * from {@link #poll poll} only in that it throws an exception if this
   1.189 +     * queue is empty.
   1.190 +     *
   1.191 +     * @return the head of this queue
   1.192 +     * @throws NoSuchElementException if this queue is empty
   1.193 +     */
   1.194 +    E remove();
   1.195 +
   1.196 +    /**
   1.197 +     * Retrieves and removes the head of this queue,
   1.198 +     * or returns <tt>null</tt> if this queue is empty.
   1.199 +     *
   1.200 +     * @return the head of this queue, or <tt>null</tt> if this queue is empty
   1.201 +     */
   1.202 +    E poll();
   1.203 +
   1.204 +    /**
   1.205 +     * Retrieves, but does not remove, the head of this queue.  This method
   1.206 +     * differs from {@link #peek peek} only in that it throws an exception
   1.207 +     * if this queue is empty.
   1.208 +     *
   1.209 +     * @return the head of this queue
   1.210 +     * @throws NoSuchElementException if this queue is empty
   1.211 +     */
   1.212 +    E element();
   1.213 +
   1.214 +    /**
   1.215 +     * Retrieves, but does not remove, the head of this queue,
   1.216 +     * or returns <tt>null</tt> if this queue is empty.
   1.217 +     *
   1.218 +     * @return the head of this queue, or <tt>null</tt> if this queue is empty
   1.219 +     */
   1.220 +    E peek();
   1.221 +}