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 17 matching lines...) Expand all Loading... | |
| 28 * growableList.add(499); | 28 * growableList.add(499); |
| 29 * growableList[0] = 87; | 29 * growableList[0] = 87; |
| 30 * | 30 * |
| 31 * Lists are [Iterable]. Iteration occurs over values in index order. Changing | 31 * Lists are [Iterable]. Iteration occurs over values in index order. Changing |
| 32 * the values does not affect iteration, but changing the valid | 32 * the values does not affect iteration, but changing the valid |
| 33 * indices—that is, changing the list's length—between iteration | 33 * indices—that is, changing the list's length—between iteration |
| 34 * steps causes a [ConcurrentModificationError]. This means that only growable | 34 * steps causes a [ConcurrentModificationError]. This means that only growable |
| 35 * lists can throw ConcurrentModificationError. If the length changes | 35 * lists can throw ConcurrentModificationError. If the length changes |
| 36 * temporarily and is restored before continuing the iteration, the iterator | 36 * temporarily and is restored before continuing the iteration, the iterator |
| 37 * does not detect it. | 37 * does not detect it. |
| 38 * | |
| 39 * It is generally not allowed to modify the list's length (adding or removing | |
| 40 * elements) while an operation on the list is being performed, | |
| 41 * for example during a call to [forEach] or [sort]. | |
| 42 * Changing the list's length while it is being iterated, either directly or | |
| 43 * by iterating an `Iterable` that is backed by the list, will break the | |
|
floitsch
2013/10/15 15:32:24
Iterating will not change the length.
Lasse Reichstein Nielsen
2013/10/16 05:41:24
Please elaborate: What do you want changed?
Lasse Reichstein Nielsen
2013/10/16 08:53:42
Ah, now I see how it can also be read. Reworded.
| |
| 44 * iteration. | |
| 38 */ | 45 */ |
| 39 abstract class List<E> implements Iterable<E>, EfficientLength { | 46 abstract class List<E> implements Iterable<E>, EfficientLength { |
| 40 /** | 47 /** |
| 41 * Creates a list of the given length. | 48 * Creates a list of the given length. |
| 42 * | 49 * |
| 43 * The created list is fixed-length if [length] is provided. | 50 * The created list is fixed-length if [length] is provided. |
| 44 * | 51 * |
| 45 * List fixedLengthList = new List(3); | 52 * List fixedLengthList = new List(3); |
| 46 * fixedLengthList.length; // 3 | 53 * fixedLengthList.length; // 3 |
| 47 fixedLengthList.length = 1; // Error | 54 * fixedLengthList.length = 1; // Error |
| 48 * | 55 * |
| 49 * | 56 * |
| 50 * The list has length 0 and is growable if [length] is omitted. | 57 * The list has length 0 and is growable if [length] is omitted. |
| 51 * | 58 * |
| 52 * List growableList = new List(); | 59 * List growableList = new List(); |
| 53 * growableList.length; // 0; | 60 * growableList.length; // 0; |
| 54 * growableList.length = 3; | 61 * growableList.length = 3; |
| 55 * | 62 * |
| 56 * An error occurs if [length] is negative. | 63 * An error occurs if [length] is negative. |
| 57 */ | 64 */ |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 * as values. The `Map.keys` [Iterable] iterates the indices of this list | 436 * as values. The `Map.keys` [Iterable] iterates the indices of this list |
| 430 * in numerical order. | 437 * in numerical order. |
| 431 * | 438 * |
| 432 * List<String> words = ['fee', 'fi', 'fo', 'fum']; | 439 * List<String> words = ['fee', 'fi', 'fo', 'fum']; |
| 433 * Map<int, String> map = words.asMap(); | 440 * Map<int, String> map = words.asMap(); |
| 434 * map[0] + map[1]; // 'feefi'; | 441 * map[0] + map[1]; // 'feefi'; |
| 435 * map.keys.toList(); // [0, 1, 2, 3] | 442 * map.keys.toList(); // [0, 1, 2, 3] |
| 436 */ | 443 */ |
| 437 Map<int, E> asMap(); | 444 Map<int, E> asMap(); |
| 438 } | 445 } |
| OLD | NEW |