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

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

Issue 315173005: Add "last" setter to List. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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
Index: sdk/lib/collection/list.dart
diff --git a/sdk/lib/collection/list.dart b/sdk/lib/collection/list.dart
index b6e1a11b66e2882ebfc6701a9ecaf54787d7a460..6b1ad17ff2e61bc46932c00a1883a00870abdc04 100644
--- a/sdk/lib/collection/list.dart
+++ b/sdk/lib/collection/list.dart
@@ -70,18 +70,23 @@ abstract class ListMixin<E> implements List<E> {
bool get isNotEmpty => !isEmpty;
E get first {
- if (length == 0) throw new StateError("No elements");
+ if (length == 0) throw IterableElementError.noElement();
return this[0];
}
E get last {
- if (length == 0) throw new StateError("No elements");
+ if (length == 0) throw IterableElementError.noElement();
return this[length - 1];
}
+ void set last(E value) {
+ if (length == 0) throw IterableElementError.noElement();
+ this[length - 1] = value;
+ }
+
E get single {
- if (length == 0) throw new StateError("No elements");
- if (length > 1) throw new StateError("Too many elements");
+ if (length == 0) throw IterableElementError.noElement();
+ if (length > 1) throw IterableElementError.tooMany();
return this[0];
}
@@ -128,7 +133,7 @@ abstract class ListMixin<E> implements List<E> {
}
}
if (orElse != null) return orElse();
- throw new StateError("No matching element");
+ throw IterableElementError.noElement();
}
dynamic lastWhere(bool test(E element), { Object orElse() }) {
@@ -141,7 +146,7 @@ abstract class ListMixin<E> implements List<E> {
}
}
if (orElse != null) return orElse();
- throw new StateError("No matching element");
+ throw IterableElementError.noElement();
}
E singleWhere(bool test(E element)) {
@@ -152,7 +157,7 @@ abstract class ListMixin<E> implements List<E> {
E element = this[i];
if (test(element)) {
if (matchFound) {
- throw new StateError("More than one matching element");
+ throw IterableElementError.tooMany();
}
matchFound = true;
match = element;
@@ -162,7 +167,7 @@ abstract class ListMixin<E> implements List<E> {
}
}
if (matchFound) return match;
- throw new StateError("No matching element");
+ throw IterableElementError.noElement();
}
String join([String separator = ""]) {
@@ -179,7 +184,7 @@ abstract class ListMixin<E> implements List<E> {
new ExpandIterable<E, dynamic>(this, f);
E reduce(E combine(E previousValue, E element)) {
- if (length == 0) throw new StateError("No elements");
+ if (length == 0) throw IterableElementError.noElement();
E value = this[0];
for (int i = 1; i < length; i++) {
value = combine(value, this[i]);
@@ -288,7 +293,7 @@ abstract class ListMixin<E> implements List<E> {
E removeLast() {
if (length == 0) {
- throw new StateError("No elements");
+ throw IterableElementError.noElement();
}
E result = this[length - 1];
length--;
@@ -376,7 +381,7 @@ abstract class ListMixin<E> implements List<E> {
otherStart = 0;
}
if (otherStart + length > otherList.length) {
- throw new StateError("Not enough elements");
+ throw IterableElementError.noElement();
}
if (otherStart < start) {
// Copy backwards to ensure correct copy if [from] is this.

Powered by Google App Engine
This is Rietveld 408576698