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

Side by Side Diff: sdk/lib/_collection_dev/iterable.dart

Issue 14246008: Allow Object when doing lookups. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix type error. Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart._collection.dev; 5 part of dart._collection.dev;
6 6
7 /** 7 /**
8 * An [Iterable] for classes that have efficient [length] and [elementAt]. 8 * An [Iterable] for classes that have efficient [length] and [elementAt].
9 * 9 *
10 * All other methods are implemented in terms of [length] and [elementAt], 10 * All other methods are implemented in terms of [length] and [elementAt],
(...skipping 28 matching lines...) Expand all
39 if (length == 0) throw new StateError("No elements"); 39 if (length == 0) throw new StateError("No elements");
40 return elementAt(length - 1); 40 return elementAt(length - 1);
41 } 41 }
42 42
43 E get single { 43 E get single {
44 if (length == 0) throw new StateError("No elements"); 44 if (length == 0) throw new StateError("No elements");
45 if (length > 1) throw new StateError("Too many elements"); 45 if (length > 1) throw new StateError("Too many elements");
46 return elementAt(0); 46 return elementAt(0);
47 } 47 }
48 48
49 bool contains(E element) { 49 bool contains(Object element) {
50 int length = this.length; 50 int length = this.length;
51 for (int i = 0; i < length; i++) { 51 for (int i = 0; i < length; i++) {
52 if (elementAt(i) == element) return true; 52 if (elementAt(i) == element) return true;
53 if (length != this.length) { 53 if (length != this.length) {
54 throw new ConcurrentModificationError(this); 54 throw new ConcurrentModificationError(this);
55 } 55 }
56 } 56 }
57 return false; 57 return false;
58 } 58 }
59 59
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 int get length => 0; 601 int get length => 0;
602 602
603 E get first { throw new StateError("No elements"); } 603 E get first { throw new StateError("No elements"); }
604 604
605 E get last { throw new StateError("No elements"); } 605 E get last { throw new StateError("No elements"); }
606 606
607 E get single { throw new StateError("No elements"); } 607 E get single { throw new StateError("No elements"); }
608 608
609 E elementAt(int index) { throw new RangeError.value(index); } 609 E elementAt(int index) { throw new RangeError.value(index); }
610 610
611 bool contains(E element) => false; 611 bool contains(Object element) => false;
612 612
613 bool every(bool test(E element)) => true; 613 bool every(bool test(E element)) => true;
614 614
615 bool any(bool test(E element)) => false; 615 bool any(bool test(E element)) => false;
616 616
617 E firstWhere(bool test(E element), { E orElse() }) { 617 E firstWhere(bool test(E element), { E orElse() }) {
618 if (orElse != null) return orElse(); 618 if (orElse != null) return orElse();
619 throw new StateError("No matching element"); 619 throw new StateError("No matching element");
620 } 620 }
621 621
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 1036
1037 static Set setDifference(Set set, Set other, Set result) { 1037 static Set setDifference(Set set, Set other, Set result) {
1038 for (var element in set) { 1038 for (var element in set) {
1039 if (!other.contains(element)) { 1039 if (!other.contains(element)) {
1040 result.add(element); 1040 result.add(element);
1041 } 1041 }
1042 } 1042 }
1043 return result; 1043 return result;
1044 } 1044 }
1045 } 1045 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698