Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: sdk/lib/core/list.dart

Issue 11312122: Change List constructors. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Reupload. Adapt code for List.fixedLength. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/async/future_impl.dart ('k') | sdk/lib/core/map.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 interface List<E> extends Collection<E>, Sequence<E>
10 default _ListImpl<E> { 10 default _ListImpl<E> {
11 /** 11 /**
12 * Creates a list of the given [length]. 12 * Creates a list of the given [length].
13 * 13 *
14 * If no [length] argument is supplied an extendable list of 14 * The length of the returned list is not fixed.
15 * length 0 is created.
16 *
17 * If a [length] argument is supplied, a fixed size list of that
18 * length is created.
19 */ 15 */
20 List([int length]); 16 List([int length = 0]);
21 17
22 /** 18 /**
23 * Creates a list with the elements of [other]. The order in 19 * Creates a fixed-sized list of the given [length] where each entry is
20 * filled with [fill].
21 */
22 List.fixedLength(int length, {E fill: null});
23
24 /**
25 * Creates an list of the given [length] where each entry is
26 * filled with [fill].
27 *
28 * The length of the returned list is not fixed.
29 */
30 List.filled(int length, E fill);
31
32 /**
33 * Creates an list with the elements of [other]. The order in
24 * the list will be the order provided by the iterator of [other]. 34 * the list will be the order provided by the iterator of [other].
35 *
36 * The length of the returned list is not fixed.
25 */ 37 */
26 List.from(Iterable<E> other); 38 List.from(Iterable<E> other);
27 39
28 /** 40 /**
29 * Returns the element at the given [index] in the list or throws 41 * Returns the element at the given [index] in the list or throws
30 * an [RangeError] if [index] is out of bounds. 42 * an [RangeError] if [index] is out of bounds.
31 */ 43 */
32 E operator [](int index); 44 E operator [](int index);
33 45
34 /** 46 /**
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 * not extendable. 172 * not extendable.
161 * If [length] is 0, this method does not do anything. 173 * If [length] is 0, this method does not do anything.
162 * Throws an [ArgumentError] if [length] is negative. 174 * Throws an [ArgumentError] if [length] is negative.
163 * Throws an [RangeError] if [start] or 175 * Throws an [RangeError] if [start] or
164 * [:start + length: - 1] are out of range. 176 * [:start + length: - 1] are out of range.
165 */ 177 */
166 void removeRange(int start, int length); 178 void removeRange(int start, int length);
167 179
168 /** 180 /**
169 * Inserts a new range into the list, starting from [start] to 181 * Inserts a new range into the list, starting from [start] to
170 * [:start + length - 1:]. The entries are filled with [initialValue]. 182 * [:start + length - 1:]. The entries are filled with [fill].
171 * Throws an [UnsupportedError] if the list is 183 * Throws an [UnsupportedError] if the list is
172 * not extendable. 184 * not extendable.
173 * If [length] is 0, this method does not do anything. 185 * If [length] is 0, this method does not do anything.
174 * If [start] is the length of the list, this method inserts the 186 * If [start] is the length of the list, this method inserts the
175 * range at the end of the list. 187 * range at the end of the list.
176 * Throws an [ArgumentError] if [length] is negative. 188 * Throws an [ArgumentError] if [length] is negative.
177 * Throws an [RangeError] if [start] is negative or if 189 * Throws an [RangeError] if [start] is negative or if
178 * [start] is greater than the length of the list. 190 * [start] is greater than the length of the list.
179 */ 191 */
180 void insertRange(int start, int length, [E initialValue]); 192 void insertRange(int start, int length, [E fill]);
181 } 193 }
182 194
183 class _ListImpl<E> { 195 class _ListImpl<E> {
184 /** 196 /**
185 * Factory implementation of List(). 197 * Factory implementation of List().
186 * 198 *
187 * Creates a list of the given [length]. 199 * Creates an extendable list of the given [length].
188 */ 200 */
189 external factory List([int length]); 201 external factory List([int length = 0]);
202
203 /**
204 * Creates a fixed-sized list of the given [length] where each entry is
205 * filled with [fill].
206 */
207 external factory List.fixedLength(int length, {E fill: null});
208
209 /**
210 * Creates an extendable list of the given [length] where each entry is
211 * filled with [fill].
212 */
213 external factory List.filled(int length, E fill);
190 214
191 /** 215 /**
192 * Factory implementation of List.from(). 216 * Factory implementation of List.from().
193 * 217 *
194 * Creates a list with the elements of [other]. The order in 218 * Creates a list with the elements of [other]. The order in
195 * the list will be the order provided by the iterator of [other]. 219 * the list will be the order provided by the iterator of [other].
196 */ 220 */
197 external factory List.from(Iterable<E> other); 221 external factory List.from(Iterable<E> other);
198 } 222 }
OLDNEW
« no previous file with comments | « sdk/lib/async/future_impl.dart ('k') | sdk/lib/core/map.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698