Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 * This class provides default implementations for Iterables (including Lists). | 8 * This class provides default implementations for Iterables (including Lists). |
| 9 * | 9 * |
| 10 * Once Dart receives Mixins it will be replaced with mixin classes. | 10 * Once Dart receives Mixins it will be replaced with mixin classes. |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 // The generic type is currently lost. It will be fixed with mixins. | 340 // The generic type is currently lost. It will be fixed with mixins. |
| 341 // This is currently a List as well as an Iterable. | 341 // This is currently a List as well as an Iterable. |
| 342 return new SubListIterable(list, n, null); | 342 return new SubListIterable(list, n, null); |
| 343 } | 343 } |
| 344 | 344 |
| 345 static Iterable skipWhile(Iterable iterable, bool test(var value)) { | 345 static Iterable skipWhile(Iterable iterable, bool test(var value)) { |
| 346 // The generic type is currently lost. It will be fixed with mixins. | 346 // The generic type is currently lost. It will be fixed with mixins. |
| 347 return new SkipWhileIterable(iterable, test); | 347 return new SkipWhileIterable(iterable, test); |
| 348 } | 348 } |
| 349 | 349 |
| 350 static Iterable reversedList(List l) { | 350 static Iterable reversedList(List list) { |
| 351 return new ReversedListIterable(l); | 351 return new ReversedListIterable(list); |
| 352 } | 352 } |
| 353 | 353 |
| 354 static void sortList(List l, int compare(a, b)) { | 354 static void sortList(List list, int compare(a, b)) { |
| 355 if (compare == null) compare = Comparable.compare; | 355 if (compare == null) compare = Comparable.compare; |
| 356 Sort.sort(l, compare); | 356 Sort.sort(list, compare); |
| 357 } | |
| 358 | |
| 359 static int indexOfList(List list, var element, int start) { | |
| 360 return Arrays.indexOf(list, element, start, list.length); | |
| 361 } | |
| 362 | |
| 363 static int lastIndexOfList(List list, var element, int start) { | |
| 364 if (start == null) start = list.length - 1; | |
| 365 return Arrays.lastIndexOf(list, element, start); | |
| 366 } | |
| 367 | |
| 368 static void setRangeList(List list, int start, int length, | |
| 369 List from, int startFrom) { | |
| 370 if (length == 0) return; | |
| 371 | |
| 372 // TODO(floitsch): decide what to do with these checks. Currently copied | |
| 373 // since that was the old behavior of dart2js, and some co19 tests rely on | |
| 374 // it. | |
| 375 if (start is! int) throw new ArgumentError(start); | |
| 376 if (length is! int) throw new ArgumentError(length); | |
| 377 if (from is! List) throw new ArgumentError(from); | |
| 378 if (startFrom is! int) throw new ArgumentError(startFrom); | |
|
srdjan
2013/03/04 21:51:49
Please remove explicit type checks. Mark correspon
floitsch
2013/03/05 13:24:39
Done.
| |
| 379 if (length < 0) throw new ArgumentError(length); | |
| 380 if (start < 0) throw new RangeError.value(start); | |
| 381 if (start + length > list.length) { | |
| 382 throw new RangeError.value(start + length); | |
| 383 } | |
| 384 | |
| 385 Arrays.copy(from, startFrom, list, start, length); | |
| 357 } | 386 } |
| 358 | 387 |
| 359 static Map<int, dynamic> asMapList(List l) { | 388 static Map<int, dynamic> asMapList(List l) { |
| 360 return new ListMapView(l); | 389 return new ListMapView(l); |
| 361 } | 390 } |
| 362 } | 391 } |
| 363 | 392 |
| 364 class Collections { | 393 class Collections { |
| 365 static String collectionToString(Collection c) | 394 static String collectionToString(Collection c) |
| 366 => ToString.collectionToString(c); | 395 => ToString.collectionToString(c); |
| 367 } | 396 } |
| 368 | 397 |
| 369 /** | 398 /** |
| 370 * An unmodifiable [List] view of another List. | 399 * An unmodifiable [List] view of another List. |
| 371 * | 400 * |
| 372 * The source of the elements may be a [List] or any [Iterable] with | 401 * The source of the elements may be a [List] or any [Iterable] with |
| 373 * efficient [Iterable.length] and [Iterable.elementAt]. | 402 * efficient [Iterable.length] and [Iterable.elementAt]. |
| 374 */ | 403 */ |
| 375 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { | 404 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { |
| 376 Iterable<E> _source; | 405 Iterable<E> _source; |
| 377 /** Create an unmodifiable list backed by [source]. */ | 406 /** Create an unmodifiable list backed by [source]. */ |
| 378 UnmodifiableListView(Iterable<E> source) : _source = source; | 407 UnmodifiableListView(Iterable<E> source) : _source = source; |
| 379 int get length => _source.length; | 408 int get length => _source.length; |
| 380 E operator[](int index) => _source.elementAt(index); | 409 E operator[](int index) => _source.elementAt(index); |
| 381 } | 410 } |
| OLD | NEW |