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

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

Issue 745573002: Create generic check methods for RangeError causing checks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix long line Created 6 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
« no previous file with comments | « sdk/lib/async/stream.dart ('k') | sdk/lib/collection/list.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/collection/iterable.dart
diff --git a/sdk/lib/collection/iterable.dart b/sdk/lib/collection/iterable.dart
index 36a1efd9201313e1b0d720fd0c49452125ed08da..22698195763f08b01f423ac5f95c37e9583c25ed 100644
--- a/sdk/lib/collection/iterable.dart
+++ b/sdk/lib/collection/iterable.dart
@@ -186,15 +186,17 @@ abstract class IterableMixin<E> implements Iterable<E> {
}
E elementAt(int index) {
- if (index is! int || index < 0) throw new RangeError.value(index);
- int remaining = index;
+ if (index is! int) throw new ArgumentError.notNull("index");
+ RangeError.checkNotNegative(index, "index");
+ int elementIndex = 0;
for (E element in this) {
- if (remaining == 0) return element;
- remaining--;
+ if (index == elementIndex) return element;
+ elementIndex++;
}
- throw new RangeError.value(index);
+ throw new RangeError.index(index, this, "index", null, elementIndex);
}
+
String toString() => IterableBase.iterableToShortString(this, '(', ')');
}
@@ -380,13 +382,14 @@ abstract class IterableBase<E> implements Iterable<E> {
}
E elementAt(int index) {
- if (index is! int || index < 0) throw new RangeError.value(index);
- int remaining = index;
+ if (index is! int) throw new ArgumentError.notNull("index");
+ RangeError.checkNotNegative(index, "index");
+ int elementIndex = 0;
for (E element in this) {
- if (remaining == 0) return element;
- remaining--;
+ if (index == elementIndex) return element;
+ elementIndex++;
}
- throw new RangeError.value(index);
+ throw new RangeError.index(index, this, "index", null, elementIndex);
}
/**
« no previous file with comments | « sdk/lib/async/stream.dart ('k') | sdk/lib/collection/list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698