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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 throw new RangeError.range(end, start, this.length); | 322 throw new RangeError.range(end, start, this.length); |
323 } | 323 } |
324 int length = end - start; | 324 int length = end - start; |
325 List<E> result = new List<E>()..length = length; | 325 List<E> result = new List<E>()..length = length; |
326 for (int i = 0; i < length; i++) { | 326 for (int i = 0; i < length; i++) { |
327 result[i] = this[start + i]; | 327 result[i] = this[start + i]; |
328 } | 328 } |
329 return result; | 329 return result; |
330 } | 330 } |
331 | 331 |
332 List<E> getRange(int start, int length) => sublist(start, start + length); | 332 Iterable<E> getRange(int start, int end) { |
| 333 if (start < 0 || start > this.length) { |
| 334 throw new RangeError.range(start, 0, this.length); |
| 335 } |
| 336 if (end < start || end > this.length) { |
| 337 throw new RangeError.range(end, start, this.length); |
| 338 } |
| 339 return new SubListIterable(this, start, end); |
| 340 } |
333 | 341 |
334 void insertRange(int start, int length, [E initialValue]) { | 342 void insertRange(int start, int length, [E initialValue]) { |
335 if (start < 0 || start > this.length) { | 343 if (start < 0 || start > this.length) { |
336 throw new RangeError.range(start, 0, this.length); | 344 throw new RangeError.range(start, 0, this.length); |
337 } | 345 } |
338 int oldLength = this.length; | 346 int oldLength = this.length; |
339 int moveLength = oldLength - start; | 347 int moveLength = oldLength - start; |
340 this.length += length; | 348 this.length += length; |
341 if (moveLength > 0) { | 349 if (moveLength > 0) { |
342 this.setRange(start + length, moveLength, this, start); | 350 this.setRange(start + length, moveLength, this, start); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 for (int i = startIndex; i >= 0; i--) { | 431 for (int i = startIndex; i >= 0; i--) { |
424 if (this[i] == element) { | 432 if (this[i] == element) { |
425 return i; | 433 return i; |
426 } | 434 } |
427 } | 435 } |
428 return -1; | 436 return -1; |
429 } | 437 } |
430 | 438 |
431 Iterable<E> get reversed => new ReversedListIterable(this); | 439 Iterable<E> get reversed => new ReversedListIterable(this); |
432 } | 440 } |
OLD | NEW |