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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 int length = this.length; | 198 int length = this.length; |
199 for (int i = 0; i < length; i++) { | 199 for (int i = 0; i < length; i++) { |
200 value = combine(value, this[i]); | 200 value = combine(value, this[i]); |
201 if (length != this.length) { | 201 if (length != this.length) { |
202 throw new ConcurrentModificationError(this); | 202 throw new ConcurrentModificationError(this); |
203 } | 203 } |
204 } | 204 } |
205 return value; | 205 return value; |
206 } | 206 } |
207 | 207 |
208 Iterable<E> skip(int count) => new SubListIterable(this, count, null); | 208 Iterable<E> skip(int count) => new SubListIterable<E>(this, count, null); |
209 | 209 |
210 Iterable<E> skipWhile(bool test(E element)) { | 210 Iterable<E> skipWhile(bool test(E element)) { |
211 return new SkipWhileIterable<E>(this, test); | 211 return new SkipWhileIterable<E>(this, test); |
212 } | 212 } |
213 | 213 |
214 Iterable<E> take(int count) => new SubListIterable(this, 0, count); | 214 Iterable<E> take(int count) => new SubListIterable<E>(this, 0, count); |
215 | 215 |
216 Iterable<E> takeWhile(bool test(E element)) { | 216 Iterable<E> takeWhile(bool test(E element)) { |
217 return new TakeWhileIterable<E>(this, test); | 217 return new TakeWhileIterable<E>(this, test); |
218 } | 218 } |
219 | 219 |
220 List<E> toList({ bool growable: true }) { | 220 List<E> toList({ bool growable: true }) { |
221 List<E> result; | 221 List<E> result; |
222 if (growable) { | 222 if (growable) { |
223 result = new List<E>()..length = length; | 223 result = new List<E>()..length = length; |
224 } else { | 224 } else { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 int length = end - start; | 340 int length = end - start; |
341 List<E> result = new List<E>()..length = length; | 341 List<E> result = new List<E>()..length = length; |
342 for (int i = 0; i < length; i++) { | 342 for (int i = 0; i < length; i++) { |
343 result[i] = this[start + i]; | 343 result[i] = this[start + i]; |
344 } | 344 } |
345 return result; | 345 return result; |
346 } | 346 } |
347 | 347 |
348 Iterable<E> getRange(int start, int end) { | 348 Iterable<E> getRange(int start, int end) { |
349 _rangeCheck(start, end); | 349 _rangeCheck(start, end); |
350 return new SubListIterable(this, start, end); | 350 return new SubListIterable<E>(this, start, end); |
351 } | 351 } |
352 | 352 |
353 void removeRange(int start, int end) { | 353 void removeRange(int start, int end) { |
354 _rangeCheck(start, end); | 354 _rangeCheck(start, end); |
355 int length = end - start; | 355 int length = end - start; |
356 setRange(start, this.length - length, this, end); | 356 setRange(start, this.length - length, this, end); |
357 this.length -= length; | 357 this.length -= length; |
358 } | 358 } |
359 | 359 |
360 void fillRange(int start, int end, [E fill]) { | 360 void fillRange(int start, int end, [E fill]) { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 void setAll(int index, Iterable<E> iterable) { | 504 void setAll(int index, Iterable<E> iterable) { |
505 if (iterable is List) { | 505 if (iterable is List) { |
506 setRange(index, index + iterable.length, iterable); | 506 setRange(index, index + iterable.length, iterable); |
507 } else { | 507 } else { |
508 for (E element in iterable) { | 508 for (E element in iterable) { |
509 this[index++] = element; | 509 this[index++] = element; |
510 } | 510 } |
511 } | 511 } |
512 } | 512 } |
513 | 513 |
514 Iterable<E> get reversed => new ReversedListIterable(this); | 514 Iterable<E> get reversed => new ReversedListIterable<E>(this); |
515 | 515 |
516 String toString() => IterableBase.iterableToFullString(this, '[', ']'); | 516 String toString() => IterableBase.iterableToFullString(this, '[', ']'); |
517 } | 517 } |
OLD | NEW |