| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 class GrowableObjectArray<T> implements List<T> { | 5 class GrowableObjectArray<T> implements List<T> { |
| 6 ObjectArray<T> backingArray; | 6 ObjectArray<T> backingArray; |
| 7 | 7 |
| 8 factory GrowableObjectArray._uninstantiable() { | 8 factory GrowableObjectArray._uninstantiable() { |
| 9 throw const UnsupportedOperationException( | 9 throw const UnsupportedOperationException( |
| 10 "GrowableObjectArray can only be allocated by the VM"); | 10 "GrowableObjectArray can only be allocated by the VM"); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 } | 215 } |
| 216 | 216 |
| 217 void clear() { | 217 void clear() { |
| 218 this.length = 0; | 218 this.length = 0; |
| 219 } | 219 } |
| 220 | 220 |
| 221 void sort(int compare(T a, T b)) { | 221 void sort(int compare(T a, T b)) { |
| 222 DualPivotQuicksort.sort(this, compare); | 222 DualPivotQuicksort.sort(this, compare); |
| 223 } | 223 } |
| 224 | 224 |
| 225 String toString() { |
| 226 return Arrays.asString(this); |
| 227 } |
| 228 |
| 225 Iterator<T> iterator() { | 229 Iterator<T> iterator() { |
| 226 return new VariableSizeArrayIterator<T>(this); | 230 return new VariableSizeArrayIterator<T>(this); |
| 227 } | 231 } |
| 228 } | 232 } |
| 229 | 233 |
| 230 | 234 |
| 231 // Iterator for arrays with variable size. | 235 // Iterator for arrays with variable size. |
| 232 class VariableSizeArrayIterator<T> implements Iterator<T> { | 236 class VariableSizeArrayIterator<T> implements Iterator<T> { |
| 233 VariableSizeArrayIterator(GrowableObjectArray<T> array) | 237 VariableSizeArrayIterator(GrowableObjectArray<T> array) |
| 234 : _array = array, _pos = 0 { | 238 : _array = array, _pos = 0 { |
| 235 } | 239 } |
| 236 | 240 |
| 237 bool hasNext() { | 241 bool hasNext() { |
| 238 return _array._length > _pos; | 242 return _array._length > _pos; |
| 239 } | 243 } |
| 240 | 244 |
| 241 T next() { | 245 T next() { |
| 242 if (!hasNext()) { | 246 if (!hasNext()) { |
| 243 throw const NoMoreElementsException(); | 247 throw const NoMoreElementsException(); |
| 244 } | 248 } |
| 245 return _array[_pos++]; | 249 return _array[_pos++]; |
| 246 } | 250 } |
| 247 | 251 |
| 248 final GrowableObjectArray<T> _array; | 252 final GrowableObjectArray<T> _array; |
| 249 int _pos; | 253 int _pos; |
| 250 } | 254 } |
| 251 | 255 |
| OLD | NEW |