Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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.core; | 5 part of dart.core; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * An indexable collection of objects with a length. | 8 * An indexable collection of objects with a length. |
| 9 * | 9 * |
| 10 * Subclasses of this class implement different kinds of lists. | 10 * Subclasses of this class implement different kinds of lists. |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 E get single { | 222 E get single { |
| 223 if (length == 1) return this[0]; | 223 if (length == 1) return this[0]; |
| 224 if (length == 0) throw new StateError("No elements"); | 224 if (length == 0) throw new StateError("No elements"); |
| 225 throw new StateError("More than one element"); | 225 throw new StateError("More than one element"); |
| 226 } | 226 } |
| 227 | 227 |
| 228 bool any(bool f(E element)) => IterableMixinWorkaround.any(this, f); | 228 bool any(bool f(E element)) => IterableMixinWorkaround.any(this, f); |
| 229 | 229 |
| 230 bool every(bool f(E element)) => IterableMixinWorkaround.every(this, f); | 230 bool every(bool f(E element)) => IterableMixinWorkaround.every(this, f); |
| 231 | 231 |
| 232 void sort([int compare(E a, E b)]) { | |
| 233 checkMutable('sort'); | |
| 234 IterableMixinWorkaround.sortList(this, compare); | |
| 235 } | |
| 236 | |
| 237 bool contains(Object other) { | 232 bool contains(Object other) { |
| 238 for (int i = 0; i < length; i++) { | 233 for (int i = 0; i < length; i++) { |
| 239 if (this[i] == other) return true; | 234 if (this[i] == other) return true; |
| 240 } | 235 } |
| 241 return false; | 236 return false; |
| 242 } | 237 } |
| 243 | 238 |
| 244 bool get isEmpty => length == 0; | 239 bool get isEmpty => length == 0; |
| 245 | 240 |
| 246 bool get isNotEmpty => !isEmpty; | 241 bool get isNotEmpty => !isEmpty; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 * numbers.join(', '); // 'one, two, four, three' | 341 * numbers.join(', '); // 'one, two, four, three' |
| 347 * | 342 * |
| 348 * The default List implementations use [Comparable.compare] if | 343 * The default List implementations use [Comparable.compare] if |
| 349 * [compare] is omitted. | 344 * [compare] is omitted. |
| 350 * | 345 * |
| 351 * List<int> nums = [13, 2, -11]; | 346 * List<int> nums = [13, 2, -11]; |
| 352 * nums.sort(); | 347 * nums.sort(); |
| 353 nums.join(', '); // '-11, 2, 13' | 348 nums.join(', '); // '-11, 2, 13' |
| 354 */ | 349 */ |
| 355 void sort([int compare(E a, E b)]) { | 350 void sort([int compare(E a, E b)]) { |
| 356 // XXX checkMutable('sort'); | 351 checkMutable('sort'); |
|
vsm
2015/05/04 21:09:21
Is this cleaning up a previous hack of ours?
Leaf
2015/05/04 21:50:42
I asked jacobr about this - the commented out chec
| |
| 357 IterableMixinWorkaround.sortList(this, compare); | 352 IterableMixinWorkaround.sortList(this, compare); |
| 358 } | 353 } |
| 359 | 354 |
| 360 /** | 355 /** |
| 361 * Shuffles the elements of this list randomly. | 356 * Shuffles the elements of this list randomly. |
| 362 */ | 357 */ |
| 363 void shuffle([Random random]) { | 358 void shuffle([Random random]) { |
| 364 IterableMixinWorkaround.shuffleList(this, random); | 359 IterableMixinWorkaround.shuffleList(this, random); |
| 365 } | 360 } |
| 366 | 361 |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 713 * | 708 * |
| 714 * List<String> words = ['fee', 'fi', 'fo', 'fum']; | 709 * List<String> words = ['fee', 'fi', 'fo', 'fum']; |
| 715 * Map<int, String> map = words.asMap(); | 710 * Map<int, String> map = words.asMap(); |
| 716 * map[0] + map[1]; // 'feefi'; | 711 * map[0] + map[1]; // 'feefi'; |
| 717 * map.keys.toList(); // [0, 1, 2, 3] | 712 * map.keys.toList(); // [0, 1, 2, 3] |
| 718 */ | 713 */ |
| 719 Map<int, E> asMap() { | 714 Map<int, E> asMap() { |
| 720 return new IterableMixinWorkaround<E>().asMapList(this); | 715 return new IterableMixinWorkaround<E>().asMapList(this); |
| 721 } | 716 } |
| 722 } | 717 } |
| OLD | NEW |