9 |
|
/** |
10 |
|
* This class provides skeletal implementations of some {@link Queue} |
11 |
|
* operations. The implementations in this class are appropriate when |
12 |
< |
* the base implementation does <em>not</em> allow <tt>null</tt> |
12 |
> |
* the base implementation does <em>not</em> allow {@code null} |
13 |
|
* elements. Methods {@link #add add}, {@link #remove remove}, and |
14 |
|
* {@link #element element} are based on {@link #offer offer}, {@link |
15 |
|
* #poll poll}, and {@link #peek peek}, respectively, but throw |
16 |
< |
* exceptions instead of indicating failure via <tt>false</tt> or |
17 |
< |
* <tt>null</tt> returns. |
16 |
> |
* exceptions instead of indicating failure via {@code false} or |
17 |
> |
* {@code null} returns. |
18 |
|
* |
19 |
< |
* <p>A <tt>Queue</tt> implementation that extends this class must |
19 |
> |
* <p>A {@code Queue} implementation that extends this class must |
20 |
|
* minimally define a method {@link Queue#offer} which does not permit |
21 |
< |
* insertion of <tt>null</tt> elements, along with methods {@link |
21 |
> |
* insertion of {@code null} elements, along with methods {@link |
22 |
|
* Queue#peek}, {@link Queue#poll}, {@link Collection#size}, and |
23 |
|
* {@link Collection#iterator}. Typically, additional methods will be |
24 |
|
* overridden as well. If these requirements cannot be met, consider |
45 |
|
/** |
46 |
|
* Inserts the specified element into this queue if it is possible to do so |
47 |
|
* immediately without violating capacity restrictions, returning |
48 |
< |
* <tt>true</tt> upon success and throwing an <tt>IllegalStateException</tt> |
48 |
> |
* {@code true} upon success and throwing an {@code IllegalStateException} |
49 |
|
* if no space is currently available. |
50 |
|
* |
51 |
< |
* <p>This implementation returns <tt>true</tt> if <tt>offer</tt> succeeds, |
52 |
< |
* else throws an <tt>IllegalStateException</tt>. |
51 |
> |
* <p>This implementation returns {@code true} if {@code offer} succeeds, |
52 |
> |
* else throws an {@code IllegalStateException}. |
53 |
|
* |
54 |
|
* @param e the element to add |
55 |
< |
* @return <tt>true</tt> (as specified by {@link Collection#add}) |
55 |
> |
* @return {@code true} (as specified by {@link Collection#add}) |
56 |
|
* @throws IllegalStateException if the element cannot be added at this |
57 |
|
* time due to capacity restrictions |
58 |
|
* @throws ClassCastException if the class of the specified element |
74 |
|
* from {@link #poll poll} only in that it throws an exception if this |
75 |
|
* queue is empty. |
76 |
|
* |
77 |
< |
* <p>This implementation returns the result of <tt>poll</tt> |
77 |
> |
* <p>This implementation returns the result of {@code poll} |
78 |
|
* unless the queue is empty. |
79 |
|
* |
80 |
|
* @return the head of this queue |
93 |
|
* differs from {@link #peek peek} only in that it throws an exception if |
94 |
|
* this queue is empty. |
95 |
|
* |
96 |
< |
* <p>This implementation returns the result of <tt>peek</tt> |
96 |
> |
* <p>This implementation returns the result of {@code peek} |
97 |
|
* unless the queue is empty. |
98 |
|
* |
99 |
|
* @return the head of this queue |
112 |
|
* The queue will be empty after this call returns. |
113 |
|
* |
114 |
|
* <p>This implementation repeatedly invokes {@link #poll poll} until it |
115 |
< |
* returns <tt>null</tt>. |
115 |
> |
* returns {@code null}. |
116 |
|
*/ |
117 |
|
public void clear() { |
118 |
|
while (poll() != null) |
122 |
|
/** |
123 |
|
* Adds all of the elements in the specified collection to this |
124 |
|
* queue. Attempts to addAll of a queue to itself result in |
125 |
< |
* <tt>IllegalArgumentException</tt>. Further, the behavior of |
125 |
> |
* {@code IllegalArgumentException}. Further, the behavior of |
126 |
|
* this operation is undefined if the specified collection is |
127 |
|
* modified while the operation is in progress. |
128 |
|
* |
130 |
|
* and adds each element returned by the iterator to this |
131 |
|
* queue, in turn. A runtime exception encountered while |
132 |
|
* trying to add an element (including, in particular, a |
133 |
< |
* <tt>null</tt> element) may result in only some of the elements |
133 |
> |
* {@code null} element) may result in only some of the elements |
134 |
|
* having been successfully added when the associated exception is |
135 |
|
* thrown. |
136 |
|
* |
137 |
|
* @param c collection containing elements to be added to this queue |
138 |
< |
* @return <tt>true</tt> if this queue changed as a result of the call |
138 |
> |
* @return {@code true} if this queue changed as a result of the call |
139 |
|
* @throws ClassCastException if the class of an element of the specified |
140 |
|
* collection prevents it from being added to this queue |
141 |
|
* @throws NullPointerException if the specified collection contains a |