| 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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 E get single { | 255 E get single { |
| 256 if (length == 1) return this[0]; | 256 if (length == 1) return this[0]; |
| 257 if (length == 0) throw new StateError("No elements"); | 257 if (length == 0) throw new StateError("No elements"); |
| 258 throw new StateError("More than one element"); | 258 throw new StateError("More than one element"); |
| 259 } | 259 } |
| 260 | 260 |
| 261 bool any(bool f(E element)) => IterableMixinWorkaround.any(this, f); | 261 bool any(bool f(E element)) => IterableMixinWorkaround.any(this, f); |
| 262 | 262 |
| 263 bool every(bool f(E element)) => IterableMixinWorkaround.every(this, f); | 263 bool every(bool f(E element)) => IterableMixinWorkaround.every(this, f); |
| 264 | 264 |
| 265 void sort([int compare(E a, E b)]) { | |
| 266 checkMutable('sort'); | |
| 267 IterableMixinWorkaround.sortList(this, compare); | |
| 268 } | |
| 269 | |
| 270 bool contains(Object other) { | 265 bool contains(Object other) { |
| 271 for (int i = 0; i < length; i++) { | 266 for (int i = 0; i < length; i++) { |
| 272 if (this[i] == other) return true; | 267 if (this[i] == other) return true; |
| 273 } | 268 } |
| 274 return false; | 269 return false; |
| 275 } | 270 } |
| 276 | 271 |
| 277 bool get isEmpty => length == 0; | 272 bool get isEmpty => length == 0; |
| 278 | 273 |
| 279 bool get isNotEmpty => !isEmpty; | 274 bool get isNotEmpty => !isEmpty; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 * numbers.join(', '); // 'one, two, four, three' | 374 * numbers.join(', '); // 'one, two, four, three' |
| 380 * | 375 * |
| 381 * The default List implementations use [Comparable.compare] if | 376 * The default List implementations use [Comparable.compare] if |
| 382 * [compare] is omitted. | 377 * [compare] is omitted. |
| 383 * | 378 * |
| 384 * List<int> nums = [13, 2, -11]; | 379 * List<int> nums = [13, 2, -11]; |
| 385 * nums.sort(); | 380 * nums.sort(); |
| 386 nums.join(', '); // '-11, 2, 13' | 381 nums.join(', '); // '-11, 2, 13' |
| 387 */ | 382 */ |
| 388 void sort([int compare(E a, E b)]) { | 383 void sort([int compare(E a, E b)]) { |
| 389 // XXX checkMutable('sort'); | 384 checkMutable('sort'); |
| 390 IterableMixinWorkaround.sortList(this, compare); | 385 IterableMixinWorkaround.sortList(this, compare); |
| 391 } | 386 } |
| 392 | 387 |
| 393 /** | 388 /** |
| 394 * Shuffles the elements of this list randomly. | 389 * Shuffles the elements of this list randomly. |
| 395 */ | 390 */ |
| 396 void shuffle([Random random]) { | 391 void shuffle([Random random]) { |
| 397 IterableMixinWorkaround.shuffleList(this, random); | 392 IterableMixinWorkaround.shuffleList(this, random); |
| 398 } | 393 } |
| 399 | 394 |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 * | 741 * |
| 747 * List<String> words = ['fee', 'fi', 'fo', 'fum']; | 742 * List<String> words = ['fee', 'fi', 'fo', 'fum']; |
| 748 * Map<int, String> map = words.asMap(); | 743 * Map<int, String> map = words.asMap(); |
| 749 * map[0] + map[1]; // 'feefi'; | 744 * map[0] + map[1]; // 'feefi'; |
| 750 * map.keys.toList(); // [0, 1, 2, 3] | 745 * map.keys.toList(); // [0, 1, 2, 3] |
| 751 */ | 746 */ |
| 752 Map<int, E> asMap() { | 747 Map<int, E> asMap() { |
| 753 return new IterableMixinWorkaround<E>().asMapList(this); | 748 return new IterableMixinWorkaround<E>().asMapList(this); |
| 754 } | 749 } |
| 755 } | 750 } |
| OLD | NEW |