| OLD | NEW |
| 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 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 abstract class BidirectionalIterator<T> implements Iterator<T> { | 703 abstract class BidirectionalIterator<T> implements Iterator<T> { |
| 704 bool movePrevious(); | 704 bool movePrevious(); |
| 705 } | 705 } |
| 706 | 706 |
| 707 /** | 707 /** |
| 708 * This class provides default implementations for Iterables (including Lists). | 708 * This class provides default implementations for Iterables (including Lists). |
| 709 * | 709 * |
| 710 * The uses of this class will be replaced by mixins. | 710 * The uses of this class will be replaced by mixins. |
| 711 */ | 711 */ |
| 712 class IterableMixinWorkaround { | 712 class IterableMixinWorkaround { |
| 713 // A list to identify cyclic collections during toString() calls. | |
| 714 static List _toStringList = new List(); | |
| 715 | |
| 716 static bool contains(Iterable iterable, var element) { | 713 static bool contains(Iterable iterable, var element) { |
| 717 for (final e in iterable) { | 714 for (final e in iterable) { |
| 718 if (e == element) return true; | 715 if (e == element) return true; |
| 719 } | 716 } |
| 720 return false; | 717 return false; |
| 721 } | 718 } |
| 722 | 719 |
| 723 static void forEach(Iterable iterable, void f(o)) { | 720 static void forEach(Iterable iterable, void f(o)) { |
| 724 for (final e in iterable) { | 721 for (final e in iterable) { |
| 725 f(e); | 722 f(e); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 } else { | 896 } else { |
| 900 buffer.write(list[0]); | 897 buffer.write(list[0]); |
| 901 for (int i = 1; i < list.length; i++) { | 898 for (int i = 1; i < list.length; i++) { |
| 902 buffer.write(separator); | 899 buffer.write(separator); |
| 903 buffer.write(list[i]); | 900 buffer.write(list[i]); |
| 904 } | 901 } |
| 905 } | 902 } |
| 906 return buffer.toString(); | 903 return buffer.toString(); |
| 907 } | 904 } |
| 908 | 905 |
| 909 static String toStringIterable(Iterable iterable, String leftDelimiter, | |
| 910 String rightDelimiter) { | |
| 911 for (int i = 0; i < _toStringList.length; i++) { | |
| 912 if (identical(_toStringList[i], iterable)) { | |
| 913 return '$leftDelimiter...$rightDelimiter'; | |
| 914 } | |
| 915 } | |
| 916 | |
| 917 StringBuffer result = new StringBuffer(); | |
| 918 try { | |
| 919 _toStringList.add(iterable); | |
| 920 result.write(leftDelimiter); | |
| 921 result.writeAll(iterable, ', '); | |
| 922 result.write(rightDelimiter); | |
| 923 } finally { | |
| 924 assert(identical(_toStringList.last, iterable)); | |
| 925 _toStringList.removeLast(); | |
| 926 } | |
| 927 return result.toString(); | |
| 928 } | |
| 929 | |
| 930 static Iterable where(Iterable iterable, bool f(var element)) { | 906 static Iterable where(Iterable iterable, bool f(var element)) { |
| 931 return new WhereIterable(iterable, f); | 907 return new WhereIterable(iterable, f); |
| 932 } | 908 } |
| 933 | 909 |
| 934 static Iterable map(Iterable iterable, f(var element)) { | 910 static Iterable map(Iterable iterable, f(var element)) { |
| 935 return new MappedIterable(iterable, f); | 911 return new MappedIterable(iterable, f); |
| 936 } | 912 } |
| 937 | 913 |
| 938 static Iterable mapList(List list, f(var element)) { | 914 static Iterable mapList(List list, f(var element)) { |
| 939 return new MappedListIterable(list, f); | 915 return new MappedListIterable(list, f); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1096 | 1072 |
| 1097 static Set setDifference(Set set, Set other, Set result) { | 1073 static Set setDifference(Set set, Set other, Set result) { |
| 1098 for (var element in set) { | 1074 for (var element in set) { |
| 1099 if (!other.contains(element)) { | 1075 if (!other.contains(element)) { |
| 1100 result.add(element); | 1076 result.add(element); |
| 1101 } | 1077 } |
| 1102 } | 1078 } |
| 1103 return result; | 1079 return result; |
| 1104 } | 1080 } |
| 1105 } | 1081 } |
| OLD | NEW |