4a7dfd2da3
Review URL: https://codereview.chromium.org//11783009 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@16687 260f80e4-7a28-3924-810f-c04153c831b5
58 lines
1.4 KiB
Dart
58 lines
1.4 KiB
Dart
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
part of html;
|
|
|
|
// Iterator for arrays with fixed size.
|
|
class FixedSizeListIterator<T> implements Iterator<T> {
|
|
final List<T> _array;
|
|
final int _length; // Cache array length for faster access.
|
|
int _position;
|
|
T _current;
|
|
|
|
FixedSizeListIterator(List<T> array)
|
|
: _array = array,
|
|
_position = -1,
|
|
_length = array.length;
|
|
|
|
bool moveNext() {
|
|
int nextPosition = _position + 1;
|
|
if (nextPosition < _length) {
|
|
_current = _array[nextPosition];
|
|
_position = nextPosition;
|
|
return true;
|
|
}
|
|
_current = null;
|
|
_position = _length;
|
|
return false;
|
|
}
|
|
|
|
T get current => _current;
|
|
}
|
|
|
|
// Iterator for arrays with variable size.
|
|
class _VariableSizeListIterator<T> implements Iterator<T> {
|
|
final List<T> _array;
|
|
int _position;
|
|
T _current;
|
|
|
|
_VariableSizeListIterator(List<T> array)
|
|
: _array = array,
|
|
_position = -1;
|
|
|
|
bool moveNext() {
|
|
int nextPosition = _position + 1;
|
|
if (nextPosition < _array.length) {
|
|
_current = _array[nextPosition];
|
|
_position = nextPosition;
|
|
return true;
|
|
}
|
|
_current = null;
|
|
_position = _array.length;
|
|
return false;
|
|
}
|
|
|
|
T get current => _current;
|
|
}
|