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 be choose not to support all methods | 10 * A `List` implementation can be choose not to support all methods |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 return result; | 60 return result; |
61 } | 61 } |
62 | 62 |
63 /** | 63 /** |
64 * Creates an list with the elements of [other]. The order in | 64 * Creates an list with the elements of [other]. The order in |
65 * the list will be the order provided by the iterator of [other]. | 65 * the list will be the order provided by the iterator of [other]. |
66 * | 66 * |
67 * The returned list is growable if [growable] is true, otherwise it's | 67 * The returned list is growable if [growable] is true, otherwise it's |
68 * a fixed length list. | 68 * a fixed length list. |
69 */ | 69 */ |
70 factory List.from(Iterable other, { bool growable: false }) { | 70 factory List.from(Iterable other, { bool growable: true }) { |
71 List<E> list = new List<E>(); | 71 List<E> list = new List<E>(); |
72 for (E e in other) { | 72 for (E e in other) { |
73 list.add(e); | 73 list.add(e); |
74 } | 74 } |
75 if (growable) return list; | 75 if (growable) return list; |
76 int length = list.length; | 76 int length = list.length; |
77 List<E> fixedList = new List<E>(length); | 77 List<E> fixedList = new List<E>(length); |
78 for (int i = 0; i < length; i++) { | 78 for (int i = 0; i < length; i++) { |
79 fixedList[i] = list[i]; | 79 fixedList[i] = list[i]; |
80 } | 80 } |
81 return fixedList; | 81 return fixedList; |
82 } | 82 } |
83 | 83 |
84 /** | 84 /** |
85 * Generate a `List` of elements. | 85 * Generate a `List` of elements. |
86 * | 86 * |
87 * Generates a list of values, where the values are created by | 87 * Generates a list of values, where the values are created by |
88 * calling the [generator] function for each index in the range | 88 * calling the [generator] function for each index in the range |
89 * 0 .. [length] - 1. | 89 * 0 .. [length] - 1. |
90 * | 90 * |
91 * The created length's length is fixed unless [growable] is true. | 91 * The created length's length is fixed unless [growable] is true. |
92 */ | 92 */ |
93 factory List.generate(int length, E generator(int index), | 93 factory List.generate(int length, E generator(int index), |
94 { bool growable: false }) { | 94 { bool growable: true }) { |
95 List<E> result; | 95 List<E> result; |
96 if (growable) { | 96 if (growable) { |
97 result = <E>[]..length = length; | 97 result = <E>[]..length = length; |
98 } else { | 98 } else { |
99 result = new List<E>(length); | 99 result = new List<E>(length); |
100 } | 100 } |
101 for (int i = 0; i < length; i++) { | 101 for (int i = 0; i < length; i++) { |
102 result[i] = generator(i); | 102 result[i] = generator(i); |
103 } | 103 } |
104 return result; | 104 return result; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 * not extendable. | 248 * not extendable. |
249 * If [length] is 0, this method does not do anything. | 249 * If [length] is 0, this method does not do anything. |
250 * If [start] is the length of the list, this method inserts the | 250 * If [start] is the length of the list, this method inserts the |
251 * range at the end of the list. | 251 * range at the end of the list. |
252 * Throws an [ArgumentError] if [length] is negative. | 252 * Throws an [ArgumentError] if [length] is negative. |
253 * Throws an [RangeError] if [start] is negative or if | 253 * Throws an [RangeError] if [start] is negative or if |
254 * [start] is greater than the length of the list. | 254 * [start] is greater than the length of the list. |
255 */ | 255 */ |
256 void insertRange(int start, int length, [E fill]); | 256 void insertRange(int start, int length, [E fill]); |
257 } | 257 } |
OLD | NEW |