7 |
|
package java.util; |
8 |
|
|
9 |
|
/** |
10 |
< |
* <tt>AbstractQueue</tt> provides default implementations of |
11 |
< |
* {@link #add add}, {@link #remove remove}, and {@link #element element} |
12 |
< |
* based on |
13 |
< |
* {@link #offer offer}, {@link #poll poll}, and {@link #peek peek}, |
14 |
< |
* respectively but that |
15 |
< |
* throw exceptions instead of indicating failure via <tt>false</tt> or |
10 |
> |
* <tt>AbstractQueue</tt> provides default implementations of |
11 |
> |
* {@link #add add}, {@link #remove remove}, and {@link #element element} |
12 |
> |
* based on |
13 |
> |
* {@link #offer offer}, {@link #poll poll}, and {@link #peek peek}, |
14 |
> |
* respectively but that |
15 |
> |
* throw exceptions instead of indicating failure via <tt>false</tt> or |
16 |
|
* <tt>null</tt> returns. |
17 |
|
* <p>The provided implementations all assume that the base implementation |
18 |
|
* does <em>not</em> allow <tt>null</tt> elements. |
19 |
|
* @since 1.5 |
20 |
|
* @author Doug Lea |
21 |
|
*/ |
22 |
< |
public abstract class AbstractQueue<E> |
23 |
< |
extends AbstractCollection<E> |
22 |
> |
public abstract class AbstractQueue<E> |
23 |
> |
extends AbstractCollection<E> |
24 |
|
implements Queue<E> { |
25 |
|
|
26 |
|
// note that optional methods are not optional here or in our subclasses, |
28 |
|
// We also inherit, or define, all necessary @throws comments |
29 |
|
|
30 |
|
/** |
31 |
+ |
* @throws NullPointerException if the specified element is <tt>null</tt> |
32 |
+ |
*/ |
33 |
+ |
public abstract boolean offer(E o); |
34 |
+ |
|
35 |
+ |
/** |
36 |
|
* Adds the specified element to this queue. |
37 |
< |
* @return <tt>true</tt> (as per the general contract of |
37 |
> |
* @return <tt>true</tt> (as per the general contract of |
38 |
|
* <tt>Collection.add</tt>). |
39 |
|
* |
40 |
< |
* @throws NullPointerException if the element is null |
40 |
> |
* @throws NullPointerException if the specified element is <tt>null</tt> |
41 |
|
*/ |
42 |
|
public boolean add(E o) { |
43 |
|
if (offer(o)) |
54 |
|
* the specified collection is this queue, and this queue is nonempty.) |
55 |
|
* <p> |
56 |
|
* This implementation iterates over the specified collection, and adds |
57 |
< |
* each object returned by the iterator to this collection, in turn. |
57 |
> |
* each object returned by the iterator to this queue, in turn. |
58 |
|
* |
59 |
|
* @param c collection whose elements are to be added to this queue |
60 |
|
* @return <tt>true</tt> if this collection changed as a result of the |
61 |
|
* call. |
62 |
< |
* @throws NullPointerException if <tt>c</tt> is <tt>null</tt> |
62 |
> |
* @throws NullPointerException if <tt>c</tt> or any element in <tt>c</tt> |
63 |
> |
* is <tt>null</tt> |
64 |
|
* |
65 |
|
*/ |
66 |
< |
boolean addAll(Collection<? extends E> c) { |
66 |
> |
public boolean addAll(Collection<? extends E> c) { |
67 |
|
return super.addAll(c); |
68 |
|
} |
69 |
|
|