Chromium Code Reviews| 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 * An indexable collection of objects with a length. |
| 9 * | 9 * |
| 10 * A `List` implementation can choose not to support all methods | 10 * Subclasses of this class implement different kinds of lists. |
| 11 * of the `List` interface. | 11 * The most common kinds of lists are: |
| 12 * | 12 * |
| 13 * The most common list types are: | 13 * * Fixed-length list. |
| 14 * * Fixed length list. It is an error to use operations that can change | 14 * An error occurs when attempting to use operations |
| 15 * the list's length. | 15 * that can change the length of the list. |
| 16 * * Growable list. Full implementation of the interface. | |
| 17 * * Unmodifiable list. It is an error to use operations that can change | |
| 18 * the list's length, or that can change the values of the list. | |
| 19 * If an unmodifable list is backed by another modifiable data structure, | |
| 20 * the values read from it may still change over time. | |
| 21 * | 16 * |
| 22 * Example: | 17 * * Growable list. Full implementation of the API defined in this class. |
| 18 * | |
| 19 * The following code illustrates that some List implementations support | |
| 20 * only a subset of the API. | |
| 23 * | 21 * |
| 24 * var fixedLengthList = new List(5); | 22 * var fixedLengthList = new List(5); |
| 25 * fixedLengthList.length = 0; // throws. | 23 * fixedLengthList.length = 0; // Error. |
| 26 * fixedLengthList.add(499); // throws | 24 * fixedLengthList.add(499); // Error. |
| 27 * fixedLengthList[0] = 87; | 25 * fixedLengthList[0] = 87; |
| 26 * | |
| 28 * var growableList = [1, 2]; | 27 * var growableList = [1, 2]; |
| 29 * growableList.length = 0; | 28 * growableList.length = 0; |
| 30 * growableList.add(499); | 29 * growableList.add(499); |
| 31 * growableList[0] = 87; | 30 * growableList[0] = 87; |
| 32 * var unmodifiableList = const [1, 2]; | |
| 33 * unmodifiableList.length = 0; // throws. | |
| 34 * unmodifiableList.add(499); // throws | |
| 35 * unmodifiableList[0] = 87; // throws. | |
| 36 * | 31 * |
| 37 * Lists are [Iterable]. | 32 * Lists are [Iterable]. |
| 38 * List iteration iterates over values in index order. | 33 * Iteration occurs over values in index order. |
| 39 * Changing the values will not affect iteration, | 34 * Changing the values does not affect iteration, |
| 40 * but changing the valid indices - | 35 * but changing the valid indices—that is, |
| 41 * that is, changing the list's length - | 36 * changing the list's length—between |
| 42 * between iteration steps | 37 * iteration steps |
| 43 * will cause a [ConcurrentModificationError]. | 38 * causes a [ConcurrentModificationError]. |
| 44 * This means that only growable lists can throw [ConcurrentModificationError]. | 39 * This means that only growable lists can throw [ConcurrentModificationError]. |
| 45 * If the length changes temporarily | 40 * If the length changes temporarily |
| 46 * and is restored before continuing the iteration, | 41 * and is restored before continuing the iteration, |
| 47 * the iterator will not detect it. | 42 * the iterator does not detect it. |
| 48 */ | 43 */ |
| 49 abstract class List<E> implements Iterable<E> { | 44 abstract class List<E> implements Iterable<E> { |
| 50 /** | 45 /** |
| 51 * Creates a list of the given [length]. | 46 * Creates a list of the given [length]. |
| 52 * | 47 * |
| 53 * The list is a fixed-length list if [length] is provided, and an empty | 48 * The list is fixed-length if [length] is provided. |
| 54 * growable list if [length] is omitted. | 49 * The list has length 0 and is growable if [length] is omitted. |
| 55 * | 50 * |
| 56 * It is an error if [length] is not a non-negative integer. | 51 * An error occurs if [length] is negative. |
| 57 */ | 52 */ |
| 58 external factory List([int length]); | 53 external factory List([int length]); |
| 59 | 54 |
| 60 /** | 55 /** |
| 61 * Creates a fixed-length list of the given [length] where each entry | 56 * Creates a fixed-length list of the given [length] |
| 62 * contains [fill]. | 57 * and initializes the value at each position with [fill]. |
| 63 */ | 58 */ |
| 64 external factory List.filled(int length, E fill); | 59 external factory List.filled(int length, E fill); |
| 65 | 60 |
| 66 /** | 61 /** |
| 67 * Creates an list with the elements of [other]. | 62 * Creates a list and initializes it using the contents of [other]. |
| 68 * | 63 * |
| 69 * The order in the list will be | 64 * The [Iterator] of [other] provides the order of the objects. |
| 70 * the order provided by the iterator of [other]. | |
| 71 * | 65 * |
| 72 * The returned list is growable if [growable] is true, otherwise it's | 66 * This constructor returns a growable list if [growable] is true; |
| 73 * a fixed length list. | 67 * otherwise, it returns a fixed-length list. |
| 74 */ | 68 */ |
| 75 factory List.from(Iterable other, { bool growable: true }) { | 69 factory List.from(Iterable other, { bool growable: true }) { |
| 76 List<E> list = new List<E>(); | 70 List<E> list = new List<E>(); |
| 77 for (E e in other) { | 71 for (E e in other) { |
| 78 list.add(e); | 72 list.add(e); |
| 79 } | 73 } |
| 80 if (growable) return list; | 74 if (growable) return list; |
| 81 int length = list.length; | 75 int length = list.length; |
| 82 List<E> fixedList = new List<E>(length); | 76 List<E> fixedList = new List<E>(length); |
| 83 for (int i = 0; i < length; i++) { | 77 for (int i = 0; i < length; i++) { |
| 84 fixedList[i] = list[i]; | 78 fixedList[i] = list[i]; |
| 85 } | 79 } |
| 86 return fixedList; | 80 return fixedList; |
| 87 } | 81 } |
| 88 | 82 |
| 89 /** | 83 /** |
| 90 * Generate a `List` of values. | 84 * Generates a list of values. |
| 91 * | 85 * |
| 92 * Creates a list with [length] positions | 86 * Creates a list with _length_ positions |
| 93 * and fills them by values created by calling [generator] | 87 * and fills it with values created by calling [generator] |
| 94 * for each index in the range `0` .. `[length] - 1` | 88 * for each index in the range `0` .. `length - 1` |
| 95 * in increasing order. | 89 * in increasing order. |
| 96 * | 90 * |
| 97 * The created list's length is fixed unless [growable] is true. | 91 * The created list is of fixed-length unless [growable] is true. |
|
Kathy Walrath
2013/08/20 21:39:34
Technically, it should be "fixed length" (no hyphe
mem
2013/08/20 23:18:19
Done.
| |
| 98 */ | 92 */ |
| 99 factory List.generate(int length, E generator(int index), | 93 factory List.generate(int length, E generator(int index), |
| 100 { bool growable: true }) { | 94 { bool growable: true }) { |
| 101 List<E> result; | 95 List<E> result; |
| 102 if (growable) { | 96 if (growable) { |
| 103 result = <E>[]..length = length; | 97 result = <E>[]..length = length; |
| 104 } else { | 98 } else { |
| 105 result = new List<E>(length); | 99 result = new List<E>(length); |
| 106 } | 100 } |
| 107 for (int i = 0; i < length; i++) { | 101 for (int i = 0; i < length; i++) { |
| 108 result[i] = generator(i); | 102 result[i] = generator(i); |
| 109 } | 103 } |
| 110 return result; | 104 return result; |
| 111 } | 105 } |
| 112 | 106 |
| 113 /** | 107 /** |
| 114 * Returns the element at the given [index] in the list or throws | 108 * Returns the object at the given [index] in the list |
| 115 * an [RangeError] if [index] is out of bounds. | 109 * or throws a [RangeError] if [index] is out of bounds. |
| 116 */ | 110 */ |
| 117 E operator [](int index); | 111 E operator [](int index); |
| 118 | 112 |
| 119 /** | 113 /** |
| 120 * Sets the entry at the given [index] in the list to [value]. | 114 * Sets the value at the given [index] in the list to [value] |
| 121 * | 115 * or throws a [RangeError] if [index] is out of bounds. |
| 122 * Throws an [RangeError] if [index] is out of bounds. | |
| 123 */ | 116 */ |
| 124 void operator []=(int index, E value); | 117 void operator []=(int index, E value); |
| 125 | 118 |
| 126 /** | 119 /** |
| 127 * Returns the number of elements in the list. | 120 * Returns the number of objects in the list. |
| 128 * | 121 * |
| 129 * The valid indices for a list are 0 through `length - 1`. | 122 * The valid indices for a list are 0 through `length - 1`. |
| 130 */ | 123 */ |
| 131 int get length; | 124 int get length; |
| 132 | 125 |
| 133 /** | 126 /** |
| 134 * Changes the length of the list. If [newLength] is greater than | 127 * Changes the length of the list. |
| 128 * | |
| 129 * If [newLength] is greater than | |
| 135 * the current [length], entries are initialized to [:null:]. | 130 * the current [length], entries are initialized to [:null:]. |
| 136 * | 131 * |
| 137 * Throws an [UnsupportedError] if the list is not extendable. | 132 * Throws an [UnsupportedError] if the list is fixed-length. |
| 138 */ | 133 */ |
| 139 void set length(int newLength); | 134 void set length(int newLength); |
| 140 | 135 |
| 141 /** | 136 /** |
| 142 * Adds [value] at the end of the list, extending the length by | 137 * Adds [value] to the end of the list, |
|
Kathy Walrath
2013/08/20 21:39:34
the list -> this list
[global]
mem
2013/08/20 23:18:19
Done.
| |
| 143 * one. | 138 * extending the length by one. |
| 144 * | 139 * |
| 145 * Throws an [UnsupportedError] if the list is not extendable. | 140 * Throws an [UnsupportedError] if the list is fixed-length. |
| 146 */ | 141 */ |
| 147 void add(E value); | 142 void add(E value); |
| 148 | 143 |
| 149 /** | 144 /** |
| 150 * Appends all elements of the [iterable] to the end of this list. | 145 * Appends all objects of [iterable] to the end of this list. |
| 151 * | 146 * |
| 152 * Extends the length of the list by the number of elements in [iterable]. | 147 * Extends the length of the list by the number of objects in [iterable]. |
| 153 * Throws an [UnsupportedError] if this list is not extensible. | 148 * Throws an [UnsupportedError] if this list is fixed-length. |
| 154 */ | 149 */ |
| 155 void addAll(Iterable<E> iterable); | 150 void addAll(Iterable<E> iterable); |
| 156 | 151 |
| 157 /** | 152 /** |
| 158 * Returns an [Iterable] of the elements of this [List] in reverse order. | 153 * Returns an [Iterable] of the objects in this List in reverse order. |
|
Kathy Walrath
2013/08/20 21:39:34
this List -> this list
mem
2013/08/20 23:18:19
Done.
| |
| 159 */ | 154 */ |
| 160 Iterable<E> get reversed; | 155 Iterable<E> get reversed; |
| 161 | 156 |
| 162 /** | 157 /** |
| 163 * Sorts the list according to the order specified by the [compare] function. | 158 * Sorts the list according to the order specified by the [compare] function. |
| 164 * | 159 * |
| 165 * The [compare] function must act as a [Comparator]. | 160 * The [compare] function must act as a [Comparator]. |
| 166 * | 161 * |
| 167 * The default [List] implementations use [Comparable.compare] if | 162 * The default List implementations use [Comparable.compare] if |
| 168 * [compare] is omitted. | 163 * [compare] is omitted. |
| 169 */ | 164 */ |
| 170 void sort([int compare(E a, E b)]); | 165 void sort([int compare(E a, E b)]); |
| 171 | 166 |
| 172 /** | 167 /** |
| 173 * Returns the first index of [element] in the list. | 168 * Returns the first index of [element] in the list. |
| 174 * | 169 * |
| 175 * Searches the list from index [start] to the length of the list. | 170 * Searches the list from index [start] to the length of the list. |
| 176 * The first time an element [:e:] is encountered so that [:e == element:], | 171 * The first time an object [:o:] is encountered so that [:o == element:], |
| 177 * the index of [:e:] is returned. | 172 * the index of [:o:] is returned. |
| 178 * Returns -1 if [element] is not found. | 173 * Returns -1 if [element] is not found. |
| 179 */ | 174 */ |
| 180 int indexOf(E element, [int start = 0]); | 175 int indexOf(E element, [int start = 0]); |
| 181 | 176 |
| 182 /** | 177 /** |
| 183 * Returns the last index of [element] in the list. | 178 * Returns the last index of [element] in the list. |
| 184 * | 179 * |
| 185 * Searches the list backwards from index [start] (inclusive) to 0. | 180 * Searches the list backwards from index [start] to 0. |
| 186 * | 181 * |
| 187 * The first time an element [:e:] is encountered so that [:e == element:], | 182 * The first time an object [:o:] is encountered so that [:o == element:], |
| 188 * the index of [:e:] is returned. | 183 * the index of [:o:] is returned. |
| 189 * | 184 * |
| 190 * If start is not provided, it defaults to [:this.length - 1:]. | 185 * If [start] is not provided, it defaults to [:this.length - 1:]. |
| 191 * | 186 * |
| 192 * Returns -1 if [element] is not found. | 187 * Returns -1 if [element] is not found. |
| 193 */ | 188 */ |
| 194 int lastIndexOf(E element, [int start]); | 189 int lastIndexOf(E element, [int start]); |
| 195 | 190 |
| 196 /** | 191 /** |
| 197 * Removes all elements in the list. | 192 * Removes all objects from the list. |
| 198 * | |
| 199 * The length of the list becomes zero. | 193 * The length of the list becomes zero. |
| 200 * | 194 * |
| 201 * Throws an [UnsupportedError], and retains all elements, if the | 195 * Throws an [UnsupportedError], and retains all objects, if this |
| 202 * length of the list cannot be changed. | 196 * is a fixed-length list. |
| 203 */ | 197 */ |
| 204 void clear(); | 198 void clear(); |
| 205 | 199 |
| 206 /** | 200 /** |
| 207 * Inserts the element at position [index] in the list. | 201 * Inserts the object at position [index] in the list. |
| 208 * | 202 * |
| 209 * This increases the length of the list by one and shifts all elements | 203 * This increases the length of the list by one and shifts all objects |
| 210 * at or after the index towards the end of the list. | 204 * at or after the index towards the end of the list. |
| 211 * | 205 * |
| 212 * It is an error if the [index] does not point inside the list or at the | 206 * An error occurs if the [index] is less than 0 or greater than length. |
| 213 * position after the last element. | 207 * An [UnsupportedError] occurs if the list is fixed-length. |
| 214 */ | 208 */ |
| 215 void insert(int index, E element); | 209 void insert(int index, E element); |
| 216 | 210 |
| 217 /** | 211 /** |
| 218 * Inserts all elements of [iterable] at position [index] in the list. | 212 * Inserts all objects of [iterable] at position [index] in the list. |
| 219 * | 213 * |
| 220 * This increases the length of the list by the length of [iterable] and | 214 * This increases the length of the list by the length of [iterable] and |
| 221 * shifts all later elements towards the end of the list. | 215 * shifts all later objects towards the end of the list. |
| 222 * | 216 * |
| 223 * It is an error if the [index] does not point inside the list or at the | 217 * An error occurs if the [index] is less than 0 or greater than length. |
| 224 * position after the last element. | 218 * An [UnsupportedError] occurs if the list is fixed-length. |
| 225 */ | 219 */ |
| 226 void insertAll(int index, Iterable<E> iterable); | 220 void insertAll(int index, Iterable<E> iterable); |
| 227 | 221 |
| 228 /** | 222 /** |
| 229 * Overwrites elements of `this` with the elemenst of [iterable] starting | 223 * Overwrites objects of `this` with the objects of [iterable], starting |
| 230 * at position [index] in the list. | 224 * at position [index] in the list. |
| 231 * | 225 * |
| 232 * This operation does not increase the length of `this`. | 226 * This operation does not increase the length of `this`. |
| 233 * | 227 * |
| 234 * It is an error if the [index] does not point inside the list or at the | 228 * An error occurs if the [index] is less than 0 or greater than length. |
| 235 * position after the last element. | 229 * An error occurs if the [iterable] is longer than [length] - [index]. |
| 236 * | |
| 237 * It is an error if the [iterable] is longer than [length] - [index]. | |
| 238 */ | 230 */ |
| 239 void setAll(int index, Iterable<E> iterable); | 231 void setAll(int index, Iterable<E> iterable); |
| 240 | 232 |
| 241 /** | 233 /** |
| 242 * Removes [value] from the list. Returns true if [value] was | 234 * Removes [value] from the list. |
| 243 * in the list. Returns false otherwise. The method has no effect | 235 * |
| 244 * if [value] value was not in the list. | 236 * Returns true if [value] was in the list. |
| 237 * Returns false otherwise. | |
| 238 * The method has no effect if [value] was not in the list. | |
|
Kathy Walrath
2013/08/20 21:39:34
No UnsupportedError?
mem
2013/08/20 23:18:19
Done.
| |
| 245 */ | 239 */ |
| 246 bool remove(Object value); | 240 bool remove(Object value); |
| 247 | 241 |
| 248 /** | 242 /** |
| 249 * Removes the element at position [index] from the list. | 243 * Removes the object at position [index] from the list. |
| 250 * | 244 * |
| 251 * This reduces the length of `this` by one and moves all later elements | 245 * This method reduces the length of `this` by one and moves all later objects |
| 252 * down by one position. | 246 * down by one position. |
| 253 * | 247 * |
| 254 * Returns the removed element. | 248 * Returns the removed object. |
| 255 * | 249 * |
| 256 * Throws an [ArgumentError] if [index] is not an [int]. | 250 * * Throws an [ArgumentError] if [index] is not an [int]. |
| 257 * | 251 * * Throws a [RangeError] if the [index] is out of range for this list. |
| 258 * Throws an [RangeError] if the [index] does not point inside | 252 * * Throws an [UnsupportedError], and doesn't remove the object, |
| 259 * the list. | 253 * if this is a fixed-length list. |
| 260 * | |
| 261 * Throws an [UnsupportedError], and doesn't remove the element, | |
| 262 * if the length of `this` cannot be changed. | |
| 263 */ | 254 */ |
| 264 E removeAt(int index); | 255 E removeAt(int index); |
| 265 | 256 |
| 266 /** | 257 /** |
| 267 * Pops and returns the last element of the list. | 258 * Pops and returns the last object of the list. |
| 268 * Throws a [UnsupportedError] if the length of the | 259 * |
| 269 * list cannot be changed. | 260 * Throws an [UnsupportedError] if this is a fixed-length list. |
| 270 */ | 261 */ |
| 271 E removeLast(); | 262 E removeLast(); |
| 272 | 263 |
| 273 /** | 264 /** |
| 274 * Removes all elements of this list that satisfy [test]. | 265 * Removes all objects from this list that satisfy [test]. |
| 275 * | 266 * |
| 276 * An elements [:e:] satisfies [test] if [:test(e):] is true. | 267 * An object [:o:] satisfies [test] if [:test(o):] is true. |
| 268 * | |
| 269 * Throws an [UnsupportedError] if this is a fixed-length list. | |
| 277 */ | 270 */ |
| 278 void removeWhere(bool test(E element)); | 271 void removeWhere(bool test(E element)); |
| 279 | 272 |
| 280 /** | 273 /** |
| 281 * Removes all elements of this list that fail to satisfy [test]. | 274 * Removes all objects from this list that fail to satisfy [test]. |
| 282 * | 275 * |
| 283 * An elements [:e:] satisfies [test] if [:test(e):] is true. | 276 * An object [:o:] satisfies [test] if [:test(o):] is true. |
| 277 * | |
| 278 * Throws an [UnsupportedError] if this is a fixed-length list. | |
| 284 */ | 279 */ |
| 285 void retainWhere(bool test(E element)); | 280 void retainWhere(bool test(E element)); |
| 286 | 281 |
| 287 /** | 282 /** |
| 288 * Returns a new list containing the elements from [start] to [end]. | 283 * Returns a new list containing the objects |
| 289 * | 284 * from [start] inclusive to [end] exclusive. |
| 290 * The result contains elements of this list with indices greater than or | |
| 291 * equal to [start] and less than [end]. | |
| 292 * | 285 * |
| 293 * If [end] is omitted, the [length] of `this` is used. | 286 * If [end] is omitted, the [length] of `this` is used. |
| 294 * | 287 * |
| 295 * It is an error if [start] is outside the range `0` .. `[length]` or if | 288 * An error occurs if [start] is outside the range `0` .. `length` or if |
| 296 * [end] is outside the range `[start]` .. `[length]`. | 289 * [end] is outside the range `start` .. `length`. |
| 297 */ | 290 */ |
| 298 List<E> sublist(int start, [int end]); | 291 List<E> sublist(int start, [int end]); |
| 299 | 292 |
| 300 /** | 293 /** |
| 301 * Returns an [Iterable] that iterates over the elements in the range | 294 * Returns an [Iterable] that iterates over the objects in the range |
| 302 * [start] to [end] exclusive. The result of this function | 295 * [start] inclusive to [end] exclusive. |
| 303 * is backed by `this`. | |
| 304 * | 296 * |
| 305 * It is an error if [end] is before [start]. | 297 * An error occurs if [end] is before [start]. |
| 306 * | 298 * |
| 307 * It is an error if the [start] and [end] are not valid ranges at the time | 299 * An error occurs if the [start] and [end] are not valid ranges at the time |
| 308 * of the call to this method. The returned [Iterable] behaves similar to | 300 * of the call to this method. The returned [Iterable] behaves like |
| 309 * `skip(start).take(end - start)`. That is, it will not throw exceptions | 301 * `skip(start).take(end - start)`. That is, it does not throw exceptions |
| 310 * if `this` changes size. | 302 * if `this` changes size. |
| 311 * | 303 * |
| 312 * Example: | 304 * Example: |
| 313 * | 305 * |
| 314 * var list = [1, 2, 3, 4, 5]; | 306 * var list = [1, 2, 3, 4, 5]; |
| 315 * var range = list.getRange(1, 4); | 307 * var range = list.getRange(1, 4); |
| 316 * print(range.join(', ')); // => 2, 3, 4 | 308 * print(range.join(', ')); // => 2, 3, 4 |
| 317 * list.length = 3; | 309 * list.length = 3; |
| 318 * print(range.join(', ')); // => 2, 3 | 310 * print(range.join(', ')); // => 2, 3 |
| 319 */ | 311 */ |
| 320 Iterable<E> getRange(int start, int end); | 312 Iterable<E> getRange(int start, int end); |
| 321 | 313 |
| 322 /** | 314 /** |
| 323 * Copies the elements of [iterable], skipping the [skipCount] first elements, | 315 * Copies the objects of [iterable], skipping [skipCount] objects first, |
| 324 * into the range [start] to [end] exclusive of `this`. | 316 * into the range [start] inclusive to [end] exclusive of `this`. |
| 325 * | 317 * |
| 326 * If [start] equals [end] and [start]..[end] represents a legal range, this | 318 * If [start] equals [end] and [start]..[end] represents a legal range, this |
| 327 * method has no effect. | 319 * method has no effect. |
| 328 * | 320 * |
| 329 * It is an error if [start]..[end] is not a valid range pointing into the | 321 * An error occurs if [start]..[end] is not a valid range for `this`. |
| 330 * `this`. | 322 * An error occurs if the [iterable] does not have enough objects after |
| 331 * | 323 * skipping [skipCount] objects. |
| 332 * It is an error if the [iterable] does not have enough elements after | |
| 333 * skipping [skipCount] elements. | |
| 334 * | 324 * |
| 335 * Example: | 325 * Example: |
| 336 * | 326 * |
| 337 * var list = [1, 2, 3, 4]; | 327 * var list = [1, 2, 3, 4]; |
| 338 * var list2 = [5, 6, 7, 8, 9]; | 328 * var list2 = [5, 6, 7, 8, 9]; |
| 339 * list.setRange(1, 3, list2, 3); | 329 * list.setRange(1, 3, list2, 3); |
| 340 * print(list); // => [1, 8, 9, 4] | 330 * print(list); // => [1, 8, 9, 4] |
| 341 */ | 331 */ |
| 342 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]); | 332 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]); |
| 343 | 333 |
| 344 /** | 334 /** |
| 345 * Removes the elements in the range [start] to [end] exclusive. | 335 * Removes the objects in the range [start] inclusive to [end] exclusive. |
| 346 * | 336 * |
| 347 * It is an error if [start]..[end] is not a valid range pointing into the | 337 * An error occurs if [start]..[end] is not a valid range for `this`. |
| 348 * `this`. | 338 * Throws an [UnsupportedError] if this is a fixed-length list. |
| 349 */ | 339 */ |
| 350 void removeRange(int start, int end); | 340 void removeRange(int start, int end); |
| 351 | 341 |
| 352 /** | 342 /** |
| 353 * Sets the elements in the range [start] to [end] exclusive to the given | 343 * Sets the objects in the range [start] inclusive to [end] exclusive |
| 354 * [fillValue]. | 344 * to the given [fillValue]. |
| 355 * | 345 * |
| 356 * It is an error if [start]..[end] is not a valid range pointing into the | 346 * An error occurs if [start]..[end] is not a valid range for `this`. |
| 357 * `this`. | |
| 358 */ | 347 */ |
| 359 void fillRange(int start, int end, [E fillValue]); | 348 void fillRange(int start, int end, [E fillValue]); |
| 360 | 349 |
| 361 /** | 350 /** |
| 362 * Removes the elements in the range [start] to [end] exclusive and replaces | 351 * Removes the objects in the range [start] inclusive to [end] exclusive |
| 363 * them with the contents of the [iterable]. | 352 * and replaces them with the contents of the [iterable]. |
| 364 * | 353 * |
| 365 * It is an error if [start]..[end] is not a valid range pointing into the | 354 * An error occurs if [start]..[end] is not a valid range for `this`. |
| 366 * `this`. | |
| 367 * | 355 * |
| 368 * Example: | 356 * Example: |
| 369 * | 357 * |
| 370 * var list = [1, 2, 3, 4, 5]; | 358 * var list = [1, 2, 3, 4, 5]; |
| 371 * list.replaceRange(1, 3, [6, 7, 8, 9]); | 359 * list.replaceRange(1, 3, [6, 7, 8, 9]); |
| 372 * print(list); // [1, 6, 7, 8, 9, 4, 5] | 360 * print(list); // [1, 6, 7, 8, 9, 4, 5] |
| 373 */ | 361 */ |
| 374 void replaceRange(int start, int end, Iterable<E> iterable); | 362 void replaceRange(int start, int end, Iterable<E> iterable); |
| 375 | 363 |
| 376 /** | 364 /** |
| 377 * Returns an unmodifiable [Map] view of `this`. | 365 * Returns an unmodifiable [Map] view of `this`. |
| 378 * | 366 * |
| 379 * It has the indices of this list as keys, and the corresponding elements | 367 * The map uses the indices of this list as keys and the corresponding objects |
| 380 * as values. The [Map.keys] [Iterable] will iterate the indices of this list | 368 * as values. The `Map.keys` [Iterable] iterates the indices of this list |
| 381 * in numerical order. | 369 * in numerical order. |
| 382 */ | 370 */ |
| 383 Map<int, E> asMap(); | 371 Map<int, E> asMap(); |
| 384 } | 372 } |
| OLD | NEW |