OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart.core; | 5 part of dart.core; |
6 | 6 |
7 /** | 7 /** |
8 * A [Queue] is a collection that can be manipulated at both ends. One | 8 * A [Queue] is a collection that can be manipulated at both ends. One |
9 * can iterate over the elements of a queue through [forEach] or with | 9 * can iterate over the elements of a queue through [forEach] or with |
10 * an [Iterator]. | 10 * an [Iterator]. |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 } | 194 } |
195 | 195 |
196 E removeLast() { | 196 E removeLast() { |
197 return _sentinel._previous.remove(); | 197 return _sentinel._previous.remove(); |
198 } | 198 } |
199 | 199 |
200 E removeFirst() { | 200 E removeFirst() { |
201 return _sentinel._next.remove(); | 201 return _sentinel._next.remove(); |
202 } | 202 } |
203 | 203 |
204 void remove(Object o) { | |
205 DoubleLinkedQueueEntry<E> entry = firstEntry(); | |
206 while (!identical(entry, _sentinel)) { | |
207 if (entry.element == o) { | |
208 entry.remove(); | |
209 return; | |
210 } | |
211 entry = entry._next; | |
212 } | |
213 } | |
214 | |
215 void removeAll(Iterable elements) { | |
floitsch
2013/01/17 13:36:58
If Collection provides default implementations, th
Lasse Reichstein Nielsen
2013/01/18 11:41:48
This implementation is not the default implementat
| |
216 Set set; | |
217 if (elements is Set) { | |
218 set = elements; | |
219 } else { | |
220 set = elements.toSet(); | |
221 } | |
222 removeMatching(set.contains); | |
223 } | |
224 | |
225 void retainAll(Iterable elements) { | |
floitsch
2013/01/17 13:36:58
ditto.
Lasse Reichstein Nielsen
2013/01/18 11:41:48
This one is the same as the default, so it can be
| |
226 Set set; | |
227 if (elements is Set) { | |
228 set = elements; | |
229 } else { | |
230 set = elements.toSet(); | |
231 } | |
232 retainMatching(set.contains); | |
233 } | |
234 | |
235 void removeMatching(bool test(E element)) { | |
236 DoubleLinkedQueueEntry<E> entry = firstEntry(); | |
237 while (!identical(entry, _sentinel)) { | |
238 DoubleLinkedQueueEntry<E> next = entry._next; | |
239 if (test(entry.element)) { | |
240 entry.remove(); | |
241 } | |
242 entry = next; | |
243 } | |
244 } | |
245 | |
246 void retainMatching(bool test(E element)) { | |
247 DoubleLinkedQueueEntry<E> entry = firstEntry(); | |
248 while (!identical(entry, _sentinel)) { | |
249 DoubleLinkedQueueEntry<E> next = entry._next; | |
250 if (!test(entry.element)) { | |
251 entry.remove(); | |
252 } | |
253 entry = next; | |
254 } | |
255 } | |
256 | |
204 E get first { | 257 E get first { |
205 return _sentinel._next.element; | 258 return _sentinel._next.element; |
206 } | 259 } |
207 | 260 |
208 E get last { | 261 E get last { |
209 return _sentinel._previous.element; | 262 return _sentinel._previous.element; |
210 } | 263 } |
211 | 264 |
212 E get single { | 265 E get single { |
213 // Note that this also covers the case where the queue is empty. | 266 // Note that this also covers the case where the queue is empty. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 _current = null; | 325 _current = null; |
273 _sentinel = null; | 326 _sentinel = null; |
274 return false; | 327 return false; |
275 } | 328 } |
276 _current = _currentEntry.element; | 329 _current = _currentEntry.element; |
277 return true; | 330 return true; |
278 } | 331 } |
279 | 332 |
280 E get current => _current; | 333 E get current => _current; |
281 } | 334 } |
OLD | NEW |