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.3 by dl, Tue May 27 18:20:06 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 > *
14 > * <p>Queues typically, but do not necessarily, order elements in a
15 > * FIFO (first-in-first-out) manner.  Among the exceptions are priority
16 > * queues, which order elements according to a supplied comparators, or
17 > * the elements natural ordering.  Every Queue implementation must specify
18 > * 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.
25 > * in fixed-capacity (or &ldquo;bounded&rdquo;) queues.
26 > *
27 > * <p>The {@link #remove()} and {@link #poll()} methods remove and return an
28 > * element in accord with the implementation's ordering policy. For example,
29 > * in FIFO queues, they remove and return the oldest element in the queue.
30 > * The <tt>remove()</tt> and <tt>poll()</tt> methods differ only in their
31 > * behavior when the queue is empty: the <tt>remove()</tt> method throws an
32 > * exception, while the <tt>poll()</tt> method returns <tt>null</tt>.
33   *
34 < * <p> The <tt>remove</tt> and <tt>poll</tt> methods delete and return
21 < * an element in accord with the implementation's ordering policies --
22 < * for example, in FIFO queues, it will return the oldest element.
23 < * The <tt>remove</tt> and <tt>poll</tt> differ only in their behavior
24 < * when the queue is empty: <tt>poll</tt> returns <tt>null</tt> while
25 < * <tt>remove</tt> throws an exception. These are designed for usage
26 < * contexts in which emptiness is considered to be normal versus
27 < * exceptional.
28 < *
29 < * <p> The <tt>element</tt> and <tt>peek</tt> methods return but do
34 > * <p>The {@link #element()} and {@link #peek()} methods return but do
35   * not delete the element that would be obtained by a call to
36 < * <tt>remove</tt> and <tt>poll</tt> respectively.
36 > * the <tt>remove</tt> and <tt>poll</tt> methods respectively.
37   *
38 < * <p> The Queue interface does not define blocking queue methods
39 < * (i.e., those that wait for elements to appear and/or for space to
40 < * be available) that are common in concurrent programming. These are
41 < * defined in the extended java.util.concurrent.BlockingQueue
42 < * interface.
43 < *
44 < * <p> Queue implementations generally do not allow insertion of
45 < * <tt>null</tt>. Even in those that allow it, it is a very bad idea
46 < * to do so, since <tt>null</tt> is also used as a sentinel by
47 < * <tt>poll</tt> to indicate that no elements exist.
48 < **/
38 > * <p>The <tt>Queue</tt> interface does not define the <i>blocking queue
39 > * methods</i>, which are common in concurrent programming.  These methods,
40 > * which wait for elements to appear or for space to become available, are
41 > * defined in the {@link java.util.concurrent.BlockingQueue} interface, which
42 > * extends this interface.
43 > *
44 > * <p><tt>Queue</tt> implementations generally do not allow insertion of
45 > * <tt>null</tt> elements.  Even in the few implementations that permit it,
46 > * it is a bad idea, as <tt>null</tt> is also used as a special return value
47 > * by the <tt>poll</tt> method to indicate that the queue contains no
48 > * elements.
49 > *
50 > * <p>This interface is a member of the
51 > * <a href="{@docRoot}/../guide/collections/index.html">
52 > * Java Collections Framework</a>.
53 > *
54 > * @see Collection
55 > * @see LinkedList
56 > * @see PriorityQueue
57 > * @see LinkedQueue
58 > * @see java.util.concurrent.BlockingQueue
59 > * @see java.util.concurrent.ArrayBlockingQueue
60 > * @see java.util.concurrent.LinkedBlockingQueue
61 > * @see java.util.concurrent.PriorityBlockingQueue
62 > */
63   public interface Queue<E> extends Collection<E> {
45
64      /**
65 <     * Add the given object to this queue if possible.
66 <     * @param x the object to add
67 <     * @return true if successful
68 <     **/
69 <    public boolean offer(E x);
65 >     * Add the specified element to this queue, if possible.
66 >     *
67 >     * @param element the element to add.
68 >     * @return true if it was possible to add the element to the queue.
69 >     */
70 >    public boolean offer(E element);
71  
72      /**
73 <     * Delete and return an object from the queue if one is available.
74 <     * @return the object, or null if the queue is empty.
75 <     **/
73 >     * Remove and return an element from the queue if one is available.
74 >     * Exactly which element is removed from the queue is a function
75 >     * of the queue's ordering policy, which differs from implementation
76 >     * to implementation.  Possible orderings include (but are not limited
77 >     * to) first-in-first-out (FIFO), element priority, and arbitrary.
78 >     *
79 >     * @return an element previously on the queue, or <tt>null</tt> if the
80 >     *         queue is empty.
81 >     */
82      public E poll();
83  
84      /**
85 <     * Delete and return the element produced by poll, if the queue is
86 <     * not empty.
87 <     * @return an element
88 <     * @throws NoSuchElementException if empty
89 <     **/
85 >     * Remove and return an element from the queue.  This method differs
86 >     * from the <tt>poll</tt> method in that it throws an exception if the
87 >     * queue is empty.
88 >     *
89 >     * @return an element previously on the queue.
90 >     * @throws NoSuchElementException if the queue is empty.
91 >     */
92      public E remove() throws NoSuchElementException;
93  
94      /**
95 <     * Return but do not delete the element that will be returned by
96 <     * the next call to poll.
97 <     * @return an element, or null if empty
98 <     **/
95 >     * Return, but do not remove, an element from the queue, or <tt>null</tt>
96 >     * if the queue is empty.  This method returns the same object reference
97 >     * that would be returned by by the <tt>poll</tt> method.  The two methods
98 >     * differ in that this method does not remove the element from the queue.
99 >     *
100 >     * @return an element on the queue, or <tt>null</tt> if the queue is empty.
101 >     */
102      public E peek();
103  
104      /**
105 <     * Return but do not delete the element that will be returned by
106 <     * the next call to poll, if the queue is not empty.
107 <     * @return an element
108 <     * @throws NoSuchElementException if empty
109 <     **/
105 >     * Return, but do not remove, an element from the queue.  This method
106 >     * differs from the <tt>peek</tt> method in that it throws an exception if
107 >     * the queue is empty.
108 >     *
109 >     * @return an element on the queue.
110 >     * @throws NoSuchElementException if the queue is empty.
111 >     */
112      public E element() throws NoSuchElementException;
113   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines