| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 for (var element in collection) { | 108 for (var element in collection) { |
| 109 if (test(element)) elementsToRemove.add(element); | 109 if (test(element)) elementsToRemove.add(element); |
| 110 } | 110 } |
| 111 collection.removeAll(elementsToRemove); | 111 collection.removeAll(elementsToRemove); |
| 112 } | 112 } |
| 113 | 113 |
| 114 /** | 114 /** |
| 115 * Removes elements matching [test] from [list]. | 115 * Removes elements matching [test] from [list]. |
| 116 * | 116 * |
| 117 * This is performed in two steps, to avoid exposing an inconsistent state | 117 * This is performed in two steps, to avoid exposing an inconsistent state |
| 118 * to the [test] function. First the elements to ratain are found, and then | 118 * to the [test] function. First the elements to retain are found, and then |
| 119 * the original list is updated to contain those elements. | 119 * the original list is updated to contain those elements. |
| 120 */ | 120 */ |
| 121 static void removeMatchingList(List list, bool test(var element)) { | 121 static void removeMatchingList(List list, bool test(var element)) { |
| 122 List retained = []; | 122 List retained = []; |
| 123 int length = list.length; | 123 int length = list.length; |
| 124 for (int i = 0; i < length; i++) { | 124 for (int i = 0; i < length; i++) { |
| 125 var element = list[i]; | 125 var element = list[i]; |
| 126 if (!test(element)) { | 126 if (!test(element)) { |
| 127 retained.add(element); | 127 retained.add(element); |
| 128 } | 128 } |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 * The source of the elements may be a [List] or any [Iterable] with | 368 * The source of the elements may be a [List] or any [Iterable] with |
| 369 * efficient [Iterable.length] and [Iterable.elementAt]. | 369 * efficient [Iterable.length] and [Iterable.elementAt]. |
| 370 */ | 370 */ |
| 371 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { | 371 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { |
| 372 Iterable<E> _source; | 372 Iterable<E> _source; |
| 373 /** Create an unmodifiable list backed by [source]. */ | 373 /** Create an unmodifiable list backed by [source]. */ |
| 374 UnmodifiableListView(Iterable<E> source) : _source = source; | 374 UnmodifiableListView(Iterable<E> source) : _source = source; |
| 375 int get length => _source.length; | 375 int get length => _source.length; |
| 376 E operator[](int index) => _source.elementAt(index); | 376 E operator[](int index) => _source.elementAt(index); |
| 377 } | 377 } |
| OLD | NEW |