ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/Queue.java
(Generate patch)

Comparing jsr166/src/main/java/util/Queue.java (file contents):
Revision 1.1 by tim, Wed May 14 21:30:45 2003 UTC vs.
Revision 1.6 by brian, Mon Jun 23 02:26:15 2003 UTC

# Line 1 | Line 1
1 + /*
2 + * Written by Doug Lea with assistance from members of JCP JSR-166
3 + * Expert Group and released to the public domain. Use, modify, and
4 + * redistribute this code in any way without acknowledgement.
5 + */
6 +
7   package java.util;
8  
9   /**
10 < * Queues are Collections supporting additional basic insertion,
11 < * extraction, and inspection operations.
12 < *
13 < * <p> Queues typically, but do not necessarily order elements in a
14 < * FIFO (first-in-first-out) manner. Among the exceptions are priority
15 < * queues, that order elements in accord with supplied
16 < * Comparators. Every Queue implementation must specify its ordering
17 < * guarantees,
18 < *
19 < * <p> The <tt>offer</tt> method adds an element if possible,
20 < * otherwise returning <tt>false</tt>. This differs from the
21 < * Collections.add method, that throws an unchecked exception upon
10 > * A Collection designed for holding elements prior to processing.
11 > * Besides basic {@link Collection} operations, queues provide
12 > * additional insertion, extraction, and inspection operations.
13 > 0 *
14 > * <p>Queues typically, but do not necessarily, order elements in a
15 > * FIFO (first-in-first-out) manner.  Among the exceptions are
16 > * priority queues, which order elements according to a supplied
17 > * comparator, or the elements' natural ordering.  Every Queue
18 > * implementation must specify its ordering guarantees.
19 > *
20 > * <p>The {@link #offer(E)} method adds an element if possible, otherwise
21 > * returning <tt>false</tt>.  This differs from the {@link
22 > * Collections#add(Object)} method, which throws an unchecked exception upon
23   * failure. It is designed for use in collections in which failure to
24   * add is a normal, rather than exceptional occurrence, for example,
25 < * in fixed-capacity queues.
26 < *
27 < * <p> The <tt>remove</tt> and <tt>poll</tt> methods delete and return
28 < * an element in accord with the implementation's ordering policies --
29 < * for example, in FIFO queues, it will return the oldest element.
30 < * The <tt>remove</tt> and <tt>poll</tt> differ only in their behavior
31 < * when the queue is empty: <tt>poll</tt> returns <tt>null</tt> while
32 < * <tt>remove</tt> throws an exception. These are designed for usage
33 < * contexts in which emptiness is considered to be normal versus
34 < * exceptional.
25 > * in fixed-capacity (or &ldquo;bounded&rdquo;) queues.
26 >
27 > *
28 > * <p>The {@link #remove()} and {@link #poll()} methods remove and return an
29 > * element in accord with the implementation's ordering policy.
30 > * Exactly which element is removed from the queue is a function
31 > * of the queue's ordering policy, which differs from implementation
32 > * to implementation.  Possible orderings include (but are not limited
33 > * to) first-in-first-out (FIFO), last-in-first-out (LIFO), element priority, and arbitrary.
34 > * The <tt>remove()</tt> and <tt>poll()</tt> methods differ only in their
35 > * behavior when the queue is empty: the <tt>remove()</tt> method throws an
36 > * exception, while the <tt>poll()</tt> method returns <tt>null</tt>.
37   *
38 < * <p> The <tt>element</tt> and <tt>peek</tt> methods return but do
38 > * <p>The {@link #element()} and {@link #peek()} methods return but do
39   * not delete the element that would be obtained by a call to
40 < * <tt>remove</tt> and <tt>poll</tt> respectively.
40 > * the <tt>remove</tt> and <tt>poll</tt> methods respectively.
41   *
42 < * <p> The Queue interface does not define blocking queue methods
43 < * (i.e., those that wait for elements to appear and/or for space to
44 < * be available) that are common in concurrent programming. These are
45 < * defined in the extended java.util.concurrent.BlockingQueue
46 < * interface.
47 < *
48 < * <p> Queue implementations generally do not allow insertion of
49 < * <tt>null</tt>. Even in those that allow it, it is a very bad idea
50 < * to do so, since <tt>null</tt> is also used as a sentinel by
51 < * <tt>poll</tt> to indicate that no elements exist.
52 < **/
42 > * <p>The <tt>Queue</tt> interface does not define the <i>blocking queue
43 > * methods</i>, which are common in concurrent programming.  These methods,
44 > * which wait for elements to appear or for space to become available, are
45 > * defined in the {@link java.util.concurrent.BlockingQueue} interface, which
46 > * extends this interface.
47 > *
48 > * <p><tt>Queue</tt> implementations generally do not allow insertion of
49 > * <tt>null</tt> elements, although some implementations, such as
50 > * {@link LinkedList}, do not prohibit insertion of <tt>null</tt>.
51 > * Even in the implementations that permit it, <tt>null</tt> should not be inserted into
52 > * a <tt>Queue</tt>, as <tt>null</tt> is also used as a special return value
53 > * by the <tt>poll</tt> method to indicate that the queue contains no
54 > * elements.
55 > *
56 > * <p>This interface is a member of the
57 > * <a href="{@docRoot}/../guide/collections/index.html">
58 > * Java Collections Framework</a>.
59 > *
60 > * @see Collection
61 > * @see LinkedList
62 > * @see PriorityQueue
63 > * @see java.util.concurrent.LinkedQueue
64 > * @see java.util.concurrent.BlockingQueue
65 > * @see java.util.concurrent.ArrayBlockingQueue
66 > * @see java.util.concurrent.LinkedBlockingQueue
67 > * @see java.util.concurrent.PriorityBlockingQueue
68 > */
69   public interface Queue<E> extends Collection<E> {
45
70      /**
71 <     * Add the given object to this queue if possible.
72 <     * @param x the object to add
73 <     * @return true if successful
74 <     **/
75 <    public boolean offer(E x);
71 >     * Add the specified element to this queue, if possible.
72 >     *
73 >     * @param element the element to add.
74 >     * @return true if it was possible to add the element to the queue.
75 >     */
76 >    public boolean offer(E element);
77  
78      /**
79 <     * Delete and return an object from the queue if one is available.
80 <     * @return the object, or null if the queue is empty.
81 <     **/
79 >     * Remove and return an element from the queue if one is available.
80 >     *
81 >     * @return an element previously on the queue, or <tt>null</tt> if the
82 >     *         queue is empty.
83 >     */
84      public E poll();
85  
86      /**
87 <     * Delete and return the element produced by poll, if the queue is
88 <     * not empty.
89 <     * @return an element
90 <     * @throws NoSuchElementException if empty
91 <     **/
87 >     * Remove and return an element from the queue.  This method differs
88 >     * from the <tt>poll</tt> method in that it throws an exception if the
89 >     * queue is empty.
90 >     *
91 >     * @return an element previously on the queue.
92 >     * @throws NoSuchElementException if the queue is empty.
93 >     */
94      public E remove() throws NoSuchElementException;
95  
96      /**
97 <     * Return but do not delete the element that will be returned by
98 <     * the next call to poll.
99 <     * @return an element, or null if empty
100 <     **/
97 >     * Return, but do not remove, an element from the queue, or <tt>null</tt>
98 >     * if the queue is empty.  This method returns the same object reference
99 >     * that would be returned by by the <tt>poll</tt> method.  The two methods
100 >     * differ in that this method does not remove the element from the queue.
101 >     *
102 >     * @return an element on the queue, or <tt>null</tt> if the queue is empty.
103 >     */
104      public E peek();
105  
106      /**
107 <     * Return but do not delete the element that will be returned by
108 <     * the next call to poll, if the queue is not empty.
109 <     * @return an element
110 <     * @throws NoSuchElementException if empty
111 <     **/
107 >     * Return, but do not remove, an element from the queue.  This method
108 >     * differs from the <tt>peek</tt> method in that it throws an exception if
109 >     * the queue is empty.
110 >     *
111 >     * @return an element on the queue.
112 >     * @throws NoSuchElementException if the queue is empty.
113 >     */
114      public E element() throws NoSuchElementException;
115   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines