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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/core/list.dart ('k') | sdk/lib/core/set.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 * A [Queue] is a collection that can be manipulated at both ends. One 8 * A [Queue] is a collection that can be manipulated at both ends. One
9 * can iterate over the elements of a queue through [forEach] or with 9 * can iterate over the elements of a queue through [forEach] or with
10 * an [Iterator]. 10 * an [Iterator].
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 194 }
195 195
196 E removeLast() { 196 E removeLast() {
197 return _sentinel._previous.remove(); 197 return _sentinel._previous.remove();
198 } 198 }
199 199
200 E removeFirst() { 200 E removeFirst() {
201 return _sentinel._next.remove(); 201 return _sentinel._next.remove();
202 } 202 }
203 203
204 void remove(Object o) {
205 DoubleLinkedQueueEntry<E> entry = firstEntry();
206 while (!identical(entry, _sentinel)) {
207 if (entry.element == o) {
208 entry.remove();
209 return;
210 }
211 entry = entry._next;
212 }
213 }
214
215 void removeAll(Iterable elements) {
216 // Use this method when remove is slow and removeMatching more efficient.
217 IterableMixinWorkaround.removeAllList(this, elements);
218 }
219
220 void removeMatching(bool test(E element)) {
221 DoubleLinkedQueueEntry<E> entry = firstEntry();
222 while (!identical(entry, _sentinel)) {
223 DoubleLinkedQueueEntry<E> next = entry._next;
224 if (test(entry.element)) {
225 entry.remove();
226 }
227 entry = next;
228 }
229 }
230
231 void retainMatching(bool test(E element)) {
232 DoubleLinkedQueueEntry<E> entry = firstEntry();
233 while (!identical(entry, _sentinel)) {
234 DoubleLinkedQueueEntry<E> next = entry._next;
235 if (!test(entry.element)) {
236 entry.remove();
237 }
238 entry = next;
239 }
240 }
241
204 E get first { 242 E get first {
205 return _sentinel._next.element; 243 return _sentinel._next.element;
206 } 244 }
207 245
208 E get last { 246 E get last {
209 return _sentinel._previous.element; 247 return _sentinel._previous.element;
210 } 248 }
211 249
212 E get single { 250 E get single {
213 // Note that this also covers the case where the queue is empty. 251 // Note that this also covers the case where the queue is empty.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 _current = null; 310 _current = null;
273 _sentinel = null; 311 _sentinel = null;
274 return false; 312 return false;
275 } 313 }
276 _current = _currentEntry.element; 314 _current = _currentEntry.element;
277 return true; 315 return true;
278 } 316 }
279 317
280 E get current => _current; 318 E get current => _current;
281 } 319 }
OLDNEW
« no previous file with comments | « sdk/lib/core/list.dart ('k') | sdk/lib/core/set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698