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

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: 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
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 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 } else { 888 } else {
889 buffer.write(list[0]); 889 buffer.write(list[0]);
890 for (int i = 1; i < list.length; i++) { 890 for (int i = 1; i < list.length; i++) {
891 buffer.write(separator); 891 buffer.write(separator);
892 buffer.write(list[i]); 892 buffer.write(list[i]);
893 } 893 }
894 } 894 }
895 return buffer.toString(); 895 return buffer.toString();
896 } 896 }
897 897
898 static String toStringIterable(Iterable iterable) {
899 var result = new StringBuffer();
floitsch 2013/07/08 12:00:50 Move checking of recursive iterables in here.
zarah 2013/07/08 14:35:15 Done.
900
901 result.write('{');
902 bool first = true;
903 for (var e in iterable) {
904 if (!first) {
905 result.write(', ');
906 }
907 first = false;
908 result.write(e);
909 }
910 result.write('}');
911
912 return result.toString();
913 }
914
915 static String toStringList(List list) {
floitsch 2013/07/08 12:00:50 Move checking of recursive lists in here.
zarah 2013/07/08 14:35:15 Done.
916 var result = new StringBuffer();
917 result.write('[');
918 for (int i = 0; i < list.length; i++) {
919 if (i > 0) {
920 result.write(', ');
921 }
922 result.write(list[i]);
923 }
924 result.write(']');
925
926 return result.toString();
927 }
928
929
898 static Iterable where(Iterable iterable, bool f(var element)) { 930 static Iterable where(Iterable iterable, bool f(var element)) {
899 return new WhereIterable(iterable, f); 931 return new WhereIterable(iterable, f);
900 } 932 }
901 933
902 static Iterable map(Iterable iterable, f(var element)) { 934 static Iterable map(Iterable iterable, f(var element)) {
903 return new MappedIterable(iterable, f); 935 return new MappedIterable(iterable, f);
904 } 936 }
905 937
906 static Iterable mapList(List list, f(var element)) { 938 static Iterable mapList(List list, f(var element)) {
907 return new MappedListIterable(list, f); 939 return new MappedListIterable(list, f);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 // TODO(floitsch): Make this accept more. 1007 // TODO(floitsch): Make this accept more.
976 List otherList; 1008 List otherList;
977 int otherStart; 1009 int otherStart;
978 if (from is List) { 1010 if (from is List) {
979 otherList = from; 1011 otherList = from;
980 otherStart = skipCount; 1012 otherStart = skipCount;
981 } else { 1013 } else {
982 otherList = from.skip(skipCount).toList(growable: false); 1014 otherList = from.skip(skipCount).toList(growable: false);
983 otherStart = 0; 1015 otherStart = 0;
984 } 1016 }
1017
985 if (otherStart + length > otherList.length) { 1018 if (otherStart + length > otherList.length) {
986 throw new StateError("Not enough elements"); 1019 throw new StateError("Not enough elements");
987 } 1020 }
988 Arrays.copy(otherList, otherStart, list, start, length); 1021 Arrays.copy(otherList, otherStart, list, start, length);
989 } 1022 }
990 1023
991 static void replaceRangeList(List list, int start, int end, 1024 static void replaceRangeList(List list, int start, int end,
992 Iterable iterable) { 1025 Iterable iterable) {
993 _rangeCheck(list, start, end); 1026 _rangeCheck(list, start, end);
994 // TODO(floitsch): optimize this. 1027 // TODO(floitsch): optimize this.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 1097
1065 static Set setDifference(Set set, Set other, Set result) { 1098 static Set setDifference(Set set, Set other, Set result) {
1066 for (var element in set) { 1099 for (var element in set) {
1067 if (!other.contains(element)) { 1100 if (!other.contains(element)) {
1068 result.add(element); 1101 result.add(element);
1069 } 1102 }
1070 } 1103 }
1071 return result; 1104 return result;
1072 } 1105 }
1073 } 1106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698