| 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 /** | 5 /** |
| 6 * A [Queue] is a collection that can be manipulated at both ends. One | 6 * A [Queue] is a collection that can be manipulated at both ends. One |
| 7 * can iterate over the elements of a queue through [forEach] or with | 7 * can iterate over the elements of a queue through [forEach] or with |
| 8 * an [Iterator]. | 8 * an [Iterator]. |
| 9 */ | 9 */ |
| 10 abstract class Queue<E> extends Collection<E> { | 10 abstract class Queue<E> extends Collection<E> { |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 Queue other = new Queue(); | 284 Queue other = new Queue(); |
| 285 DoubleLinkedQueueEntry<E> entry = _sentinel._next; | 285 DoubleLinkedQueueEntry<E> entry = _sentinel._next; |
| 286 while (!identical(entry, _sentinel)) { | 286 while (!identical(entry, _sentinel)) { |
| 287 DoubleLinkedQueueEntry<E> nextEntry = entry._next; | 287 DoubleLinkedQueueEntry<E> nextEntry = entry._next; |
| 288 other.addLast(f(entry._element)); | 288 other.addLast(f(entry._element)); |
| 289 entry = nextEntry; | 289 entry = nextEntry; |
| 290 } | 290 } |
| 291 return other; | 291 return other; |
| 292 } | 292 } |
| 293 | 293 |
| 294 Dynamic reduce(Dynamic initialValue, | 294 dynamic reduce(dynamic initialValue, |
| 295 Dynamic combine(Dynamic previousValue, E element)) { | 295 dynamic combine(dynamic previousValue, E element)) { |
| 296 return Collections.reduce(this, initialValue, combine); | 296 return Collections.reduce(this, initialValue, combine); |
| 297 } | 297 } |
| 298 | 298 |
| 299 Queue<E> filter(bool f(E element)) { | 299 Queue<E> filter(bool f(E element)) { |
| 300 Queue<E> other = new Queue<E>(); | 300 Queue<E> other = new Queue<E>(); |
| 301 DoubleLinkedQueueEntry<E> entry = _sentinel._next; | 301 DoubleLinkedQueueEntry<E> entry = _sentinel._next; |
| 302 while (!identical(entry, _sentinel)) { | 302 while (!identical(entry, _sentinel)) { |
| 303 DoubleLinkedQueueEntry<E> nextEntry = entry._next; | 303 DoubleLinkedQueueEntry<E> nextEntry = entry._next; |
| 304 if (f(entry._element)) other.addLast(entry._element); | 304 if (f(entry._element)) other.addLast(entry._element); |
| 305 entry = nextEntry; | 305 entry = nextEntry; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 329 } | 329 } |
| 330 | 330 |
| 331 E next() { | 331 E next() { |
| 332 if (!hasNext) { | 332 if (!hasNext) { |
| 333 throw new StateError("No more elements"); | 333 throw new StateError("No more elements"); |
| 334 } | 334 } |
| 335 _currentEntry = _currentEntry._next; | 335 _currentEntry = _currentEntry._next; |
| 336 return _currentEntry.element; | 336 return _currentEntry.element; |
| 337 } | 337 } |
| 338 } | 338 } |
| OLD | NEW |