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

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

Issue 11931034: Add methods to Collection. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Also on DoubleLinkedQueue. 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
Index: sdk/lib/core/queue.dart
diff --git a/sdk/lib/core/queue.dart b/sdk/lib/core/queue.dart
index 9a000c34143274a16c5d08f0f5829556efc2a59b..b90af624929499950ff5264d270a495a1ab9fedf 100644
--- a/sdk/lib/core/queue.dart
+++ b/sdk/lib/core/queue.dart
@@ -201,6 +201,59 @@ class DoubleLinkedQueue<E> extends Iterable<E> implements Queue<E> {
return _sentinel._next.remove();
}
+ void remove(Object o) {
+ DoubleLinkedQueueEntry<E> entry = firstEntry();
+ while (!identical(entry, _sentinel)) {
+ if (entry.element == o) {
+ entry.remove();
+ return;
+ }
+ entry = entry._next;
+ }
+ }
+
+ void removeAll(Iterable elements) {
floitsch 2013/01/17 13:36:58 If Collection provides default implementations, th
Lasse Reichstein Nielsen 2013/01/18 11:41:48 This implementation is not the default implementat
+ Set set;
+ if (elements is Set) {
+ set = elements;
+ } else {
+ set = elements.toSet();
+ }
+ removeMatching(set.contains);
+ }
+
+ void retainAll(Iterable elements) {
floitsch 2013/01/17 13:36:58 ditto.
Lasse Reichstein Nielsen 2013/01/18 11:41:48 This one is the same as the default, so it can be
+ Set set;
+ if (elements is Set) {
+ set = elements;
+ } else {
+ set = elements.toSet();
+ }
+ retainMatching(set.contains);
+ }
+
+ void removeMatching(bool test(E element)) {
+ DoubleLinkedQueueEntry<E> entry = firstEntry();
+ while (!identical(entry, _sentinel)) {
+ DoubleLinkedQueueEntry<E> next = entry._next;
+ if (test(entry.element)) {
+ entry.remove();
+ }
+ entry = next;
+ }
+ }
+
+ void retainMatching(bool test(E element)) {
+ DoubleLinkedQueueEntry<E> entry = firstEntry();
+ while (!identical(entry, _sentinel)) {
+ DoubleLinkedQueueEntry<E> next = entry._next;
+ if (!test(entry.element)) {
+ entry.remove();
+ }
+ entry = next;
+ }
+ }
+
E get first {
return _sentinel._next.element;
}

Powered by Google App Engine
This is Rietveld 408576698