25 |
|
* in fixed-capacity (or “bounded”) 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>. |
28 |
> |
* <p>The {@link #remove()} and {@link #poll()} methods remove and |
29 |
> |
* return an element in accord with the implementation's ordering |
30 |
> |
* policy. Exactly which element is removed from the queue is a |
31 |
> |
* function of the queue's ordering policy, which differs from |
32 |
> |
* implementation to implementation. Possible orderings include (but |
33 |
> |
* are not limited to) first-in-first-out (FIFO), last-in-first-out |
34 |
> |
* (LIFO), element priority, and arbitrary. The <tt>remove()</tt> and |
35 |
> |
* <tt>poll()</tt> methods differ only in their behavior when the |
36 |
> |
* queue is empty: the <tt>remove()</tt> method throws an exception, |
37 |
> |
* while the <tt>poll()</tt> method returns <tt>null</tt>. |
38 |
|
* |
39 |
|
* <p>The {@link #element()} and {@link #peek()} methods return but do |
40 |
|
* not delete the element that would be obtained by a call to |
46 |
|
* defined in the {@link java.util.concurrent.BlockingQueue} interface, which |
47 |
|
* extends this interface. |
48 |
|
* |
49 |
< |
* <p><tt>Queue</tt> implementations generally do not allow insertion of |
50 |
< |
* <tt>null</tt> elements, although some implementations, such as |
49 |
> |
* <p><tt>Queue</tt> implementations generally do not allow insertion |
50 |
> |
* of <tt>null</tt> elements, although some implementations, such as |
51 |
|
* {@link LinkedList}, do not prohibit insertion of <tt>null</tt>. |
52 |
< |
* Even in the implementations that permit it, <tt>null</tt> should not be inserted into |
53 |
< |
* a <tt>Queue</tt>, as <tt>null</tt> is also used as a special return value |
54 |
< |
* by the <tt>poll</tt> method to indicate that the queue contains no |
55 |
< |
* elements. |
52 |
> |
* Even in the implementations that permit it, <tt>null</tt> should |
53 |
> |
* not be inserted into a <tt>Queue</tt>, as <tt>null</tt> is also |
54 |
> |
* used as a special return value by the <tt>poll</tt> method to |
55 |
> |
* indicate that the queue contains no elements. |
56 |
|
* |
57 |
|
* <p>This interface is a member of the |
58 |
|
* <a href="{@docRoot}/../guide/collections/index.html"> |
66 |
|
* @see java.util.concurrent.ArrayBlockingQueue |
67 |
|
* @see java.util.concurrent.LinkedBlockingQueue |
68 |
|
* @see java.util.concurrent.PriorityBlockingQueue |
69 |
+ |
* @since 1.5 |
70 |
+ |
* @author Doug Lea |
71 |
|
*/ |
72 |
|
public interface Queue<E> extends Collection<E> { |
73 |
|
/** |
76 |
|
* @param element the element to add. |
77 |
|
* @return true if it was possible to add the element to the queue. |
78 |
|
*/ |
79 |
< |
public boolean offer(E element); |
79 |
> |
boolean offer(E element); |
80 |
|
|
81 |
|
/** |
82 |
|
* Remove and return an element from the queue if one is available. |
84 |
|
* @return an element previously on the queue, or <tt>null</tt> if the |
85 |
|
* queue is empty. |
86 |
|
*/ |
87 |
< |
public E poll(); |
87 |
> |
E poll(); |
88 |
|
|
89 |
|
/** |
90 |
|
* Remove and return an element from the queue. This method differs |
94 |
|
* @return an element previously on the queue. |
95 |
|
* @throws NoSuchElementException if the queue is empty. |
96 |
|
*/ |
97 |
< |
public E remove() throws NoSuchElementException; |
97 |
> |
E remove() throws NoSuchElementException; |
98 |
|
|
99 |
|
/** |
100 |
|
* Return, but do not remove, an element from the queue, or <tt>null</tt> |
104 |
|
* |
105 |
|
* @return an element on the queue, or <tt>null</tt> if the queue is empty. |
106 |
|
*/ |
107 |
< |
public E peek(); |
107 |
> |
E peek(); |
108 |
|
|
109 |
|
/** |
110 |
|
* Return, but do not remove, an element from the queue. This method |
114 |
|
* @return an element on the queue. |
115 |
|
* @throws NoSuchElementException if the queue is empty. |
116 |
|
*/ |
117 |
< |
public E element() throws NoSuchElementException; |
117 |
> |
E element() throws NoSuchElementException; |
118 |
|
} |