| 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 /** | 5 /** |
| 6 * A [List] is an indexable collection with a length. It can be of | 6 * A [List] is an indexable collection with a length. It can be of |
| 7 * fixed size or extendable. | 7 * fixed size or extendable. |
| 8 */ | 8 */ |
| 9 interface List<E> extends Collection<E>, Sequence<E> | 9 abstract class List<E> implements Collection<E>, Sequence<E> { |
| 10 default _ListImpl<E> { | |
| 11 /** | 10 /** |
| 12 * Creates a list of the given [length]. | 11 * Creates a list of the given [length]. |
| 13 * | 12 * |
| 14 * If no [length] argument is supplied an extendable list of | 13 * If no [length] argument is supplied an extendable list of |
| 15 * length 0 is created. | 14 * length 0 is created. |
| 16 * | 15 * |
| 17 * If a [length] argument is supplied, a fixed size list of that | 16 * If a [length] argument is supplied, a fixed size list of that |
| 18 * length is created. | 17 * length is created. |
| 19 */ | 18 */ |
| 20 List([int length]); | 19 external factory List([int length]); |
| 21 | 20 |
| 22 /** | 21 /** |
| 23 * Creates a list with the elements of [other]. The order in | 22 * Creates a list with the elements of [other]. The order in |
| 24 * the list will be the order provided by the iterator of [other]. | 23 * the list will be the order provided by the iterator of [other]. |
| 25 */ | 24 */ |
| 26 List.from(Iterable<E> other); | 25 factory List.from(Iterable<E> other) { |
| 26 var list = new List<E>(); |
| 27 for (var e in other) { |
| 28 list.add(e); |
| 29 } |
| 30 return list; |
| 31 } |
| 27 | 32 |
| 28 /** | 33 /** |
| 29 * Returns the element at the given [index] in the list or throws | 34 * Returns the element at the given [index] in the list or throws |
| 30 * an [RangeError] if [index] is out of bounds. | 35 * an [RangeError] if [index] is out of bounds. |
| 31 */ | 36 */ |
| 32 E operator [](int index); | 37 E operator [](int index); |
| 33 | 38 |
| 34 /** | 39 /** |
| 35 * Sets the entry at the given [index] in the list to [value]. | 40 * Sets the entry at the given [index] in the list to [value]. |
| 36 * Throws an [RangeError] if [index] is out of bounds. | 41 * Throws an [RangeError] if [index] is out of bounds. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 * not extendable. | 178 * not extendable. |
| 174 * If [length] is 0, this method does not do anything. | 179 * If [length] is 0, this method does not do anything. |
| 175 * If [start] is the length of the list, this method inserts the | 180 * If [start] is the length of the list, this method inserts the |
| 176 * range at the end of the list. | 181 * range at the end of the list. |
| 177 * Throws an [ArgumentError] if [length] is negative. | 182 * Throws an [ArgumentError] if [length] is negative. |
| 178 * Throws an [RangeError] if [start] is negative or if | 183 * Throws an [RangeError] if [start] is negative or if |
| 179 * [start] is greater than the length of the list. | 184 * [start] is greater than the length of the list. |
| 180 */ | 185 */ |
| 181 void insertRange(int start, int length, [E initialValue]); | 186 void insertRange(int start, int length, [E initialValue]); |
| 182 } | 187 } |
| 183 | |
| 184 class _ListImpl<E> { | |
| 185 /** | |
| 186 * Factory implementation of List(). | |
| 187 * | |
| 188 * Creates a list of the given [length]. | |
| 189 */ | |
| 190 external factory List([int length]); | |
| 191 | |
| 192 /** | |
| 193 * Factory implementation of List.from(). | |
| 194 * | |
| 195 * Creates a list with the elements of [other]. The order in | |
| 196 * the list will be the order provided by the iterator of [other]. | |
| 197 */ | |
| 198 external factory List.from(Iterable<E> other); | |
| 199 } | |
| OLD | NEW |