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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 311 |
312 static Iterable where(Iterable iterable, bool f(var element)) { | 312 static Iterable where(Iterable iterable, bool f(var element)) { |
313 return new WhereIterable(iterable, f); | 313 return new WhereIterable(iterable, f); |
314 } | 314 } |
315 | 315 |
316 static Iterable map(Iterable iterable, f(var element)) { | 316 static Iterable map(Iterable iterable, f(var element)) { |
317 return new MappedIterable(iterable, f); | 317 return new MappedIterable(iterable, f); |
318 } | 318 } |
319 | 319 |
320 static Iterable mapList(List list, f(var element)) { | 320 static Iterable mapList(List list, f(var element)) { |
321 return new MappedListIterable(list, f, 0, null); | 321 return new MappedListIterable(list, f); |
322 } | |
323 | |
324 static List mappedByList(List list, f(var element)) { | |
325 // This is currently a List as well as an Iterable. | |
326 return new MappedList(list, f); | |
327 } | 322 } |
328 | 323 |
329 static Iterable expand(Iterable iterable, Iterable f(var element)) { | 324 static Iterable expand(Iterable iterable, Iterable f(var element)) { |
330 return new ExpandIterable(iterable, f); | 325 return new ExpandIterable(iterable, f); |
331 } | 326 } |
332 | 327 |
333 static Iterable takeList(List list, int n) { | 328 static Iterable takeList(List list, int n) { |
334 // The generic type is currently lost. It will be fixed with mixins. | 329 // The generic type is currently lost. It will be fixed with mixins. |
335 // This is currently a List as well as an Iterable. | 330 // This is currently a List as well as an Iterable. |
336 return new ListView(list, 0, n); | 331 return new SubListIterable(list, 0, n); |
337 } | 332 } |
338 | 333 |
339 static Iterable takeWhile(Iterable iterable, bool test(var value)) { | 334 static Iterable takeWhile(Iterable iterable, bool test(var value)) { |
340 // The generic type is currently lost. It will be fixed with mixins. | 335 // The generic type is currently lost. It will be fixed with mixins. |
341 return new TakeWhileIterable(iterable, test); | 336 return new TakeWhileIterable(iterable, test); |
342 } | 337 } |
343 | 338 |
344 static Iterable skipList(List list, int n) { | 339 static Iterable skipList(List list, int n) { |
345 // 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. |
346 // This is currently a List as well as an Iterable. | 341 // This is currently a List as well as an Iterable. |
347 return new ListView(list, n, null); | 342 return new SubListIterable(list, n, null); |
348 } | 343 } |
349 | 344 |
350 static Iterable skipWhile(Iterable iterable, bool test(var value)) { | 345 static Iterable skipWhile(Iterable iterable, bool test(var value)) { |
351 // 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. |
352 return new SkipWhileIterable(iterable, test); | 347 return new SkipWhileIterable(iterable, test); |
353 } | 348 } |
354 | 349 |
355 static List reversedList(List l) { | 350 static Iterable reversedList(List l) { |
356 return new ReversedListView(l, 0, null); | 351 return new ReversedListIterable(l); |
357 } | 352 } |
358 | 353 |
359 static void sortList(List l, int compare(a, b)) { | 354 static void sortList(List l, int compare(a, b)) { |
360 if (compare == null) compare = Comparable.compare; | 355 if (compare == null) compare = Comparable.compare; |
361 Sort.sort(l, compare); | 356 Sort.sort(l, compare); |
362 } | 357 } |
363 } | 358 } |
364 | 359 |
365 /** | 360 /** |
366 * The [Collections] class implements static methods useful when | 361 * The [Collections] class implements static methods useful when |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 static String joinList(List list, [String separator]) | 462 static String joinList(List list, [String separator]) |
468 => IterableMixinWorkaround.joinList(list, separator); | 463 => IterableMixinWorkaround.joinList(list, separator); |
469 | 464 |
470 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ | 465 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ |
471 @deprecated | 466 @deprecated |
472 static Iterable where(Iterable iterable, bool f(var element)) | 467 static Iterable where(Iterable iterable, bool f(var element)) |
473 => IterableMixinWorkaround.where(iterable, f); | 468 => IterableMixinWorkaround.where(iterable, f); |
474 | 469 |
475 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ | 470 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ |
476 @deprecated | 471 @deprecated |
477 static List mappedByList(List list, f(var element)) | |
478 => IterableMixinWorkaround.mappedByList(list, f); | |
479 | |
480 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ | |
481 @deprecated | |
482 static Iterable takeList(List list, int n) | 472 static Iterable takeList(List list, int n) |
483 => IterableMixinWorkaround.takeList(list, n); | 473 => IterableMixinWorkaround.takeList(list, n); |
484 | 474 |
485 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ | 475 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ |
486 @deprecated | 476 @deprecated |
487 static Iterable takeWhile(Iterable iterable, bool test(var value)) | 477 static Iterable takeWhile(Iterable iterable, bool test(var value)) |
488 => IterableMixinWorkaround.takeWhile(iterable, test); | 478 => IterableMixinWorkaround.takeWhile(iterable, test); |
489 | 479 |
490 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ | 480 /** Deprecated. Use the same method in [IterableMixinWorkaround] instead.*/ |
491 @deprecated | 481 @deprecated |
(...skipping 15 matching lines...) Expand all Loading... |
507 * The source of the elements may be a [List] or any [Iterable] with | 497 * The source of the elements may be a [List] or any [Iterable] with |
508 * efficient [Iterable.length] and [Iterable.elementAt]. | 498 * efficient [Iterable.length] and [Iterable.elementAt]. |
509 */ | 499 */ |
510 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { | 500 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { |
511 Iterable<E> _source; | 501 Iterable<E> _source; |
512 /** Create an unmodifiable list backed by [source]. */ | 502 /** Create an unmodifiable list backed by [source]. */ |
513 UnmodifiableListView(Iterable<E> source) : _source = source; | 503 UnmodifiableListView(Iterable<E> source) : _source = source; |
514 int get length => _source.length; | 504 int get length => _source.length; |
515 E operator[](int index) => _source.elementAt(index); | 505 E operator[](int index) => _source.elementAt(index); |
516 } | 506 } |
OLD | NEW |