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 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 * If no [length] argument is supplied an extendable list of |
15 * length 0 is created. | 15 * length 0 is created. |
16 * | 16 * |
17 * If a [length] argument is supplied, a fixed size list of that | 17 * If a [length] argument is supplied, a fixed size list of that |
18 * length is created. | 18 * length is created. |
19 */ | 19 */ |
20 List([int length]); | 20 List([int length]); |
21 | 21 |
22 /** | 22 /** |
23 * Creates a list with the elements of [other]. The order in | 23 * Creates a list with the elements of [other]. The order in |
24 * the list will be the order provided by the iterator of [other]. | 24 * the list will be the order provided by the iterator of [other]. |
25 */ | 25 */ |
26 List.from(Iterable<E> other); | 26 List.from(Iterable<E> other); |
27 | 27 |
28 /** | 28 /** |
29 * Returns the element at the given [index] in the list or throws | 29 * Returns the element at the given [index] in the list or throws |
30 * an [IndexOutOfRangeException] if [index] is out of bounds. | 30 * an [RangeError] if [index] is out of bounds. |
31 */ | 31 */ |
32 E operator [](int index); | 32 E operator [](int index); |
33 | 33 |
34 /** | 34 /** |
35 * Sets the entry at the given [index] in the list to [value]. | 35 * Sets the entry at the given [index] in the list to [value]. |
36 * Throws an [IndexOutOfRangeException] if [index] is out of bounds. | 36 * Throws an [RangeError] if [index] is out of bounds. |
37 */ | 37 */ |
38 void operator []=(int index, E value); | 38 void operator []=(int index, E value); |
39 | 39 |
40 /** | 40 /** |
41 * Changes the length of the list. If [newLength] is greater than | 41 * Changes the length of the list. If [newLength] is greater than |
42 * the current [length], entries are initialized to [:null:]. Throws | 42 * the current [length], entries are initialized to [:null:]. Throws |
43 * an [UnsupportedError] if the list is not extendable. | 43 * an [UnsupportedError] if the list is not extendable. |
44 */ | 44 */ |
45 void set length(int newLength); | 45 void set length(int newLength); |
46 | 46 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 */ | 101 */ |
102 void clear(); | 102 void clear(); |
103 | 103 |
104 /** | 104 /** |
105 * Removes the element at position[index] from the list. | 105 * Removes the element at position[index] from the list. |
106 * | 106 * |
107 * This reduces the length of the list by one and moves all later elements | 107 * This reduces the length of the list by one and moves all later elements |
108 * down by one position. | 108 * down by one position. |
109 * Returns the removed element. | 109 * Returns the removed element. |
110 * Throws an [ArgumentError] if [index] is not an [int]. | 110 * Throws an [ArgumentError] if [index] is not an [int]. |
111 * Throws an [IndexOutOfRangeException] if the [index] does not point inside | 111 * Throws an [RangeError] if the [index] does not point inside |
112 * the list. | 112 * the list. |
113 * Throws an [UnsupportedError], and doesn't remove the element, | 113 * Throws an [UnsupportedError], and doesn't remove the element, |
114 * if the length of the list cannot be changed. | 114 * if the length of the list cannot be changed. |
115 */ | 115 */ |
116 E removeAt(int index); | 116 E removeAt(int index); |
117 | 117 |
118 /** | 118 /** |
119 * Pops and returns the last element of the list. | 119 * Pops and returns the last element of the list. |
120 * Throws a [UnsupportedError] if the length of the | 120 * Throws a [UnsupportedError] if the length of the |
121 * list cannot be changed. | 121 * list cannot be changed. |
122 */ | 122 */ |
123 E removeLast(); | 123 E removeLast(); |
124 | 124 |
125 /** | 125 /** |
126 * Returns the last element of the list, or throws an out of bounds | 126 * Returns the last element of the list, or throws an out of bounds |
127 * exception if the list is empty. | 127 * exception if the list is empty. |
128 */ | 128 */ |
129 E get last; | 129 E get last; |
130 | 130 |
131 /** | 131 /** |
132 * Returns a new list containing [length] elements from the list, | 132 * Returns a new list containing [length] elements from the list, |
133 * starting at [start]. | 133 * starting at [start]. |
134 * Returns an empty list if [length] is 0. | 134 * Returns an empty list if [length] is 0. |
135 * Throws an [ArgumentError] if [length] is negative. | 135 * Throws an [ArgumentError] if [length] is negative. |
136 * Throws an [IndexOutOfRangeException] if [start] or | 136 * Throws an [RangeError] if [start] or |
137 * [:start + length - 1:] are out of range. | 137 * [:start + length - 1:] are out of range. |
138 */ | 138 */ |
139 List<E> getRange(int start, int length); | 139 List<E> getRange(int start, int length); |
140 | 140 |
141 /** | 141 /** |
142 * Copies [length] elements of [from], starting | 142 * Copies [length] elements of [from], starting |
143 * at [startFrom], into the list, starting at [start]. | 143 * at [startFrom], into the list, starting at [start]. |
144 * If [length] is 0, this method does not do anything. | 144 * If [length] is 0, this method does not do anything. |
145 * Throws an [ArgumentError] if [length] is negative. | 145 * Throws an [ArgumentError] if [length] is negative. |
146 * Throws an [IndexOutOfRangeException] if [start] or | 146 * Throws an [RangeError] if [start] or |
147 * [:start + length - 1:] are out of range for [:this:], or if | 147 * [:start + length - 1:] are out of range for [:this:], or if |
148 * [startFrom] or [:startFrom + length - 1:] are out of range for [from]. | 148 * [startFrom] or [:startFrom + length - 1:] are out of range for [from]. |
149 */ | 149 */ |
150 void setRange(int start, int length, List<E> from, [int startFrom]); | 150 void setRange(int start, int length, List<E> from, [int startFrom]); |
151 | 151 |
152 /** | 152 /** |
153 * Removes [length] elements from the list, beginning at [start]. | 153 * Removes [length] elements from the list, beginning at [start]. |
154 * Throws an [UnsupportedError] if the list is | 154 * Throws an [UnsupportedError] if the list is |
155 * not extendable. | 155 * not extendable. |
156 * If [length] is 0, this method does not do anything. | 156 * If [length] is 0, this method does not do anything. |
157 * Throws an [ArgumentError] if [length] is negative. | 157 * Throws an [ArgumentError] if [length] is negative. |
158 * Throws an [IndexOutOfRangeException] if [start] or | 158 * Throws an [RangeError] if [start] or |
159 * [:start + length: - 1] are out of range. | 159 * [:start + length: - 1] are out of range. |
160 */ | 160 */ |
161 void removeRange(int start, int length); | 161 void removeRange(int start, int length); |
162 | 162 |
163 /** | 163 /** |
164 * Inserts a new range into the list, starting from [start] to | 164 * Inserts a new range into the list, starting from [start] to |
165 * [:start + length - 1:]. The entries are filled with [initialValue]. | 165 * [:start + length - 1:]. The entries are filled with [initialValue]. |
166 * Throws an [UnsupportedError] if the list is | 166 * Throws an [UnsupportedError] if the list is |
167 * not extendable. | 167 * not extendable. |
168 * If [length] is 0, this method does not do anything. | 168 * If [length] is 0, this method does not do anything. |
169 * If [start] is the length of the list, this method inserts the | 169 * If [start] is the length of the list, this method inserts the |
170 * range at the end of the list. | 170 * range at the end of the list. |
171 * Throws an [ArgumentError] if [length] is negative. | 171 * Throws an [ArgumentError] if [length] is negative. |
172 * Throws an [IndexOutOfRangeException] if [start] is negative or if | 172 * Throws an [RangeError] if [start] is negative or if |
173 * [start] is greater than the length of the list. | 173 * [start] is greater than the length of the list. |
174 */ | 174 */ |
175 void insertRange(int start, int length, [E initialValue]); | 175 void insertRange(int start, int length, [E initialValue]); |
176 } | 176 } |
177 | 177 |
178 class _ListImpl<E> { | 178 class _ListImpl<E> { |
179 /** | 179 /** |
180 * Factory implementation of List(). | 180 * Factory implementation of List(). |
181 * | 181 * |
182 * Creates a list of the given [length]. | 182 * Creates a list of the given [length]. |
183 */ | 183 */ |
184 external factory List([int length]); | 184 external factory List([int length]); |
185 | 185 |
186 /** | 186 /** |
187 * Factory implementation of List.from(). | 187 * Factory implementation of List.from(). |
188 * | 188 * |
189 * Creates a list with the elements of [other]. The order in | 189 * Creates a list with the elements of [other]. The order in |
190 * the list will be the order provided by the iterator of [other]. | 190 * the list will be the order provided by the iterator of [other]. |
191 */ | 191 */ |
192 external factory List.from(Iterable<E> other); | 192 external factory List.from(Iterable<E> other); |
193 } | 193 } |
OLD | NEW |