Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Unified Diff: sdk/lib/core/queue.dart

Issue 11410086: Use iterator, moveNext(), current. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Address comments. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/core/queue.dart
diff --git a/sdk/lib/core/queue.dart b/sdk/lib/core/queue.dart
index acb9c04772288b33dd835a5b274e0ef4f53cef79..15ebed34fb3d6790a161311d6285dc9761b30ec1 100644
--- a/sdk/lib/core/queue.dart
+++ b/sdk/lib/core/queue.dart
@@ -307,7 +307,7 @@ class DoubleLinkedQueue<E> implements Queue<E> {
return other;
}
- _DoubleLinkedQueueIterator<E> iterator() {
+ _DoubleLinkedQueueIterator<E> get iterator {
return new _DoubleLinkedQueueIterator<E>(_sentinel);
}
@@ -318,21 +318,24 @@ class DoubleLinkedQueue<E> implements Queue<E> {
class _DoubleLinkedQueueIterator<E> implements Iterator<E> {
final _DoubleLinkedQueueEntrySentinel<E> _sentinel;
- DoubleLinkedQueueEntry<E> _currentEntry;
+ DoubleLinkedQueueEntry<E> _currentEntry = null;
- _DoubleLinkedQueueIterator(_DoubleLinkedQueueEntrySentinel this._sentinel) {
- _currentEntry = _sentinel;
- }
+ _DoubleLinkedQueueIterator(this._sentinel);
- bool get hasNext {
- return !identical(_currentEntry._next, _sentinel);
+ bool moveNext() {
+ // [:null:] means that the iterator hasn't moved yet.
+ // When it is set to the sentinel, then it is at the end.
+ if (identical(_currentEntry, _sentinel)) return false;
+ if (_currentEntry == null) _currentEntry = _sentinel;
+ _currentEntry = _currentEntry._next;
+ return !identical(_currentEntry, _sentinel);
}
- E next() {
- if (!hasNext) {
- throw new StateError("No more elements");
+ E get current {
+ if (_currentEntry != null && !identical(_currentEntry, _sentinel)) {
+ return _currentEntry.element;
}
- _currentEntry = _currentEntry._next;
- return _currentEntry.element;
+ // TODO(floitsch): adapt error message.
+ throw new StateError("No more elements");
}
}

Powered by Google App Engine
This is Rietveld 408576698