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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 } | 382 } |
383 } else { | 383 } else { |
384 for (int i = 0; i < length; i++) { | 384 for (int i = 0; i < length; i++) { |
385 this[start + i] = otherList[otherStart + i]; | 385 this[start + i] = otherList[otherStart + i]; |
386 } | 386 } |
387 } | 387 } |
388 } | 388 } |
389 | 389 |
390 void replaceRange(int start, int end, Iterable<E> newContents) { | 390 void replaceRange(int start, int end, Iterable<E> newContents) { |
391 RangeError.checkValidRange(start, end, this.length); | 391 RangeError.checkValidRange(start, end, this.length); |
392 if (newContents is! EfficientLength) { | 392 if (newContents is! EfficientLengthIterable) { |
393 newContents = newContents.toList(); | 393 newContents = newContents.toList(); |
394 } | 394 } |
395 int removeLength = end - start; | 395 int removeLength = end - start; |
396 int insertLength = newContents.length; | 396 int insertLength = newContents.length; |
397 if (removeLength >= insertLength) { | 397 if (removeLength >= insertLength) { |
398 int delta = removeLength - insertLength; | 398 int delta = removeLength - insertLength; |
399 int insertEnd = start + insertLength; | 399 int insertEnd = start + insertLength; |
400 int newLength = this.length - delta; | 400 int newLength = this.length - delta; |
401 this.setRange(start, insertEnd, newContents); | 401 this.setRange(start, insertEnd, newContents); |
402 if (delta != 0) { | 402 if (delta != 0) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 | 469 |
470 E removeAt(int index) { | 470 E removeAt(int index) { |
471 E result = this[index]; | 471 E result = this[index]; |
472 setRange(index, this.length - 1, this, index + 1); | 472 setRange(index, this.length - 1, this, index + 1); |
473 length--; | 473 length--; |
474 return result; | 474 return result; |
475 } | 475 } |
476 | 476 |
477 void insertAll(int index, Iterable<E> iterable) { | 477 void insertAll(int index, Iterable<E> iterable) { |
478 RangeError.checkValueInInterval(index, 0, length, "index"); | 478 RangeError.checkValueInInterval(index, 0, length, "index"); |
479 if (iterable is EfficientLength) { | 479 if (iterable is EfficientLengthIterable) { |
480 iterable = iterable.toList(); | 480 iterable = iterable.toList(); |
481 } | 481 } |
482 int insertionLength = iterable.length; | 482 int insertionLength = iterable.length; |
483 // There might be errors after the length change, in which case the list | 483 // There might be errors after the length change, in which case the list |
484 // will end up being modified but the operation not complete. Unless we | 484 // will end up being modified but the operation not complete. Unless we |
485 // always go through a "toList" we can't really avoid that. | 485 // always go through a "toList" we can't really avoid that. |
486 this.length += insertionLength; | 486 this.length += insertionLength; |
487 setRange(index + insertionLength, this.length, this, index); | 487 setRange(index + insertionLength, this.length, this, index); |
488 setAll(index, iterable); | 488 setAll(index, iterable); |
489 } | 489 } |
490 | 490 |
491 void setAll(int index, Iterable<E> iterable) { | 491 void setAll(int index, Iterable<E> iterable) { |
492 if (iterable is List) { | 492 if (iterable is List) { |
493 setRange(index, index + iterable.length, iterable); | 493 setRange(index, index + iterable.length, iterable); |
494 } else { | 494 } else { |
495 for (E element in iterable) { | 495 for (E element in iterable) { |
496 this[index++] = element; | 496 this[index++] = element; |
497 } | 497 } |
498 } | 498 } |
499 } | 499 } |
500 | 500 |
501 Iterable<E> get reversed => new ReversedListIterable<E>(this); | 501 Iterable<E> get reversed => new ReversedListIterable<E>(this); |
502 | 502 |
503 String toString() => IterableBase.iterableToFullString(this, '[', ']'); | 503 String toString() => IterableBase.iterableToFullString(this, '[', ']'); |
504 } | 504 } |
OLD | NEW |