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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 Iterable<E> getRange(int start, int end) { | 317 Iterable<E> getRange(int start, int end) { |
318 if (start < 0 || start > this.length) { | 318 if (start < 0 || start > this.length) { |
319 throw new RangeError.range(start, 0, this.length); | 319 throw new RangeError.range(start, 0, this.length); |
320 } | 320 } |
321 if (end < start || end > this.length) { | 321 if (end < start || end > this.length) { |
322 throw new RangeError.range(end, start, this.length); | 322 throw new RangeError.range(end, start, this.length); |
323 } | 323 } |
324 return new SubListIterable(this, start, end); | 324 return new SubListIterable(this, start, end); |
325 } | 325 } |
326 | 326 |
327 void insertRange(int start, int length, [E initialValue]) { | 327 void removeRange(int start, int end) { |
328 if (start < 0 || start > this.length) { | 328 if (start < 0 || start > this.length) { |
329 throw new RangeError.range(start, 0, this.length); | 329 throw new RangeError.range(start, 0, this.length); |
330 } | 330 } |
331 int oldLength = this.length; | 331 if (end < start || end > this.length) { |
332 int moveLength = oldLength - start; | 332 throw new RangeError.range(end, start, this.length); |
333 this.length += length; | |
334 if (moveLength > 0) { | |
335 this.setRange(start + length, oldLength, this, start); | |
336 } | 333 } |
337 for (int i = 0; i < length; i++) { | 334 int length = end - start; |
338 this[start + i] = initialValue; | |
339 } | |
340 } | |
341 | |
342 void removeRange(int start, int length) { | |
343 if (start < 0 || start > this.length) { | |
344 throw new RangeError.range(start, 0, this.length); | |
345 } | |
346 if (length < 0 || start + length > this.length) { | |
347 throw new RangeError.range(length, 0, this.length - start); | |
348 } | |
349 int end = start + length; | |
350 setRange(start, this.length - length, this, end); | 335 setRange(start, this.length - length, this, end); |
351 this.length -= length; | 336 this.length -= length; |
352 } | 337 } |
353 | 338 |
354 void clearRange(int start, int length, [E fill]) { | 339 void clearRange(int start, int length, [E fill]) { |
355 for (int i = 0; i < length; i++) { | 340 for (int i = 0; i < length; i++) { |
356 this[start + i] = fill; | 341 this[start + i] = fill; |
357 } | 342 } |
358 } | 343 } |
359 | 344 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 return i; | 415 return i; |
431 } | 416 } |
432 } | 417 } |
433 return -1; | 418 return -1; |
434 } | 419 } |
435 | 420 |
436 Iterable<E> get reversed => new ReversedListIterable(this); | 421 Iterable<E> get reversed => new ReversedListIterable(this); |
437 | 422 |
438 String toString() => ToString.iterableToString(this); | 423 String toString() => ToString.iterableToString(this); |
439 } | 424 } |
OLD | NEW |