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 class GrowableObjectArray<T> implements List<T> { | 5 class GrowableObjectArray<T> implements List<T> { |
6 factory GrowableObjectArray._uninstantiable() { | 6 factory GrowableObjectArray._uninstantiable() { |
7 throw const UnsupportedOperationException( | 7 throw const UnsupportedOperationException( |
8 "GrowableObjectArray can only be allocated by the VM"); | 8 "GrowableObjectArray can only be allocated by the VM"); |
9 } | 9 } |
10 | 10 |
11 E removeAt(int index) { | 11 T removeAt(int index) { |
12 E result = this[index]; | 12 if (index is! int) throw new IllegalArgumentException(index); |
| 13 T result = this[index]; |
| 14 int newLength = this.length - 1; |
13 Arrays.copy(this, | 15 Arrays.copy(this, |
14 index + 1, | 16 index + 1, |
15 this, | 17 this, |
16 index, | 18 index, |
17 this.length - index - 1); | 19 newLength - index); |
18 this.length = this.length - 1; | 20 this.length = newLength; |
19 return result; | 21 return result; |
20 } | 22 } |
21 | 23 |
22 void setRange(int start, int length, List<T> from, [int startFrom = 0]) { | 24 void setRange(int start, int length, List<T> from, [int startFrom = 0]) { |
23 if (length < 0) { | 25 if (length < 0) { |
24 throw new IllegalArgumentException("negative length $length"); | 26 throw new IllegalArgumentException("negative length $length"); |
25 } | 27 } |
26 Arrays.copy(from, startFrom, this, start, length); | 28 Arrays.copy(from, startFrom, this, start, length); |
27 } | 29 } |
28 | 30 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 T next() { | 240 T next() { |
239 if (!hasNext()) { | 241 if (!hasNext()) { |
240 throw const NoMoreElementsException(); | 242 throw const NoMoreElementsException(); |
241 } | 243 } |
242 return _array[_pos++]; | 244 return _array[_pos++]; |
243 } | 245 } |
244 | 246 |
245 final GrowableObjectArray<T> _array; | 247 final GrowableObjectArray<T> _array; |
246 int _pos; | 248 int _pos; |
247 } | 249 } |
OLD | NEW |