| OLD | NEW |
| 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 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 newStart = -count; | 482 newStart = -count; |
| 483 } else { | 483 } else { |
| 484 newStart = _end - count; | 484 newStart = _end - count; |
| 485 if (_end >= 0 && newStart < 0) { | 485 if (_end >= 0 && newStart < 0) { |
| 486 return new EmptyList<E>(); | 486 return new EmptyList<E>(); |
| 487 } | 487 } |
| 488 } | 488 } |
| 489 return _createReversedListView(newStart, _end); | 489 return _createReversedListView(newStart, _end); |
| 490 } | 490 } |
| 491 | 491 |
| 492 Iterable<E> get iterator => new ReverseListIterator<E>( | 492 Iterator<E> get iterator => new ReverseListIterator<E>( |
| 493 _list, _absoluteIndex(_start), _absoluteIndex(_end)); | 493 _list, _absoluteIndex(_start), _absoluteIndex(_end)); |
| 494 | 494 |
| 495 List<E> get reversed { | 495 List<E> get reversed { |
| 496 return new ListView(_list, _start, _end); | 496 return new ListView(_list, _start, _end); |
| 497 } | 497 } |
| 498 } | 498 } |
| 499 | 499 |
| 500 /** | 500 /** |
| 501 * An [Iterator] over a slice of a list that access elements in reverse order. | 501 * An [Iterator] over a slice of a list that access elements in reverse order. |
| 502 */ | 502 */ |
| 503 class ReverseListIterator<E> implements Iterator<E> { | 503 class ReverseListIterator<E> implements Iterator<E> { |
| 504 final List<E> _list; | 504 final List<E> _list; |
| 505 final int _start; | 505 final int _start; |
| 506 final int _originalLength; | 506 final int _originalLength; |
| 507 int _index; | 507 int _index; |
| 508 E _current; | 508 E _current; |
| 509 | 509 |
| 510 ReverseListIterator(List<E> list, int start, int end) | 510 ReverseListIterator(List<E> list, int start, int end) |
| 511 : _list = list, | 511 : _list = list, |
| 512 _start = start, | 512 _start = start, |
| 513 _index = end, | 513 _index = end, |
| 514 _originalLength = list.length; | 514 _originalLength = list.length; |
| 515 | 515 |
| 516 bool moveNext() { | 516 bool moveNext() { |
| 517 if (list.length != _originalLength) { | 517 if (_list.length != _originalLength) { |
| 518 throw new ConcurrentModificationError(list); | 518 throw new ConcurrentModificationError(list); |
| 519 } | 519 } |
| 520 if (_index <= _start) return false; | 520 if (_index <= _start) return false; |
| 521 _index -= 1; | 521 _index -= 1; |
| 522 _current = _list[_index]; | 522 _current = _list[_index]; |
| 523 return true; | 523 return true; |
| 524 } | 524 } |
| 525 | 525 |
| 526 E get current => _current; | 526 E get current => _current; |
| 527 } | 527 } |
| OLD | NEW |