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

Side by Side Diff: sdk/lib/collection_dev/list.dart

Issue 12040018: Make ListIterator throw if the underlying list's length changes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 | « no previous file | tests/corelib/list_iterators_test.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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.collection.dev; 5 part of dart.collection.dev;
6 6
7 /** 7 /**
8 * Class implementing the read-operations on [List]. 8 * Class implementing the read-operations on [List].
9 * 9 *
10 * Implements all read-only operations, except [:operator[]:] and [:length:], 10 * Implements all read-only operations, except [:operator[]:] and [:length:],
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 throw new UnsupportedError( 266 throw new UnsupportedError(
267 "Cannot insert range in an unmodifiable list"); 267 "Cannot insert range in an unmodifiable list");
268 } 268 }
269 } 269 }
270 270
271 /** 271 /**
272 * Iterates over a [List] in growing index order. 272 * Iterates over a [List] in growing index order.
273 */ 273 */
274 class ListIterator<E> implements Iterator<E> { 274 class ListIterator<E> implements Iterator<E> {
275 final List<E> _list; 275 final List<E> _list;
276 final int _initialLength;
276 int _position; 277 int _position;
277 E _current; 278 E _current;
278 279
279 ListIterator(List<E> list) : _list = list, _position = -1; 280 ListIterator(List<E> list)
281 : _list = list, _position = -1, _initialLength = list.length;
280 282
281 bool moveNext() { 283 bool moveNext() {
284 if (_list.length != _initialLength) {
285 throw new ConcurrentModificationError(_list);
286 }
282 int nextPosition = _position + 1; 287 int nextPosition = _position + 1;
283 if (nextPosition < _list.length) { 288 if (nextPosition < _list.length) {
284 _current = _list[nextPosition]; 289 _current = _list[nextPosition];
285 _position = nextPosition; 290 _position = nextPosition;
286 return true; 291 return true;
287 } 292 }
288 _position = _list.length; 293 _position = _list.length;
289 _current = null; 294 _current = null;
290 return false; 295 return false;
291 } 296 }
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 throw new ConcurrentModificationError(list); 523 throw new ConcurrentModificationError(list);
519 } 524 }
520 if (_index <= _start) return false; 525 if (_index <= _start) return false;
521 _index -= 1; 526 _index -= 1;
522 _current = _list[_index]; 527 _current = _list[_index];
523 return true; 528 return true;
524 } 529 }
525 530
526 E get current => _current; 531 E get current => _current;
527 } 532 }
OLDNEW
« no previous file with comments | « no previous file | tests/corelib/list_iterators_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698