OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 * An indexed sequence of elements of the same type. | 6 * An indexed sequence of elements of the same type. |
7 * | 7 * |
8 * This is a primitive interface that any finite integer-indexable | 8 * This is a primitive interface that any finite integer-indexable |
9 * sequence can implement. | 9 * sequence can implement. |
10 * It is intended for data structures where access by index is | 10 * It is intended for data structures where access by index is |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } | 110 } |
111 | 111 |
112 int lastIndexOf(E value, [int start]) { | 112 int lastIndexOf(E value, [int start]) { |
113 if (start == null) start = sequence.length - 1; | 113 if (start == null) start = sequence.length - 1; |
114 for (int i = start; i >= 0; i--) { | 114 for (int i = start; i >= 0; i--) { |
115 if (sequence[i] == value) return i; | 115 if (sequence[i] == value) return i; |
116 } | 116 } |
117 return -1; | 117 return -1; |
118 } | 118 } |
119 | 119 |
120 E last() => sequence[sequence.length - 1]; | 120 E get last => sequence[sequence.length - 1]; |
121 | 121 |
122 List<E> getRange(int start, int length) { | 122 List<E> getRange(int start, int length) { |
123 List<E> result = <E>[]; | 123 List<E> result = <E>[]; |
124 for (int i = 0; i < length; i++) { | 124 for (int i = 0; i < length; i++) { |
125 result.add(sequence[start + i]); | 125 result.add(sequence[start + i]); |
126 } | 126 } |
127 return result; | 127 return result; |
128 } | 128 } |
129 | 129 |
130 void operator []=(int index, E value) { | 130 void operator []=(int index, E value) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 Sequence<E> _sequence; | 195 Sequence<E> _sequence; |
196 int _position; | 196 int _position; |
197 SequenceIterator(this._sequence) : _position = 0; | 197 SequenceIterator(this._sequence) : _position = 0; |
198 bool get hasNext => _position < _sequence.length; | 198 bool get hasNext => _position < _sequence.length; |
199 E next() { | 199 E next() { |
200 if (hasNext) return _sequence[_position++]; | 200 if (hasNext) return _sequence[_position++]; |
201 throw new NoMoreElementsException(); | 201 throw new NoMoreElementsException(); |
202 } | 202 } |
203 } | 203 } |
204 | 204 |
OLD | NEW |