OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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.core; | 5 part of dart.core; |
6 | 6 |
7 /** | 7 /** |
8 * The common interface of all collections. | 8 * A collection of individual elements. |
9 * | 9 * |
10 * The [Collection] class contains a skeleton implementation of | 10 * A [Collection] contains some elements in a structure optimized |
11 * an iterator based collection. | 11 * for certain operations. Different collections are optimized for different |
| 12 * uses. |
| 13 * |
| 14 * A collection can be updated by adding or removing elements. |
| 15 * |
| 16 * Collections are [Iterable]. The order of iteration is defined by |
| 17 * each type of collection. |
12 */ | 18 */ |
13 abstract class Collection<E> extends Iterable<E> { | 19 abstract class Collection<E> extends Iterable<E> { |
14 const Collection(); | 20 const Collection(); |
| 21 |
| 22 /** |
| 23 * Adds an element to this collection. |
| 24 */ |
| 25 void add(E element); |
| 26 |
| 27 /** |
| 28 * Adds all of [elements] to this collection. |
| 29 * |
| 30 * Equivalent to adding each element in [elements] using [add], |
| 31 * but some collections may be able to optimize it. |
| 32 */ |
| 33 void addAll(Iterable<E> elements) { |
| 34 for (E element in elements) { |
| 35 add(element); |
| 36 } |
| 37 } |
| 38 |
| 39 /** |
| 40 * Removes an instance of [element] from this collection. |
| 41 * |
| 42 * This removes only one instance of the element for collections that can |
| 43 * contain the same element more than once (e.g., [List]). Which instance |
| 44 * is removed is decided by the collection. |
| 45 * |
| 46 * Has no effect if the elements is not in this collection. |
| 47 */ |
| 48 void remove(Object element); |
| 49 |
| 50 /** |
| 51 * Removes all of [elements] from this collection. |
| 52 * |
| 53 * Equivalent to calling [remove] once for each element in |
| 54 * [elements], but may be faster for some collections. |
| 55 */ |
| 56 void removeAll(Iterable elements) { |
| 57 IterableMixinWorkaround.removeAll(this, elements); |
| 58 } |
| 59 |
| 60 /** |
| 61 * Removes all elements of this collection that are not |
| 62 * in [elements]. |
| 63 * |
| 64 * For [Set]s, this is the intersection of the two original sets. |
| 65 */ |
| 66 void retainAll(Iterable elements) { |
| 67 IterableMixinWorkaround.retainAll(this, elements); |
| 68 } |
| 69 |
| 70 /** |
| 71 * Removes all elements of this collection that satisfy [test]. |
| 72 * |
| 73 * An elements [:e:] satisfies [test] if [:test(e):] is true. |
| 74 */ |
| 75 void removeMatching(bool test(E element)) { |
| 76 IterableMixinWorkaround.removeMatching(this, test); |
| 77 } |
| 78 |
| 79 /** |
| 80 * Removes all elements of this collection that fail to satisfy [test]. |
| 81 * |
| 82 * An elements [:e:] satisfies [test] if [:test(e):] is true. |
| 83 */ |
| 84 void retainMatching(bool test(E element)) { |
| 85 IterableMixinWorkaround.retainMatching(this, test); |
| 86 } |
15 } | 87 } |
OLD | NEW |