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 * An indexable collection of objects with a length. | 8 * An indexable collection of objects with a length. |
| 9 * | 9 * |
| 10 * Subclasses of this class implement different kinds of lists. | 10 * Subclasses of this class implement different kinds of lists. |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 * | 408 * |
| 409 * An error occurs if [start] is outside the range `0` .. `length` or if | 409 * An error occurs if [start] is outside the range `0` .. `length` or if |
| 410 * [end] is outside the range `start` .. `length`. | 410 * [end] is outside the range `start` .. `length`. |
| 411 */ | 411 */ |
| 412 List<E> sublist(int start, [int end]); | 412 List<E> sublist(int start, [int end]); |
| 413 | 413 |
| 414 /** | 414 /** |
| 415 * Returns an [Iterable] that iterates over the objects in the range | 415 * Returns an [Iterable] that iterates over the objects in the range |
| 416 * [start] inclusive to [end] exclusive. | 416 * [start] inclusive to [end] exclusive. |
| 417 * | 417 * |
| 418 * An error occurs if [end] is before [start]. | 418 * The provide range, given by [start] and [end], must be valid at the time |
| 419 * of the call. | |
| 419 * | 420 * |
| 420 * An error occurs if the [start] and [end] are not valid ranges at the time | 421 * A range from [start] to [end] is valid if `0 <= start <= end <= len`, where |
| 421 * of the call to this method. The returned [Iterable] behaves like | 422 * `len` is this list's `length`. The range starts at `start` and has length |
| 422 * `skip(start).take(end - start)`. That is, it does not throw exceptions | 423 * `end - start`. An empty range (with `end == start`) is valid. |
| 423 * if `this` changes size. | 424 * |
| 425 * The returned [Iterable] behaves like `skip(start).take(end - start)`. | |
| 426 * That is, it does *not* throw exceptions if this list changes size. | |
|
Lasse Reichstein Nielsen
2017/01/17 15:56:59
Drop "exceptions" (it's errors if it's anything).
floitsch
2017/01/18 12:54:18
Done.
| |
| 424 * | 427 * |
| 425 * List<String> colors = ['red', 'green', 'blue', 'orange', 'pink']; | 428 * List<String> colors = ['red', 'green', 'blue', 'orange', 'pink']; |
| 426 * Iterable<String> range = colors.getRange(1, 4); | 429 * Iterable<String> range = colors.getRange(1, 4); |
| 427 * range.join(', '); // 'green, blue, orange' | 430 * range.join(', '); // 'green, blue, orange' |
| 428 * colors.length = 3; | 431 * colors.length = 3; |
| 429 * range.join(', '); // 'green, blue' | 432 * range.join(', '); // 'green, blue' |
| 430 */ | 433 */ |
| 431 Iterable<E> getRange(int start, int end); | 434 Iterable<E> getRange(int start, int end); |
| 432 | 435 |
| 433 /** | 436 /** |
| 434 * Copies the objects of [iterable], skipping [skipCount] objects first, | 437 * Copies the objects of [iterable], skipping [skipCount] objects first, |
| 435 * into the range [start], inclusive, to [end], exclusive, of the list. | 438 * into the range [start], inclusive, to [end], exclusive, of the list. |
| 436 * | 439 * |
| 437 * List<int> list1 = [1, 2, 3, 4]; | 440 * List<int> list1 = [1, 2, 3, 4]; |
| 438 * List<int> list2 = [5, 6, 7, 8, 9]; | 441 * List<int> list2 = [5, 6, 7, 8, 9]; |
| 439 * // Copies the 4th and 5th items in list2 as the 2nd and 3rd items | 442 * // Copies the 4th and 5th items in list2 as the 2nd and 3rd items |
| 440 * // of list1. | 443 * // of list1. |
| 441 * list1.setRange(1, 3, list2, 3); | 444 * list1.setRange(1, 3, list2, 3); |
| 442 * list1.join(', '); // '1, 8, 9, 4' | 445 * list1.join(', '); // '1, 8, 9, 4' |
| 443 * | 446 * |
| 444 * The [start] and [end] indices must satisfy `0 ≤ start ≤ end ≤ length`. | 447 * The provide range, given by [start] and [end], must be valid. |
| 445 * If [start] equals [end], this method has no effect. | 448 * A range from [start] to [end] is valid if `0 <= start <= end <= len`, where |
| 449 * `len` is this list's `length`. The range starts at `start` and has length | |
| 450 * `end - start`. An empty range (with `end == start`) is valid. | |
| 446 * | 451 * |
| 447 * The [iterable] must have enough objects to fill the range from `start` | 452 * The [iterable] must have enough objects to fill the range from `start` |
| 448 * to `end` after skipping [skipCount] objects. | 453 * to `end` after skipping [skipCount] objects. |
| 449 * | 454 * |
| 450 * If `iterable` is this list, the operation will copy the elements originally | 455 * If `iterable` is this list, the operation will copies the elements |
|
Lasse Reichstein Nielsen
2017/01/17 15:56:58
drop "will"
floitsch
2017/01/18 12:54:18
Done.
| |
| 451 * in the range from `skipCount` to `skipCount + (end - start)` to the | 456 * originally in the range from `skipCount` to `skipCount + (end - start)` to |
| 452 * range `start` to `end`, even if the two ranges overlap. | 457 * the range `start` to `end`, even if the two ranges overlap. |
| 453 * | 458 * |
| 454 * If `iterable` depends on this list in some other way, no guarantees are | 459 * If `iterable` depends on this list in some other way, no guarantees are |
| 455 * made. | 460 * made. |
| 456 */ | 461 */ |
| 457 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]); | 462 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]); |
| 458 | 463 |
| 459 /** | 464 /** |
| 460 * Removes the objects in the range [start] inclusive to [end] exclusive. | 465 * Removes the objects in the range [start] inclusive to [end] exclusive. |
| 461 * | 466 * |
| 462 * The [start] and [end] indices must be in the range | 467 * The provide range, given by [start] and [end], must be valid. |
| 463 * `0 ≤ index ≤ length`, and `start ≤ end`. | 468 * A range from [start] to [end] is valid if `0 <= start <= end <= len`, where |
| 469 * `len` is this list's `length`. The range starts at `start` and has length | |
| 470 * `end - start`. An empty range (with `end == start`) is valid. | |
| 464 * | 471 * |
| 465 * Throws an [UnsupportedError] if this is a fixed-length list. In that case | 472 * Throws an [UnsupportedError] if this is a fixed-length list. In that case |
| 466 * the list is not modified. | 473 * the list is not modified. |
| 467 */ | 474 */ |
| 468 void removeRange(int start, int end); | 475 void removeRange(int start, int end); |
| 469 | 476 |
| 470 /** | 477 /** |
| 471 * Sets the objects in the range [start] inclusive to [end] exclusive | 478 * Sets the objects in the range [start] inclusive to [end] exclusive |
| 472 * to the given [fillValue]. | 479 * to the given [fillValue]. |
| 473 * | 480 * |
| 474 * An error occurs if [start]..[end] is not a valid range for `this`. | 481 * The provide range, given by [start] and [end], must be valid. |
| 482 * A range from [start] to [end] is valid if `0 <= start <= end <= len`, where | |
| 483 * `len` is this list's `length`. The range starts at `start` and has length | |
| 484 * `end - start`. An empty range (with `end == start`) is valid. | |
| 475 */ | 485 */ |
| 476 void fillRange(int start, int end, [E fillValue]); | 486 void fillRange(int start, int end, [E fillValue]); |
| 477 | 487 |
| 478 /** | 488 /** |
| 479 * Removes the objects in the range [start] inclusive to [end] exclusive | 489 * Removes the objects in the range [start] inclusive to [end] exclusive |
| 480 * and inserts the contents of [replacement] in its place. | 490 * and inserts the contents of [replacement] in its place. |
| 481 * | 491 * |
| 482 * List<int> list = [1, 2, 3, 4, 5]; | 492 * List<int> list = [1, 2, 3, 4, 5]; |
| 483 * list.replaceRange(1, 4, [6, 7]); | 493 * list.replaceRange(1, 4, [6, 7]); |
| 484 * list.join(', '); // '1, 6, 7, 5' | 494 * list.join(', '); // '1, 6, 7, 5' |
| 485 * | 495 * |
| 486 * An error occurs if [start]..[end] is not a valid range for `this`. | 496 * The provide range, given by [start] and [end], must be valid. |
| 497 * A range from [start] to [end] is valid if `0 <= start <= end <= len`, where | |
| 498 * `len` is this list's `length`. The range starts at `start` and has length | |
| 499 * `end - start`. An empty range (with `end == start`) is valid. | |
| 487 * | 500 * |
| 488 * This method does not work on fixed-length lists, even when [replacement] | 501 * This method does not work on fixed-length lists, even when [replacement] |
| 489 * has the same number of elements as the replaced range. In that case use | 502 * has the same number of elements as the replaced range. In that case use |
| 490 * [setRange] instead. | 503 * [setRange] instead. |
| 491 */ | 504 */ |
| 492 void replaceRange(int start, int end, Iterable<E> replacement); | 505 void replaceRange(int start, int end, Iterable<E> replacement); |
| 493 | 506 |
| 494 /** | 507 /** |
| 495 * Returns an unmodifiable [Map] view of `this`. | 508 * Returns an unmodifiable [Map] view of `this`. |
| 496 * | 509 * |
| 497 * The map uses the indices of this list as keys and the corresponding objects | 510 * The map uses the indices of this list as keys and the corresponding objects |
| 498 * as values. The `Map.keys` [Iterable] iterates the indices of this list | 511 * as values. The `Map.keys` [Iterable] iterates the indices of this list |
| 499 * in numerical order. | 512 * in numerical order. |
| 500 * | 513 * |
| 501 * List<String> words = ['fee', 'fi', 'fo', 'fum']; | 514 * List<String> words = ['fee', 'fi', 'fo', 'fum']; |
| 502 * Map<int, String> map = words.asMap(); | 515 * Map<int, String> map = words.asMap(); |
| 503 * map[0] + map[1]; // 'feefi'; | 516 * map[0] + map[1]; // 'feefi'; |
| 504 * map.keys.toList(); // [0, 1, 2, 3] | 517 * map.keys.toList(); // [0, 1, 2, 3] |
| 505 */ | 518 */ |
| 506 Map<int, E> asMap(); | 519 Map<int, E> asMap(); |
| 507 } | 520 } |
| OLD | NEW |