| 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 16 matching lines...) Expand all Loading... |
| 27 * fixedLengthList[0] = 87; | 27 * fixedLengthList[0] = 87; |
| 28 * var growableList = [1, 2]; | 28 * var growableList = [1, 2]; |
| 29 * growableList.length = 0; | 29 * growableList.length = 0; |
| 30 * growableList.add(499); | 30 * growableList.add(499); |
| 31 * growableList[0] = 87; | 31 * growableList[0] = 87; |
| 32 * var unmodifiableList = const [1, 2]; | 32 * var unmodifiableList = const [1, 2]; |
| 33 * unmodifiableList.length = 0; // throws. | 33 * unmodifiableList.length = 0; // throws. |
| 34 * unmodifiableList.add(499); // throws | 34 * unmodifiableList.add(499); // throws |
| 35 * unmodifiableList[0] = 87; // throws. | 35 * unmodifiableList[0] = 87; // throws. |
| 36 */ | 36 */ |
| 37 abstract class List<E> implements Collection<E> { | 37 abstract class List<E> implements Iterable<E> { |
| 38 /** | 38 /** |
| 39 * Creates a list of the given [length]. | 39 * Creates a list of the given [length]. |
| 40 * | 40 * |
| 41 * The list is a fixed-length list if [length] is provided, and an empty | 41 * The list is a fixed-length list if [length] is provided, and an empty |
| 42 * growable list if [length] is omitted. | 42 * growable list if [length] is omitted. |
| 43 */ | 43 */ |
| 44 external factory List([int length]); | 44 external factory List([int length]); |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * Creates a fixed-length list of the given [length] where each entry | 47 * Creates a fixed-length list of the given [length] where each entry |
| 48 * contains [fill]. | 48 * contains [fill]. |
| 49 */ | 49 */ |
| 50 external factory List.filled(int length, E fill); | 50 external factory List.filled(int length, E fill); |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * *Deprecated*: Use `new List(count)` instead. | |
| 54 */ | |
| 55 @deprecated | |
| 56 factory List.fixedLength(int count, { E fill }) { | |
| 57 List<E> result = new List(count); | |
| 58 if (fill != null) { | |
| 59 for (int i = 0; i < count; i++) result[i] = fill; | |
| 60 } | |
| 61 return result; | |
| 62 } | |
| 63 | |
| 64 /** | |
| 65 * Creates an list with the elements of [other]. The order in | 53 * Creates an list with the elements of [other]. The order in |
| 66 * the list will be the order provided by the iterator of [other]. | 54 * the list will be the order provided by the iterator of [other]. |
| 67 * | 55 * |
| 68 * The returned list is growable if [growable] is true, otherwise it's | 56 * The returned list is growable if [growable] is true, otherwise it's |
| 69 * a fixed length list. | 57 * a fixed length list. |
| 70 */ | 58 */ |
| 71 factory List.from(Iterable other, { bool growable: true }) { | 59 factory List.from(Iterable other, { bool growable: true }) { |
| 72 List<E> list = new List<E>(); | 60 List<E> list = new List<E>(); |
| 73 for (E e in other) { | 61 for (E e in other) { |
| 74 list.add(e); | 62 list.add(e); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 * | 182 * |
| 195 * This increases the length of the list by one and shifts all later elements | 183 * This increases the length of the list by one and shifts all later elements |
| 196 * towards the end of the list. | 184 * towards the end of the list. |
| 197 * | 185 * |
| 198 * It is an error if the [index] does not point inside the list or at the | 186 * It is an error if the [index] does not point inside the list or at the |
| 199 * position after the last element. | 187 * position after the last element. |
| 200 */ | 188 */ |
| 201 void insert(int index, E element); | 189 void insert(int index, E element); |
| 202 | 190 |
| 203 /** | 191 /** |
| 192 * Removes [value] from the list. Returns true if [value] was |
| 193 * in the list. Returns false otherwise. The method has no effect |
| 194 * if [value] value was not in the list. |
| 195 */ |
| 196 bool remove(Object value); |
| 197 |
| 198 /** |
| 204 * Removes the element at position [index] from the list. | 199 * Removes the element at position [index] from the list. |
| 205 * | 200 * |
| 206 * This reduces the length of the list by one and moves all later elements | 201 * This reduces the length of the list by one and moves all later elements |
| 207 * down by one position. | 202 * down by one position. |
| 208 * Returns the removed element. | 203 * Returns the removed element. |
| 209 * Throws an [ArgumentError] if [index] is not an [int]. | 204 * Throws an [ArgumentError] if [index] is not an [int]. |
| 210 * Throws an [RangeError] if the [index] does not point inside | 205 * Throws an [RangeError] if the [index] does not point inside |
| 211 * the list. | 206 * the list. |
| 212 * Throws an [UnsupportedError], and doesn't remove the element, | 207 * Throws an [UnsupportedError], and doesn't remove the element, |
| 213 * if the length of the list cannot be changed. | 208 * if the length of the list cannot be changed. |
| 214 */ | 209 */ |
| 215 E removeAt(int index); | 210 E removeAt(int index); |
| 216 | 211 |
| 217 /** | 212 /** |
| 218 * Pops and returns the last element of the list. | 213 * Pops and returns the last element of the list. |
| 219 * Throws a [UnsupportedError] if the length of the | 214 * Throws a [UnsupportedError] if the length of the |
| 220 * list cannot be changed. | 215 * list cannot be changed. |
| 221 */ | 216 */ |
| 222 E removeLast(); | 217 E removeLast(); |
| 223 | 218 |
| 224 /** | 219 /** |
| 220 * Removes all elements of this list that satisfy [test]. |
| 221 * |
| 222 * An elements [:e:] satisfies [test] if [:test(e):] is true. |
| 223 */ |
| 224 void removeWhere(bool test(E element)); |
| 225 |
| 226 /** |
| 227 * Removes all elements of this list that fail to satisfy [test]. |
| 228 * |
| 229 * An elements [:e:] satisfies [test] if [:test(e):] is true. |
| 230 */ |
| 231 void retainWhere(bool test(E element)); |
| 232 |
| 233 /** |
| 225 * Returns a new list containing the elements from [start] to [end]. | 234 * Returns a new list containing the elements from [start] to [end]. |
| 226 * | 235 * |
| 227 * If [end] is omitted, the [length] of the list is used. | 236 * If [end] is omitted, the [length] of the list is used. |
| 228 * | 237 * |
| 229 * It is an error if [start] or [end] are not list indices for this list, | 238 * It is an error if [start] or [end] are not list indices for this list, |
| 230 * or if [end] is before [start]. | 239 * or if [end] is before [start]. |
| 231 */ | 240 */ |
| 232 List<E> sublist(int start, [int end]); | 241 List<E> sublist(int start, [int end]); |
| 233 | 242 |
| 234 /** | 243 /** |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 void insertRange(int start, int length, [E fill]); | 299 void insertRange(int start, int length, [E fill]); |
| 291 | 300 |
| 292 /** | 301 /** |
| 293 * Returns an unmodifiable [Map] view of `this`. | 302 * Returns an unmodifiable [Map] view of `this`. |
| 294 * | 303 * |
| 295 * It has the indices of this list as keys, and the corresponding elements | 304 * It has the indices of this list as keys, and the corresponding elements |
| 296 * as values. | 305 * as values. |
| 297 */ | 306 */ |
| 298 Map<int, E> asMap(); | 307 Map<int, E> asMap(); |
| 299 } | 308 } |
| OLD | NEW |