OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 6 /** |
7 * An entry in a doubly linked list. It contains a pointer to the next | 7 * An entry in a doubly linked list. It contains a pointer to the next |
8 * entry, the previous entry, and the boxed element. | 8 * entry, the previous entry, and the boxed element. |
9 */ | 9 */ |
10 class DoubleLinkedQueueEntry<E> { | 10 class DoubleLinkedQueueEntry<E> { |
11 DoubleLinkedQueueEntry<E> _previous; | 11 DoubleLinkedQueueEntry<E> _previous; |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 DoubleLinkedQueueEntry<E> nextEntry = entry._next; | 224 DoubleLinkedQueueEntry<E> nextEntry = entry._next; |
225 if (f(entry._element)) other.addLast(entry._element); | 225 if (f(entry._element)) other.addLast(entry._element); |
226 entry = nextEntry; | 226 entry = nextEntry; |
227 } | 227 } |
228 return other; | 228 return other; |
229 } | 229 } |
230 | 230 |
231 _DoubleLinkedQueueIterator<E> iterator() { | 231 _DoubleLinkedQueueIterator<E> iterator() { |
232 return new _DoubleLinkedQueueIterator<E>(_sentinel); | 232 return new _DoubleLinkedQueueIterator<E>(_sentinel); |
233 } | 233 } |
| 234 |
| 235 String toString() { |
| 236 return Collections.collectionToString(this); |
| 237 } |
234 } | 238 } |
235 | 239 |
236 class _DoubleLinkedQueueIterator<E> implements Iterator<E> { | 240 class _DoubleLinkedQueueIterator<E> implements Iterator<E> { |
237 final _DoubleLinkedQueueEntrySentinel<E> _sentinel; | 241 final _DoubleLinkedQueueEntrySentinel<E> _sentinel; |
238 DoubleLinkedQueueEntry<E> _currentEntry; | 242 DoubleLinkedQueueEntry<E> _currentEntry; |
239 | 243 |
240 _DoubleLinkedQueueIterator(_DoubleLinkedQueueEntrySentinel this._sentinel) { | 244 _DoubleLinkedQueueIterator(_DoubleLinkedQueueEntrySentinel this._sentinel) { |
241 _currentEntry = _sentinel; | 245 _currentEntry = _sentinel; |
242 } | 246 } |
243 | 247 |
244 bool hasNext() { | 248 bool hasNext() { |
245 return _currentEntry._next !== _sentinel; | 249 return _currentEntry._next !== _sentinel; |
246 } | 250 } |
247 | 251 |
248 E next() { | 252 E next() { |
249 if (!hasNext()) { | 253 if (!hasNext()) { |
250 throw const NoMoreElementsException(); | 254 throw const NoMoreElementsException(); |
251 } | 255 } |
252 _currentEntry = _currentEntry._next; | 256 _currentEntry = _currentEntry._next; |
253 return _currentEntry.element; | 257 return _currentEntry.element; |
254 } | 258 } |
255 } | 259 } |
OLD | NEW |