16 |
|
* The <em>head</em> of the queue is that element that has been on the |
17 |
|
* queue the longest time. |
18 |
|
* The <em>tail</em> of the queue is that element that has been on the |
19 |
< |
* queue the shortest time. |
19 |
> |
* queue the shortest time. New elements |
20 |
> |
* are inserted at the tail of the queue, and the queue retrieval |
21 |
> |
* operations obtain elements at the head of the queue. |
22 |
|
* Linked queues typically have higher throughput than array-based queues but |
23 |
|
* less predictable performance in most concurrent applications. |
24 |
|
* |
182 |
|
add(it.next()); |
183 |
|
} |
184 |
|
|
183 |
– |
// Have to override just to update the javadoc |
184 |
– |
|
185 |
– |
/** |
186 |
– |
* Adds the specified element to the tail of this queue. |
187 |
– |
* @return <tt>true</tt> (as per the general contract of |
188 |
– |
* <tt>Collection.add</tt>). |
189 |
– |
* @throws IllegalStateException {@inheritDoc} |
190 |
– |
* @throws NullPointerException {@inheritDoc} |
191 |
– |
*/ |
192 |
– |
public boolean add(E o) { |
193 |
– |
return super.add(o); |
194 |
– |
} |
195 |
– |
|
196 |
– |
/** |
197 |
– |
* Adds all of the elements in the specified collection to this queue. |
198 |
– |
* The behavior of this operation is undefined if |
199 |
– |
* the specified collection is modified while the operation is in |
200 |
– |
* progress. (This implies that the behavior of this call is undefined if |
201 |
– |
* the specified collection is this queue, and this queue is nonempty.) |
202 |
– |
* <p> |
203 |
– |
* This implementation iterates over the specified collection, and adds |
204 |
– |
* each object returned by the iterator to this queue's tail, in turn. |
205 |
– |
* @throws IllegalStateException {@inheritDoc} |
206 |
– |
* @throws NullPointerException {@inheritDoc} |
207 |
– |
*/ |
208 |
– |
public boolean addAll(Collection<? extends E> c) { |
209 |
– |
return super.addAll(c); |
210 |
– |
} |
185 |
|
|
186 |
|
// this doc comment is overridden to remove the reference to collections |
187 |
|
// greater in size than Integer.MAX_VALUE |
188 |
|
/** |
189 |
< |
* Returns the number of elements in this collection. |
189 |
> |
* Returns the number of elements in this queue. |
190 |
> |
* |
191 |
> |
* @return the number of elements in this queue. |
192 |
|
*/ |
193 |
|
public int size() { |
194 |
|
return count.get(); |
211 |
|
return capacity - count.get(); |
212 |
|
} |
213 |
|
|
238 |
– |
/** |
239 |
– |
* Adds the specified element to the tail of this queue, waiting if |
240 |
– |
* necessary for space to become available. |
241 |
– |
* @throws NullPointerException {@inheritDoc} |
242 |
– |
*/ |
214 |
|
public void put(E o) throws InterruptedException { |
215 |
|
if (o == null) throw new NullPointerException(); |
216 |
|
// Note: convention in all put/take/etc is to preset |
245 |
|
signalNotEmpty(); |
246 |
|
} |
247 |
|
|
277 |
– |
/** |
278 |
– |
* Adds the specified element to the tail of this queue, waiting if |
279 |
– |
* necessary up to the specified wait time for space to become available. |
280 |
– |
* @throws NullPointerException {@inheritDoc} |
281 |
– |
*/ |
248 |
|
public boolean offer(E o, long timeout, TimeUnit unit) |
249 |
|
throws InterruptedException { |
250 |
|
|
282 |
|
* Adds the specified element to the tail of this queue if possible, |
283 |
|
* returning immediately if this queue is full. |
284 |
|
* |
285 |
< |
* @throws NullPointerException {@inheritDoc} |
285 |
> |
* @param o the element to add. |
286 |
> |
* @return <tt>true</tt> if it was possible to add the element to |
287 |
> |
* this queue, else <tt>false</tt> |
288 |
> |
* @throws NullPointerException if the specified element is <tt>null</tt> |
289 |
|
*/ |
290 |
|
public boolean offer(E o) { |
291 |
|
if (o == null) throw new NullPointerException(); |
402 |
|
} |
403 |
|
} |
404 |
|
|
436 |
– |
/** |
437 |
– |
* Removes a single instance of the specified element from this |
438 |
– |
* queue, if it is present. More formally, |
439 |
– |
* removes an element <tt>e</tt> such that <tt>(o==null ? e==null : |
440 |
– |
* o.equals(e))</tt>, if the queue contains one or more such |
441 |
– |
* elements. Returns <tt>true</tt> if the queue contained the |
442 |
– |
* specified element (or equivalently, if the queue changed as a |
443 |
– |
* result of the call). |
444 |
– |
* |
445 |
– |
*/ |
405 |
|
public boolean remove(Object o) { |
406 |
|
if (o == null) return false; |
407 |
|
boolean removed = false; |