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

Unified Diff: sdk/lib/collection/iterator.dart

Issue 11867024: Move some core classes to collection library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update status files with bug number. Created 7 years, 11 months 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
« no previous file with comments | « sdk/lib/collection/collection_sources.gypi ('k') | sdk/lib/collection/map.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/collection/iterator.dart
diff --git a/sdk/lib/collection/iterator.dart b/sdk/lib/collection/iterator.dart
new file mode 100644
index 0000000000000000000000000000000000000000..1fe49cd2dc4d1ea84e27e2d2cbed7a9d7ae3003f
--- /dev/null
+++ b/sdk/lib/collection/iterator.dart
@@ -0,0 +1,45 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+part of dart.collection;
+
+/**
+ * The [HasNextIterator] class wraps an [Iterator] and provides methods to
+ * iterate over an object using `hasNext` and `next`.
+ *
+ * An [HasNextIterator] does not implement the [Iterator] interface.
+ */
+class HasNextIterator<E> {
+ static const int _HAS_NEXT_AND_NEXT_IN_CURRENT = 0;
+ static const int _NO_NEXT = 1;
+ static const int _NOT_MOVED_YET = 2;
+
+ Iterator _iterator;
+ int _state = _NOT_MOVED_YET;
+
+ HasNextIterator(this._iterator);
+
+ bool get hasNext {
+ if (_state == _NOT_MOVED_YET) _move();
+ return _state == _HAS_NEXT_AND_NEXT_IN_CURRENT;
+ }
+
+ E next() {
+ // Call to hasNext is necessary to make sure we are positioned at the first
+ // element when we start iterating.
+ if (!hasNext) throw new StateError("No more elements");
+ assert(_state == _HAS_NEXT_AND_NEXT_IN_CURRENT);
+ E result = _iterator.current;
+ _move();
+ return result;
+ }
+
+ void _move() {
+ if (_iterator.moveNext()) {
+ _state = _HAS_NEXT_AND_NEXT_IN_CURRENT;
+ } else {
+ _state = _NO_NEXT;
+ }
+ }
+}
« no previous file with comments | « sdk/lib/collection/collection_sources.gypi ('k') | sdk/lib/collection/map.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698