OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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.collection; | 5 part of dart.collection; |
6 | 6 |
7 /** | 7 /** |
8 * Abstract implementation of a list. | 8 * Abstract implementation of a list. |
9 * | 9 * |
10 * `ListBase` can be used as a base class for implementing the `List` interface. | 10 * `ListBase` can be used as a base class for implementing the `List` interface. |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 } | 388 } |
389 } else { | 389 } else { |
390 for (int i = 0; i < length; i++) { | 390 for (int i = 0; i < length; i++) { |
391 this[start + i] = otherList[otherStart + i]; | 391 this[start + i] = otherList[otherStart + i]; |
392 } | 392 } |
393 } | 393 } |
394 } | 394 } |
395 | 395 |
396 void replaceRange(int start, int end, Iterable<E> newContents) { | 396 void replaceRange(int start, int end, Iterable<E> newContents) { |
397 RangeError.checkValidRange(start, end, this.length); | 397 RangeError.checkValidRange(start, end, this.length); |
398 if (newContents is! EfficientLength) { | 398 if (newContents is! EfficientLengthIterable) { |
399 newContents = newContents.toList(); | 399 newContents = newContents.toList(); |
400 } | 400 } |
401 int removeLength = end - start; | 401 int removeLength = end - start; |
402 int insertLength = newContents.length; | 402 int insertLength = newContents.length; |
403 if (removeLength >= insertLength) { | 403 if (removeLength >= insertLength) { |
404 int delta = removeLength - insertLength; | 404 int delta = removeLength - insertLength; |
405 int insertEnd = start + insertLength; | 405 int insertEnd = start + insertLength; |
406 int newLength = this.length - delta; | 406 int newLength = this.length - delta; |
407 this.setRange(start, insertEnd, newContents); | 407 this.setRange(start, insertEnd, newContents); |
408 if (delta != 0) { | 408 if (delta != 0) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 | 475 |
476 E removeAt(int index) { | 476 E removeAt(int index) { |
477 E result = this[index]; | 477 E result = this[index]; |
478 setRange(index, this.length - 1, this, index + 1); | 478 setRange(index, this.length - 1, this, index + 1); |
479 length--; | 479 length--; |
480 return result; | 480 return result; |
481 } | 481 } |
482 | 482 |
483 void insertAll(int index, Iterable<E> iterable) { | 483 void insertAll(int index, Iterable<E> iterable) { |
484 RangeError.checkValueInInterval(index, 0, length, "index"); | 484 RangeError.checkValueInInterval(index, 0, length, "index"); |
485 if (iterable is! EfficientLength || identical(iterable, this)) { | 485 if (iterable is! EfficientLengthIterable || identical(iterable, this)) { |
486 iterable = iterable.toList(); | 486 iterable = iterable.toList(); |
487 } | 487 } |
488 int insertionLength = iterable.length; | 488 int insertionLength = iterable.length; |
489 // There might be errors after the length change, in which case the list | 489 // There might be errors after the length change, in which case the list |
490 // will end up being modified but the operation not complete. Unless we | 490 // will end up being modified but the operation not complete. Unless we |
491 // always go through a "toList" we can't really avoid that. | 491 // always go through a "toList" we can't really avoid that. |
492 this.length += insertionLength; | 492 this.length += insertionLength; |
493 if (iterable.length != insertionLength) { | 493 if (iterable.length != insertionLength) { |
494 // If the iterable's length is linked to this list's length somehow, | 494 // If the iterable's length is linked to this list's length somehow, |
495 // we can't insert one in the other. | 495 // we can't insert one in the other. |
(...skipping 11 matching lines...) Expand all Loading... |
507 for (E element in iterable) { | 507 for (E element in iterable) { |
508 this[index++] = element; | 508 this[index++] = element; |
509 } | 509 } |
510 } | 510 } |
511 } | 511 } |
512 | 512 |
513 Iterable<E> get reversed => new ReversedListIterable<E>(this); | 513 Iterable<E> get reversed => new ReversedListIterable<E>(this); |
514 | 514 |
515 String toString() => IterableBase.iterableToFullString(this, '[', ']'); | 515 String toString() => IterableBase.iterableToFullString(this, '[', ']'); |
516 } | 516 } |
OLD | NEW |