| 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._internal; | 5 part of dart._internal; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Marker interface for [Iterable] subclasses that have an efficient | 8 * Marker interface for [Iterable] subclasses that have an efficient |
| 9 * [length] implementation. | 9 * [length] implementation. |
| 10 */ | 10 */ |
| (...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 abstract class BidirectionalIterator<T> implements Iterator<T> { | 734 abstract class BidirectionalIterator<T> implements Iterator<T> { |
| 735 bool movePrevious(); | 735 bool movePrevious(); |
| 736 } | 736 } |
| 737 | 737 |
| 738 /** | 738 /** |
| 739 * This class provides default implementations for Iterables (including Lists). | 739 * This class provides default implementations for Iterables (including Lists). |
| 740 * | 740 * |
| 741 * The uses of this class will be replaced by mixins. | 741 * The uses of this class will be replaced by mixins. |
| 742 */ | 742 */ |
| 743 class IterableMixinWorkaround { | 743 class IterableMixinWorkaround { |
| 744 // A list to identify cyclic collections during toString() calls. | |
| 745 static List _toStringList = new List(); | |
| 746 | |
| 747 static bool contains(Iterable iterable, var element) { | 744 static bool contains(Iterable iterable, var element) { |
| 748 for (final e in iterable) { | 745 for (final e in iterable) { |
| 749 if (e == element) return true; | 746 if (e == element) return true; |
| 750 } | 747 } |
| 751 return false; | 748 return false; |
| 752 } | 749 } |
| 753 | 750 |
| 754 static void forEach(Iterable iterable, void f(o)) { | 751 static void forEach(Iterable iterable, void f(o)) { |
| 755 for (final e in iterable) { | 752 for (final e in iterable) { |
| 756 f(e); | 753 f(e); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 } else { | 927 } else { |
| 931 buffer.write(list[0]); | 928 buffer.write(list[0]); |
| 932 for (int i = 1; i < list.length; i++) { | 929 for (int i = 1; i < list.length; i++) { |
| 933 buffer.write(separator); | 930 buffer.write(separator); |
| 934 buffer.write(list[i]); | 931 buffer.write(list[i]); |
| 935 } | 932 } |
| 936 } | 933 } |
| 937 return buffer.toString(); | 934 return buffer.toString(); |
| 938 } | 935 } |
| 939 | 936 |
| 940 static String toStringIterable(Iterable iterable, String leftDelimiter, | |
| 941 String rightDelimiter) { | |
| 942 for (int i = 0; i < _toStringList.length; i++) { | |
| 943 if (identical(_toStringList[i], iterable)) { | |
| 944 return '$leftDelimiter...$rightDelimiter'; | |
| 945 } | |
| 946 } | |
| 947 | |
| 948 StringBuffer result = new StringBuffer(); | |
| 949 try { | |
| 950 _toStringList.add(iterable); | |
| 951 result.write(leftDelimiter); | |
| 952 result.writeAll(iterable, ', '); | |
| 953 result.write(rightDelimiter); | |
| 954 } finally { | |
| 955 assert(identical(_toStringList.last, iterable)); | |
| 956 _toStringList.removeLast(); | |
| 957 } | |
| 958 return result.toString(); | |
| 959 } | |
| 960 | |
| 961 static Iterable where(Iterable iterable, bool f(var element)) { | 937 static Iterable where(Iterable iterable, bool f(var element)) { |
| 962 return new WhereIterable(iterable, f); | 938 return new WhereIterable(iterable, f); |
| 963 } | 939 } |
| 964 | 940 |
| 965 static Iterable map(Iterable iterable, f(var element)) { | 941 static Iterable map(Iterable iterable, f(var element)) { |
| 966 return new MappedIterable(iterable, f); | 942 return new MappedIterable(iterable, f); |
| 967 } | 943 } |
| 968 | 944 |
| 969 static Iterable mapList(List list, f(var element)) { | 945 static Iterable mapList(List list, f(var element)) { |
| 970 return new MappedListIterable(list, f); | 946 return new MappedListIterable(list, f); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1170 * Creates errors throw by [Iterable] when the element count is wrong. | 1146 * Creates errors throw by [Iterable] when the element count is wrong. |
| 1171 */ | 1147 */ |
| 1172 abstract class IterableElementError { | 1148 abstract class IterableElementError { |
| 1173 /** Error thrown thrown by, e.g., [Iterable.first] when there is no result. */ | 1149 /** Error thrown thrown by, e.g., [Iterable.first] when there is no result. */ |
| 1174 static StateError noElement() => new StateError("No element"); | 1150 static StateError noElement() => new StateError("No element"); |
| 1175 /** Error thrown by, e.g., [Iterable.single] if there are too many results. */ | 1151 /** Error thrown by, e.g., [Iterable.single] if there are too many results. */ |
| 1176 static StateError tooMany() => new StateError("Too many elements"); | 1152 static StateError tooMany() => new StateError("Too many elements"); |
| 1177 /** Error thrown by, e.g., [List.setRange] if there are too few elements. */ | 1153 /** Error thrown by, e.g., [List.setRange] if there are too few elements. */ |
| 1178 static StateError tooFew() => new StateError("Too few elements"); | 1154 static StateError tooFew() => new StateError("Too few elements"); |
| 1179 } | 1155 } |
| OLD | NEW |