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

Side by Side Diff: sdk/lib/collection/set.dart

Issue 1937103002: Make dart:collection strong-mode clean. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: rebase Created 4 years, 7 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 /** 5 /**
6 * Base implementations of [Set]. 6 * Base implementations of [Set].
7 */ 7 */
8 part of dart.collection; 8 part of dart.collection;
9 9
10 /** 10 /**
(...skipping 15 matching lines...) Expand all
26 */ 26 */
27 abstract class SetMixin<E> implements Set<E> { 27 abstract class SetMixin<E> implements Set<E> {
28 // This class reimplements all of [IterableMixin]. 28 // This class reimplements all of [IterableMixin].
29 // If/when Dart mixins get more powerful, we should just create a single 29 // If/when Dart mixins get more powerful, we should just create a single
30 // Mixin class from IterableMixin and the new methods of thisclass. 30 // Mixin class from IterableMixin and the new methods of thisclass.
31 31
32 bool add(E element); 32 bool add(E element);
33 33
34 bool contains(Object element); 34 bool contains(Object element);
35 35
36 E lookup(E element); 36 E lookup(Object element);
37 37
38 bool remove(Object element); 38 bool remove(Object element);
39 39
40 Iterator<E> get iterator; 40 Iterator<E> get iterator;
41 41
42 Set<E> toSet(); 42 Set<E> toSet();
43 43
44 int get length; 44 int get length;
45 45
46 bool get isEmpty => length == 0; 46 bool get isEmpty => length == 0;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 int i = 0; 118 int i = 0;
119 for (E element in this) result[i++] = element; 119 for (E element in this) result[i++] = element;
120 return result; 120 return result;
121 } 121 }
122 122
123 Iterable/*<T>*/ map/*<T>*/(/*=T*/f(E element)) => 123 Iterable/*<T>*/ map/*<T>*/(/*=T*/f(E element)) =>
124 new EfficientLengthMappedIterable<E, dynamic/*=T*/>(this, f); 124 new EfficientLengthMappedIterable<E, dynamic/*=T*/>(this, f);
125 125
126 E get single { 126 E get single {
127 if (length > 1) throw IterableElementError.tooMany(); 127 if (length > 1) throw IterableElementError.tooMany();
128 Iterator it = iterator; 128 Iterator<E> it = iterator;
129 if (!it.moveNext()) throw IterableElementError.noElement(); 129 if (!it.moveNext()) throw IterableElementError.noElement();
130 E result = it.current; 130 E result = it.current;
131 return result; 131 return result;
132 } 132 }
133 133
134 String toString() => IterableBase.iterableToFullString(this, '{', '}'); 134 String toString() => IterableBase.iterableToFullString(this, '{', '}');
135 135
136 // Copied from IterableMixin. 136 // Copied from IterableMixin.
137 // Should be inherited if we had multi-level mixins. 137 // Should be inherited if we had multi-level mixins.
138 138
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 206
207 Iterable<E> skip(int n) { 207 Iterable<E> skip(int n) {
208 return new SkipIterable<E>(this, n); 208 return new SkipIterable<E>(this, n);
209 } 209 }
210 210
211 Iterable<E> skipWhile(bool test(E value)) { 211 Iterable<E> skipWhile(bool test(E value)) {
212 return new SkipWhileIterable<E>(this, test); 212 return new SkipWhileIterable<E>(this, test);
213 } 213 }
214 214
215 E get first { 215 E get first {
216 Iterator it = iterator; 216 Iterator<E> it = iterator;
217 if (!it.moveNext()) { 217 if (!it.moveNext()) {
218 throw IterableElementError.noElement(); 218 throw IterableElementError.noElement();
219 } 219 }
220 return it.current; 220 return it.current;
221 } 221 }
222 222
223 E get last { 223 E get last {
224 Iterator it = iterator; 224 Iterator<E> it = iterator;
225 if (!it.moveNext()) { 225 if (!it.moveNext()) {
226 throw IterableElementError.noElement(); 226 throw IterableElementError.noElement();
227 } 227 }
228 E result; 228 E result;
229 do { 229 do {
230 result = it.current; 230 result = it.current;
231 } while(it.moveNext()); 231 } while(it.moveNext());
232 return result; 232 return result;
233 } 233 }
234 234
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 abstract class SetBase<E> extends SetMixin<E> { 302 abstract class SetBase<E> extends SetMixin<E> {
303 /** 303 /**
304 * Convert a `Set` to a string as `{each, element, as, string}`. 304 * Convert a `Set` to a string as `{each, element, as, string}`.
305 * 305 *
306 * Handles circular references where converting one of the elements 306 * Handles circular references where converting one of the elements
307 * to a string ends up converting [set] to a string again. 307 * to a string ends up converting [set] to a string again.
308 */ 308 */
309 static String setToString(Set set) => 309 static String setToString(Set set) =>
310 IterableBase.iterableToFullString(set, '{', '}'); 310 IterableBase.iterableToFullString(set, '{', '}');
311 } 311 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698