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

Unified Diff: sdk/lib/html/templates/html/impl/impl_Element.darttemplate

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/html/templates/html/impl/impl_Element.darttemplate
diff --git a/sdk/lib/html/templates/html/impl/impl_Element.darttemplate b/sdk/lib/html/templates/html/impl/impl_Element.darttemplate
index 0be29f58908798e2a977c284f95671c243dbacb5..5700dfd5308fd5931a2776f29f1eda401495a122 100644
--- a/sdk/lib/html/templates/html/impl/impl_Element.darttemplate
+++ b/sdk/lib/html/templates/html/impl/impl_Element.darttemplate
@@ -95,7 +95,7 @@ class _ChildrenElementList implements List {
Element addLast(Element value) => add(value);
- Iterator<Element> iterator() => _toList().iterator();
+ Iterator<Element> get iterator => _toList().iterator;
void addAll(Collection<Element> collection) {
for (Element element in collection) {
@@ -232,7 +232,7 @@ class _FrozenElementList implements List {
throw new UnsupportedError('');
}
- Iterator<Element> iterator() => new _FrozenElementListIterator(this);
+ Iterator<Element> get iterator => new _FrozenElementListIterator(this);
void addAll(Collection<Element> collection) {
throw new UnsupportedError('');
@@ -281,21 +281,29 @@ class _FrozenElementListIterator implements Iterator<Element> {
_FrozenElementListIterator(this._list);
/**
- * Gets the next element in the iteration. Throws a
- * [StateError("No more elements")] if no element is left.
+ * Moves to the next element. Returns true if the iterator is positioned
+ * at an element. Returns false if it is positioned after the last element.
*/
- Element next() {
- if (!hasNext) {
- throw new StateError("No more elements");
- }
-
- return _list[_index++];
+ bool moveNext() {
+ _index++;
+ if (_index < _list.length) return true;
+ _index = _list.length;
+ return false;
}
/**
- * Returns whether the [Iterator] has elements left.
+ * Returns the element the [Iterator] is positioned at.
+ *
+ * Throws a [StateError] if the iterator is positioned before the first, or
+ * after the last element.
*/
- bool get hasNext => _index < _list.length;
+ bool get current {
+ if (0 <= _index && _index < _list.length) {
+ return _list[_index];
+ }
+ // TODO(floitsch): adapt the error message.
+ throw new StateError("No more elements");
+ }
}
/**

Powered by Google App Engine
This is Rietveld 408576698