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