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

Side by Side Diff: corelib/src/implementation/queue.dart

Issue 9114021: Added method map to Collection interface and all its implementations (except classes generated fr... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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
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 5
6 /** 6 /**
7 * An entry in a doubly linked list. It contains a pointer to the next 7 * An entry in a doubly linked list. It contains a pointer to the next
8 * entry, the previous entry, and the boxed element. 8 * entry, the previous entry, and the boxed element.
9 */ 9 */
10 class DoubleLinkedQueueEntry<E> { 10 class DoubleLinkedQueueEntry<E> {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 bool some(bool f(E element)) { 198 bool some(bool f(E element)) {
199 DoubleLinkedQueueEntry<E> entry = _sentinel._next; 199 DoubleLinkedQueueEntry<E> entry = _sentinel._next;
200 while (entry !== _sentinel) { 200 while (entry !== _sentinel) {
201 DoubleLinkedQueueEntry<E> nextEntry = entry._next; 201 DoubleLinkedQueueEntry<E> nextEntry = entry._next;
202 if (f(entry._element)) return true; 202 if (f(entry._element)) return true;
203 entry = nextEntry; 203 entry = nextEntry;
204 } 204 }
205 return false; 205 return false;
206 } 206 }
207 207
208 Queue map(f(E element)) {
209 Queue<E> other = new Queue();
ahe 2012/01/05 22:36:54 Remove <E>.
210 DoubleLinkedQueueEntry<E> entry = _sentinel._next;
211 while (entry !== _sentinel) {
212 DoubleLinkedQueueEntry<E> nextEntry = entry._next;
213 other.addLast(f(entry._element));
214 entry = nextEntry;
215 }
216 return other;
217 }
218
219
208 Queue<E> filter(bool f(E element)) { 220 Queue<E> filter(bool f(E element)) {
209 Queue<E> other = new Queue<E>(); 221 Queue<E> other = new Queue<E>();
210 DoubleLinkedQueueEntry<E> entry = _sentinel._next; 222 DoubleLinkedQueueEntry<E> entry = _sentinel._next;
211 while (entry !== _sentinel) { 223 while (entry !== _sentinel) {
212 DoubleLinkedQueueEntry<E> nextEntry = entry._next; 224 DoubleLinkedQueueEntry<E> nextEntry = entry._next;
213 if (f(entry._element)) other.addLast(entry._element); 225 if (f(entry._element)) other.addLast(entry._element);
214 entry = nextEntry; 226 entry = nextEntry;
215 } 227 }
216 return other; 228 return other;
217 } 229 }
(...skipping 16 matching lines...) Expand all
234 } 246 }
235 247
236 E next() { 248 E next() {
237 if (!hasNext()) { 249 if (!hasNext()) {
238 throw const NoMoreElementsException(); 250 throw const NoMoreElementsException();
239 } 251 }
240 _currentEntry = _currentEntry._next; 252 _currentEntry = _currentEntry._next;
241 return _currentEntry.element; 253 return _currentEntry.element;
242 } 254 }
243 } 255 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698