| 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 if (length < 0) throw new ArgumentError(length); |
| 373 if (start < 0) throw new RangeError.value(start); |
| 374 if (start + length > list.length) { |
| 375 throw new RangeError.value(start + length); |
| 376 } |
| 377 |
| 378 Arrays.copy(from, startFrom, list, start, length); |
| 357 } | 379 } |
| 358 | 380 |
| 359 static Map<int, dynamic> asMapList(List l) { | 381 static Map<int, dynamic> asMapList(List l) { |
| 360 return new ListMapView(l); | 382 return new ListMapView(l); |
| 361 } | 383 } |
| 362 } | 384 } |
| 363 | 385 |
| 364 class Collections { | 386 class Collections { |
| 365 static String collectionToString(Collection c) | 387 static String collectionToString(Collection c) |
| 366 => ToString.collectionToString(c); | 388 => ToString.collectionToString(c); |
| 367 } | 389 } |
| 368 | 390 |
| 369 /** | 391 /** |
| 370 * An unmodifiable [List] view of another List. | 392 * An unmodifiable [List] view of another List. |
| 371 * | 393 * |
| 372 * The source of the elements may be a [List] or any [Iterable] with | 394 * The source of the elements may be a [List] or any [Iterable] with |
| 373 * efficient [Iterable.length] and [Iterable.elementAt]. | 395 * efficient [Iterable.length] and [Iterable.elementAt]. |
| 374 */ | 396 */ |
| 375 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { | 397 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { |
| 376 Iterable<E> _source; | 398 Iterable<E> _source; |
| 377 /** Create an unmodifiable list backed by [source]. */ | 399 /** Create an unmodifiable list backed by [source]. */ |
| 378 UnmodifiableListView(Iterable<E> source) : _source = source; | 400 UnmodifiableListView(Iterable<E> source) : _source = source; |
| 379 int get length => _source.length; | 401 int get length => _source.length; |
| 380 E operator[](int index) => _source.elementAt(index); | 402 E operator[](int index) => _source.elementAt(index); |
| 381 } | 403 } |
| OLD | NEW |