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 * A [List] is an indexable collection with a length. | 8 * A [List] is an indexable collection with a length. |
| 9 * | 9 * |
| 10 * A `List` implementation can choose not to support all methods | 10 * A `List` implementation can choose not to support all methods |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 * If the length changes temporarily | 45 * If the length changes temporarily |
| 46 * and is restored before continuing the iteration, | 46 * and is restored before continuing the iteration, |
| 47 * the iterator will not detect it. | 47 * the iterator will not detect it. |
| 48 */ | 48 */ |
| 49 abstract class List<E> implements Iterable<E> { | 49 abstract class List<E> implements Iterable<E> { |
| 50 /** | 50 /** |
| 51 * Creates a list of the given [length]. | 51 * Creates a list of the given [length]. |
| 52 * | 52 * |
| 53 * The list is a fixed-length list if [length] is provided, and an empty | 53 * The list is a fixed-length list if [length] is provided, and an empty |
| 54 * growable list if [length] is omitted. | 54 * growable list if [length] is omitted. |
| 55 * | |
| 56 * It is an error if [length] is not a non-negative integer. | |
|
Søren Gjesse
2013/04/24 12:02:20
State the obvious :-)
Lasse Reichstein Nielsen
2013/04/24 12:09:51
Can't be too careful :)
Another option would be to
| |
| 55 */ | 57 */ |
| 56 external factory List([int length]); | 58 external factory List([int length]); |
| 57 | 59 |
| 58 /** | 60 /** |
| 59 * Creates a fixed-length list of the given [length] where each entry | 61 * Creates a fixed-length list of the given [length] where each entry |
| 60 * contains [fill]. | 62 * contains [fill]. |
| 61 */ | 63 */ |
| 62 external factory List.filled(int length, E fill); | 64 external factory List.filled(int length, E fill); |
| 63 | 65 |
| 64 /** | 66 /** |
| 65 * Creates an list with the elements of [other]. The order in | 67 * Creates an list with the elements of [other]. |
| 66 * the list will be the order provided by the iterator of [other]. | 68 * |
| 69 * The order in the list will be | |
| 70 * the order provided by the iterator of [other]. | |
| 67 * | 71 * |
| 68 * The returned list is growable if [growable] is true, otherwise it's | 72 * The returned list is growable if [growable] is true, otherwise it's |
| 69 * a fixed length list. | 73 * a fixed length list. |
| 70 */ | 74 */ |
| 71 factory List.from(Iterable other, { bool growable: true }) { | 75 factory List.from(Iterable other, { bool growable: true }) { |
| 72 List<E> list = new List<E>(); | 76 List<E> list = new List<E>(); |
| 73 for (E e in other) { | 77 for (E e in other) { |
| 74 list.add(e); | 78 list.add(e); |
| 75 } | 79 } |
| 76 if (growable) return list; | 80 if (growable) return list; |
| 77 int length = list.length; | 81 int length = list.length; |
| 78 List<E> fixedList = new List<E>(length); | 82 List<E> fixedList = new List<E>(length); |
| 79 for (int i = 0; i < length; i++) { | 83 for (int i = 0; i < length; i++) { |
| 80 fixedList[i] = list[i]; | 84 fixedList[i] = list[i]; |
| 81 } | 85 } |
| 82 return fixedList; | 86 return fixedList; |
| 83 } | 87 } |
| 84 | 88 |
| 85 /** | 89 /** |
| 86 * Generate a `List` of elements. | 90 * Generate a `List` of values. |
| 87 * | 91 * |
| 88 * Generates a list of values, where the values are created by | 92 * Creates a list with [length] positions |
| 89 * calling the [generator] function for each index in the range | 93 * and fills them by values created by calling [generator] |
| 90 * 0 .. [length] - 1. | 94 * for each index in the range `0` .. `[length] - 1` |
| 95 * in increasing order. | |
| 91 * | 96 * |
| 92 * The created length's length is fixed unless [growable] is true. | 97 * The created length's length is fixed unless [growable] is true. |
| 93 */ | 98 */ |
| 94 factory List.generate(int length, E generator(int index), | 99 factory List.generate(int length, E generator(int index), |
| 95 { bool growable: true }) { | 100 { bool growable: true }) { |
| 96 List<E> result; | 101 List<E> result; |
| 97 if (growable) { | 102 if (growable) { |
| 98 result = <E>[]..length = length; | 103 result = <E>[]..length = length; |
| 99 } else { | 104 } else { |
| 100 result = new List<E>(length); | 105 result = new List<E>(length); |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 void replaceRange(int start, int end, Iterable<E> iterable); | 351 void replaceRange(int start, int end, Iterable<E> iterable); |
| 347 | 352 |
| 348 /** | 353 /** |
| 349 * Returns an unmodifiable [Map] view of `this`. | 354 * Returns an unmodifiable [Map] view of `this`. |
| 350 * | 355 * |
| 351 * It has the indices of this list as keys, and the corresponding elements | 356 * It has the indices of this list as keys, and the corresponding elements |
| 352 * as values. | 357 * as values. |
| 353 */ | 358 */ |
| 354 Map<int, E> asMap(); | 359 Map<int, E> asMap(); |
| 355 } | 360 } |
| OLD | NEW |