27 |
|
* |
28 |
|
* @since 1.5 |
29 |
|
* @author Doug Lea |
30 |
+ |
* @param <E> the type of elements held in this collection |
31 |
|
*/ |
32 |
|
public abstract class AbstractQueue<E> |
33 |
|
extends AbstractCollection<E> |
102 |
|
while (poll() != null) |
103 |
|
; |
104 |
|
} |
105 |
+ |
|
106 |
+ |
/** |
107 |
+ |
* Adds all of the elements in the specified collection to this |
108 |
+ |
* queue. Attempts to addAll of a queue to itself result in |
109 |
+ |
* <tt>IllegalArgumentException</tt>. Further, the behavior of |
110 |
+ |
* this operation is undefined if the specified collection is |
111 |
+ |
* modified while the operation is in progress. |
112 |
+ |
* |
113 |
+ |
* <p>This implementation iterates over the specified collection, |
114 |
+ |
* and adds each element returned by the iterator to this |
115 |
+ |
* collection, in turn. A runtime exception encountered while |
116 |
+ |
* trying to add an element (including, in particular, a |
117 |
+ |
* <tt>null</tt> element) may result in only some of the elements |
118 |
+ |
* having been successfully added when the associated exception is |
119 |
+ |
* thrown. |
120 |
+ |
* |
121 |
+ |
* @param c collection whose elements are to be added to this collection. |
122 |
+ |
* @return <tt>true</tt> if this collection changed as a result of the |
123 |
+ |
* call. |
124 |
+ |
* @throws NullPointerException if the specified collection, or |
125 |
+ |
* any of its elements are null. |
126 |
+ |
* @throws IllegalArgumentException if c is this queue. |
127 |
+ |
* |
128 |
+ |
* @see #add(Object) |
129 |
+ |
*/ |
130 |
+ |
public boolean addAll(Collection<? extends E> c) { |
131 |
+ |
if (c == null) |
132 |
+ |
throw new NullPointerException(); |
133 |
+ |
if (c == this) |
134 |
+ |
throw new IllegalArgumentException(); |
135 |
+ |
boolean modified = false; |
136 |
+ |
Iterator<? extends E> e = c.iterator(); |
137 |
+ |
while (e.hasNext()) { |
138 |
+ |
if (add(e.next())) |
139 |
+ |
modified = true; |
140 |
+ |
} |
141 |
+ |
return modified; |
142 |
+ |
} |
143 |
+ |
|
144 |
|
} |