8 |
|
|
9 |
|
/** |
10 |
|
* A collection designed for holding elements prior to processing. |
11 |
< |
* Besides basic {@link java.util.Collection Collection} operations, |
12 |
< |
* queues provide additional insertion, extraction, and inspection |
13 |
< |
* operations. Each of these methods exists in two forms: one throws |
14 |
< |
* an exception if the operation fails, the other returns a special |
15 |
< |
* value (either {@code null} or {@code false}, depending on the |
16 |
< |
* operation). The latter form of the insert operation is designed |
17 |
< |
* specifically for use with capacity-restricted {@code Queue} |
18 |
< |
* implementations; in most implementations, insert operations cannot |
19 |
< |
* fail. |
11 |
> |
* Besides basic {@link Collection} operations, queues provide |
12 |
> |
* additional insertion, extraction, and inspection operations. |
13 |
> |
* Each of these methods exists in two forms: one throws an exception |
14 |
> |
* if the operation fails, the other returns a special value (either |
15 |
> |
* {@code null} or {@code false}, depending on the operation). The |
16 |
> |
* latter form of the insert operation is designed specifically for |
17 |
> |
* use with capacity-restricted {@code Queue} implementations; in most |
18 |
> |
* implementations, insert operations cannot fail. |
19 |
|
* |
20 |
< |
* <table BORDER CELLPADDING=3 CELLSPACING=1> |
20 |
> |
* <table class="striped"> |
21 |
|
* <caption>Summary of Queue methods</caption> |
22 |
+ |
* <thead> |
23 |
|
* <tr> |
24 |
|
* <td></td> |
25 |
< |
* <td ALIGN=CENTER><em>Throws exception</em></td> |
26 |
< |
* <td ALIGN=CENTER><em>Returns special value</em></td> |
25 |
> |
* <th scope="col" style="font-weight:normal; font-style:italic">Throws exception</th> |
26 |
> |
* <th scope="col" style="font-weight:normal; font-style:italic">Returns special value</th> |
27 |
|
* </tr> |
28 |
+ |
* </thead> |
29 |
+ |
* <tbody> |
30 |
|
* <tr> |
31 |
< |
* <td><b>Insert</b></td> |
32 |
< |
* <td>{@link Queue#add add(e)}</td> |
33 |
< |
* <td>{@link Queue#offer offer(e)}</td> |
31 |
> |
* <th scope="row">Insert</th> |
32 |
> |
* <td>{@link #add(Object) add(e)}</td> |
33 |
> |
* <td>{@link #offer(Object) offer(e)}</td> |
34 |
|
* </tr> |
35 |
|
* <tr> |
36 |
< |
* <td><b>Remove</b></td> |
37 |
< |
* <td>{@link Queue#remove remove()}</td> |
38 |
< |
* <td>{@link Queue#poll poll()}</td> |
36 |
> |
* <th scope="row">Remove</th> |
37 |
> |
* <td>{@link #remove() remove()}</td> |
38 |
> |
* <td>{@link #poll() poll()}</td> |
39 |
|
* </tr> |
40 |
|
* <tr> |
41 |
< |
* <td><b>Examine</b></td> |
42 |
< |
* <td>{@link Queue#element element()}</td> |
43 |
< |
* <td>{@link Queue#peek peek()}</td> |
41 |
> |
* <th scope="row">Examine</th> |
42 |
> |
* <td>{@link #element() element()}</td> |
43 |
> |
* <td>{@link #peek() peek()}</td> |
44 |
|
* </tr> |
45 |
+ |
* </tbody> |
46 |
|
* </table> |
47 |
|
* |
48 |
|
* <p>Queues typically, but do not necessarily, order elements in a |
51 |
|
* comparator, or the elements' natural ordering, and LIFO queues (or |
52 |
|
* stacks) which order the elements LIFO (last-in-first-out). |
53 |
|
* Whatever the ordering used, the <em>head</em> of the queue is that |
54 |
< |
* element which would be removed by a call to {@link #remove() } or |
54 |
> |
* element which would be removed by a call to {@link #remove()} or |
55 |
|
* {@link #poll()}. In a FIFO queue, all new elements are inserted at |
56 |
|
* the <em>tail</em> of the queue. Other kinds of queues may use |
57 |
|
* different placement rules. Every {@code Queue} implementation |
98 |
|
* always well-defined for queues with the same elements but different |
99 |
|
* ordering properties. |
100 |
|
* |
98 |
– |
* |
101 |
|
* <p>This interface is a member of the |
102 |
< |
* <a href="{@docRoot}/../technotes/guides/collections/index.html"> |
102 |
> |
* <a href="{@docRoot}/java/util/package-summary.html#CollectionsFramework"> |
103 |
|
* Java Collections Framework</a>. |
104 |
|
* |
103 |
– |
* @see java.util.Collection |
104 |
– |
* @see LinkedList |
105 |
– |
* @see PriorityQueue |
106 |
– |
* @see java.util.concurrent.LinkedBlockingQueue |
107 |
– |
* @see java.util.concurrent.BlockingQueue |
108 |
– |
* @see java.util.concurrent.ArrayBlockingQueue |
109 |
– |
* @see java.util.concurrent.LinkedBlockingQueue |
110 |
– |
* @see java.util.concurrent.PriorityBlockingQueue |
105 |
|
* @since 1.5 |
106 |
|
* @author Doug Lea |
107 |
|
* @param <E> the type of elements held in this queue |
147 |
|
|
148 |
|
/** |
149 |
|
* Retrieves and removes the head of this queue. This method differs |
150 |
< |
* from {@link #poll poll} only in that it throws an exception if this |
151 |
< |
* queue is empty. |
150 |
> |
* from {@link #poll() poll()} only in that it throws an exception if |
151 |
> |
* this queue is empty. |
152 |
|
* |
153 |
|
* @return the head of this queue |
154 |
|
* @throws NoSuchElementException if this queue is empty |