| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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) { |
| 131 throw new UnsupportedOperationException( | 131 throw new StateError( |
| 132 "Cannot modify an unmodifiable list"); | 132 "Cannot modify an unmodifiable list"); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void set length(int newLength) { | 135 void set length(int newLength) { |
| 136 throw new UnsupportedOperationException( | 136 throw new StateError( |
| 137 "Cannot change the length of an unmodifiable list"); | 137 "Cannot change the length of an unmodifiable list"); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void add(E value) { | 140 void add(E value) { |
| 141 throw new UnsupportedOperationException( | 141 throw new StateError( |
| 142 "Cannot add to an unmodifiable list"); | 142 "Cannot add to an unmodifiable list"); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void addLast(E value) { | 145 void addLast(E value) { |
| 146 throw new UnsupportedOperationException( | 146 throw new StateError( |
| 147 "Cannot add to an unmodifiable list"); | 147 "Cannot add to an unmodifiable list"); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void addAll(Collection<E> collection) { | 150 void addAll(Collection<E> collection) { |
| 151 throw new UnsupportedOperationException( | 151 throw new StateError( |
| 152 "Cannot add to an unmodifiable list"); | 152 "Cannot add to an unmodifiable list"); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void sort([Comparator<E> compare]) { | 155 void sort([Comparator<E> compare]) { |
| 156 throw new UnsupportedOperationException( | 156 throw new StateError( |
| 157 "Cannot modify an unmodifiable list"); | 157 "Cannot modify an unmodifiable list"); |
| 158 } | 158 } |
| 159 | 159 |
| 160 void clear() { | 160 void clear() { |
| 161 throw new UnsupportedOperationException( | 161 throw new StateError( |
| 162 "Cannot clear an unmodifiable list"); | 162 "Cannot clear an unmodifiable list"); |
| 163 } | 163 } |
| 164 | 164 |
| 165 E removeAt(int index) { | 165 E removeAt(int index) { |
| 166 throw new UnsupportedOperationException( | 166 throw new StateError( |
| 167 "Cannot remove in an unmodifiable list"); | 167 "Cannot remove in an unmodifiable list"); |
| 168 } | 168 } |
| 169 | 169 |
| 170 E removeLast() { | 170 E removeLast() { |
| 171 throw new UnsupportedOperationException( | 171 throw new StateError( |
| 172 "Cannot remove in an unmodifiable list"); | 172 "Cannot remove in an unmodifiable list"); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void setRange(int start, int length, List<E> from, [int startFrom]) { | 175 void setRange(int start, int length, List<E> from, [int startFrom]) { |
| 176 throw new UnsupportedOperationException( | 176 throw new StateError( |
| 177 "Cannot modify an unmodifiable list"); | 177 "Cannot modify an unmodifiable list"); |
| 178 } | 178 } |
| 179 | 179 |
| 180 void removeRange(int start, int length) { | 180 void removeRange(int start, int length) { |
| 181 throw new UnsupportedOperationException( | 181 throw new StateError( |
| 182 "Cannot remove in an unmodifiable list"); | 182 "Cannot remove in an unmodifiable list"); |
| 183 } | 183 } |
| 184 | 184 |
| 185 void insertRange(int start, int length, [E initialValue]) { | 185 void insertRange(int start, int length, [E initialValue]) { |
| 186 throw new UnsupportedOperationException( | 186 throw new StateError( |
| 187 "Cannot insert range in an unmodifiable list"); | 187 "Cannot insert range in an unmodifiable list"); |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 | 190 |
| 191 /** | 191 /** |
| 192 * Iterates over a [Sequence] in growing index order. | 192 * Iterates over a [Sequence] in growing index order. |
| 193 */ | 193 */ |
| 194 class SequenceIterator<E> implements Iterator<E> { | 194 class SequenceIterator<E> implements Iterator<E> { |
| 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 hasNext() => _position < _sequence.length; | 198 bool 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 |