Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Unified Diff: sdk/lib/core/collection.dart

Issue 11931034: Add methods to Collection. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/collection/collections.dart ('k') | sdk/lib/core/list.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/collection.dart
diff --git a/sdk/lib/core/collection.dart b/sdk/lib/core/collection.dart
index 23b08e6b4b008e89eb954a2ff696923b0fdb1f34..48ab1de2e88cd30f0c8d0e212d2077d6c472a622 100644
--- a/sdk/lib/core/collection.dart
+++ b/sdk/lib/core/collection.dart
@@ -5,11 +5,83 @@
part of dart.core;
/**
- * The common interface of all collections.
+ * A collection of individual elements.
*
- * The [Collection] class contains a skeleton implementation of
- * an iterator based collection.
+ * A [Collection] contains some elements in a structure optimized
+ * for certain operations. Different collections are optimized for different
+ * uses.
+ *
+ * A collection can be updated by adding or removing elements.
+ *
+ * Collections are [Iterable]. The order of iteration is defined by
+ * each type of collection.
*/
abstract class Collection<E> extends Iterable<E> {
const Collection();
+
+ /**
+ * Adds an element to this collection.
+ */
+ void add(E element);
+
+ /**
+ * Adds all of [elements] to this collection.
+ *
+ * Equivalent to adding each element in [elements] using [add],
+ * but some collections may be able to optimize it.
+ */
+ void addAll(Iterable<E> elements) {
+ for (E element in elements) {
+ add(element);
+ }
+ }
+
+ /**
+ * Removes an instance of [element] from this collection.
+ *
+ * This removes only one instance of the element for collections that can
+ * contain the same element more than once (e.g., [List]). Which instance
+ * is removed is decided by the collection.
+ *
+ * Has no effect if the elements is not in this collection.
+ */
+ void remove(Object element);
+
+ /**
+ * Removes all of [elements] from this collection.
+ *
+ * Equivalent to calling [remove] once for each element in
+ * [elements], but may be faster for some collections.
+ */
+ void removeAll(Iterable elements) {
+ IterableMixinWorkaround.removeAll(this, elements);
+ }
+
+ /**
+ * Removes all elements of this collection that are not
+ * in [elements].
+ *
+ * For [Set]s, this is the intersection of the two original sets.
+ */
+ void retainAll(Iterable elements) {
+ IterableMixinWorkaround.retainAll(this, elements);
+ }
+
+ /**
+ * Removes all elements of this collection that satisfy [test].
+ *
+ * An elements [:e:] satisfies [test] if [:test(e):] is true.
+ */
+ void removeMatching(bool test(E element)) {
+ IterableMixinWorkaround.removeMatching(this, test);
+ }
+
+ /**
+ * Removes all elements of this collection that fail to satisfy [test].
+ *
+ * An elements [:e:] satisfies [test] if [:test(e):] is true.
+ */
+ void retainMatching(bool test(E element)) {
+ IterableMixinWorkaround.retainMatching(this, test);
+ }
}
« no previous file with comments | « sdk/lib/collection/collections.dart ('k') | sdk/lib/core/list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698