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 * All operations are defined in terms of `length`, `operator[]`, | 10 * All operations are defined in terms of `length`, `operator[]`, |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 throw new RangeError.range(end, start, this.length); | 357 throw new RangeError.range(end, start, this.length); |
358 } | 358 } |
359 int length = end - start; | 359 int length = end - start; |
360 List<E> result = new List<E>()..length = length; | 360 List<E> result = new List<E>()..length = length; |
361 for (int i = 0; i < length; i++) { | 361 for (int i = 0; i < length; i++) { |
362 result[i] = this[start + i]; | 362 result[i] = this[start + i]; |
363 } | 363 } |
364 return result; | 364 return result; |
365 } | 365 } |
366 | 366 |
367 List<E> getRange(int start, int length) => sublist(start, start + length); | 367 Iterable<E> getRange(int start, int end) { |
| 368 if (start < 0 || start > this.length) { |
| 369 throw new RangeError.range(start, 0, this.length); |
| 370 } |
| 371 if (end < start || end > this.length) { |
| 372 throw new RangeError.range(end, start, this.length); |
| 373 } |
| 374 return new SubListIterable(this, start, end); |
| 375 } |
368 | 376 |
369 void insertRange(int start, int length, [E initialValue]) { | 377 void insertRange(int start, int length, [E initialValue]) { |
370 if (start < 0 || start > this.length) { | 378 if (start < 0 || start > this.length) { |
371 throw new RangeError.range(start, 0, this.length); | 379 throw new RangeError.range(start, 0, this.length); |
372 } | 380 } |
373 int oldLength = this.length; | 381 int oldLength = this.length; |
374 int moveLength = oldLength - start; | 382 int moveLength = oldLength - start; |
375 this.length += length; | 383 this.length += length; |
376 if (moveLength > 0) { | 384 if (moveLength > 0) { |
377 this.setRange(start + length, moveLength, this, start); | 385 this.setRange(start + length, moveLength, this, start); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 for (int i = startIndex; i >= 0; i--) { | 466 for (int i = startIndex; i >= 0; i--) { |
459 if (this[i] == element) { | 467 if (this[i] == element) { |
460 return i; | 468 return i; |
461 } | 469 } |
462 } | 470 } |
463 return -1; | 471 return -1; |
464 } | 472 } |
465 | 473 |
466 Iterable<E> get reversed => new ReversedListIterable(this); | 474 Iterable<E> get reversed => new ReversedListIterable(this); |
467 } | 475 } |
OLD | NEW |