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

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

Issue 18837002: Move toString() to collection classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Reupload Created 7 years, 5 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
« no previous file with comments | « runtime/lib/typed_data.dart ('k') | sdk/lib/_internal/lib/js_array.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // This is a hack to make @deprecated work in dart:io. Don't remove or use this, 8 // This is a hack to make @deprecated work in dart:io. Don't remove or use this,
9 // unless coordinated with either me or the core library team. Thanks! 9 // unless coordinated with either me or the core library team. Thanks!
10 // TODO(ajohnsen): Remove at the 11th of Auguest 2013. 10 // TODO(ajohnsen): Remove at the 11th of Auguest 2013.
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 abstract class BidirectionalIterator<T> implements Iterator<T> { 681 abstract class BidirectionalIterator<T> implements Iterator<T> {
682 bool movePrevious(); 682 bool movePrevious();
683 } 683 }
684 684
685 /** 685 /**
686 * This class provides default implementations for Iterables (including Lists). 686 * This class provides default implementations for Iterables (including Lists).
687 * 687 *
688 * The uses of this class will be replaced by mixins. 688 * The uses of this class will be replaced by mixins.
689 */ 689 */
690 class IterableMixinWorkaround { 690 class IterableMixinWorkaround {
691 // A list to identify cyclic collections during toString() calls.
692 static List _toStringList = new List();
693
691 static bool contains(Iterable iterable, var element) { 694 static bool contains(Iterable iterable, var element) {
692 for (final e in iterable) { 695 for (final e in iterable) {
693 if (e == element) return true; 696 if (e == element) return true;
694 } 697 }
695 return false; 698 return false;
696 } 699 }
697 700
698 static void forEach(Iterable iterable, void f(o)) { 701 static void forEach(Iterable iterable, void f(o)) {
699 for (final e in iterable) { 702 for (final e in iterable) {
700 f(e); 703 f(e);
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 } else { 877 } else {
875 buffer.write(list[0]); 878 buffer.write(list[0]);
876 for (int i = 1; i < list.length; i++) { 879 for (int i = 1; i < list.length; i++) {
877 buffer.write(separator); 880 buffer.write(separator);
878 buffer.write(list[i]); 881 buffer.write(list[i]);
879 } 882 }
880 } 883 }
881 return buffer.toString(); 884 return buffer.toString();
882 } 885 }
883 886
887 static String toStringIterable(Iterable iterable, String leftDelimiter,
888 String rightDelimiter) {
889 for (int i = 0; i < _toStringList.length; i++) {
890 if (identical(_toStringList[i], iterable)) {
891 return '$leftDelimiter...$rightDelimiter';
892 }
893 }
894
895 StringBuffer result = new StringBuffer();
896 try {
897 _toStringList.add(iterable);
898 result.write(leftDelimiter);
899 result.writeAll(iterable, ', ');
900 result.write(rightDelimiter);
901 } finally {
902 assert(identical(_toStringList.last, iterable));
903 _toStringList.removeLast();
904 }
905 return result.toString();
906 }
907
884 static Iterable where(Iterable iterable, bool f(var element)) { 908 static Iterable where(Iterable iterable, bool f(var element)) {
885 return new WhereIterable(iterable, f); 909 return new WhereIterable(iterable, f);
886 } 910 }
887 911
888 static Iterable map(Iterable iterable, f(var element)) { 912 static Iterable map(Iterable iterable, f(var element)) {
889 return new MappedIterable(iterable, f); 913 return new MappedIterable(iterable, f);
890 } 914 }
891 915
892 static Iterable mapList(List list, f(var element)) { 916 static Iterable mapList(List list, f(var element)) {
893 return new MappedListIterable(list, f); 917 return new MappedListIterable(list, f);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 1074
1051 static Set setDifference(Set set, Set other, Set result) { 1075 static Set setDifference(Set set, Set other, Set result) {
1052 for (var element in set) { 1076 for (var element in set) {
1053 if (!other.contains(element)) { 1077 if (!other.contains(element)) {
1054 result.add(element); 1078 result.add(element);
1055 } 1079 }
1056 } 1080 }
1057 return result; 1081 return result;
1058 } 1082 }
1059 } 1083 }
OLDNEW
« no previous file with comments | « runtime/lib/typed_data.dart ('k') | sdk/lib/_internal/lib/js_array.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698