OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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; | 5 part of dart.collection; |
6 | 6 |
7 /** | 7 /** |
8 * Abstract implementation of a list. | 8 * Abstract implementation of a list. |
9 * | 9 * |
10 * `ListBase` can be used as a base class for implementing the `List` interface. | 10 * `ListBase` can be used as a base class for implementing the `List` interface. |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 } | 267 } |
268 | 268 |
269 void removeWhere(bool test(E element)) { | 269 void removeWhere(bool test(E element)) { |
270 _filter(this, test, false); | 270 _filter(this, test, false); |
271 } | 271 } |
272 | 272 |
273 void retainWhere(bool test(E element)) { | 273 void retainWhere(bool test(E element)) { |
274 _filter(this, test, true); | 274 _filter(this, test, true); |
275 } | 275 } |
276 | 276 |
277 static void _filter(List source, | 277 void _filter(List source, bool test(var element), bool retainMatching) { |
278 bool test(var element), | 278 List<E> retained = <E>[]; |
Jennifer Messerly
2017/02/24 23:23:57
This change is needed to prevent a cast failure in
Lasse Reichstein Nielsen
2017/02/25 10:53:15
Acknowledged.
| |
279 bool retainMatching) { | |
280 List retained = []; | |
281 int length = source.length; | 279 int length = source.length; |
282 for (int i = 0; i < length; i++) { | 280 for (int i = 0; i < length; i++) { |
283 var element = source[i]; | 281 var element = source[i]; |
284 if (test(element) == retainMatching) { | 282 if (test(element) == retainMatching) { |
285 retained.add(element); | 283 retained.add(element); |
286 } | 284 } |
287 if (length != source.length) { | 285 if (length != source.length) { |
288 throw new ConcurrentModificationError(source); | 286 throw new ConcurrentModificationError(source); |
289 } | 287 } |
290 } | 288 } |
(...skipping 11 matching lines...) Expand all Loading... | |
302 if (length == 0) { | 300 if (length == 0) { |
303 throw IterableElementError.noElement(); | 301 throw IterableElementError.noElement(); |
304 } | 302 } |
305 E result = this[length - 1]; | 303 E result = this[length - 1]; |
306 length--; | 304 length--; |
307 return result; | 305 return result; |
308 } | 306 } |
309 | 307 |
310 void sort([int compare(E a, E b)]) { | 308 void sort([int compare(E a, E b)]) { |
311 if (compare == null) { | 309 if (compare == null) { |
312 Sort.sort(this, Comparable.compare); | 310 Sort.sort(this, (a, b) => Comparable.compare(a, b)); |
Jennifer Messerly
2017/02/24 23:23:57
This change is because Comparable.compare requires
Lasse Reichstein Nielsen
2017/02/25 10:53:15
Comparable.compare was always a type hack, so it's
Jennifer Messerly
2017/02/27 18:28:08
good catch, added _compareAny
| |
313 } else { | 311 } else { |
314 Sort.sort(this, compare); | 312 Sort.sort(this, compare); |
315 } | 313 } |
316 } | 314 } |
317 | 315 |
318 void shuffle([Random random]) { | 316 void shuffle([Random random]) { |
319 if (random == null) random = new Random(); | 317 if (random == null) random = new Random(); |
320 int length = this.length; | 318 int length = this.length; |
321 while (length > 1) { | 319 while (length > 1) { |
322 int pos = random.nextInt(length); | 320 int pos = random.nextInt(length); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
507 for (E element in iterable) { | 505 for (E element in iterable) { |
508 this[index++] = element; | 506 this[index++] = element; |
509 } | 507 } |
510 } | 508 } |
511 } | 509 } |
512 | 510 |
513 Iterable<E> get reversed => new ReversedListIterable<E>(this); | 511 Iterable<E> get reversed => new ReversedListIterable<E>(this); |
514 | 512 |
515 String toString() => IterableBase.iterableToFullString(this, '[', ']'); | 513 String toString() => IterableBase.iterableToFullString(this, '[', ']'); |
516 } | 514 } |
OLD | NEW |