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 T removeAt(int index) { | 11 T removeAt(int index) { |
12 if (index is! int) throw new IllegalArgumentException(index); | 12 if (index is! int) throw new ArgumentError(index); |
13 T result = this[index]; | 13 T result = this[index]; |
14 int newLength = this.length - 1; | 14 int newLength = this.length - 1; |
15 Arrays.copy(this, | 15 Arrays.copy(this, |
16 index + 1, | 16 index + 1, |
17 this, | 17 this, |
18 index, | 18 index, |
19 newLength - index); | 19 newLength - index); |
20 this.length = newLength; | 20 this.length = newLength; |
21 return result; | 21 return result; |
22 } | 22 } |
23 | 23 |
24 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]) { |
25 if (length < 0) { | 25 if (length < 0) { |
26 throw new IllegalArgumentException("negative length $length"); | 26 throw new ArgumentError("negative length $length"); |
27 } | 27 } |
28 Arrays.copy(from, startFrom, this, start, length); | 28 Arrays.copy(from, startFrom, this, start, length); |
29 } | 29 } |
30 | 30 |
31 void removeRange(int start, int length) { | 31 void removeRange(int start, int length) { |
32 if (length == 0) { | 32 if (length == 0) { |
33 return; | 33 return; |
34 } | 34 } |
35 Arrays.rangeCheck(this, start, length); | 35 Arrays.rangeCheck(this, start, length); |
36 Arrays.copy(this, | 36 Arrays.copy(this, |
37 start + length, | 37 start + length, |
38 this, | 38 this, |
39 start, | 39 start, |
40 this.length - length - start); | 40 this.length - length - start); |
41 this.length = this.length - length; | 41 this.length = this.length - length; |
42 } | 42 } |
43 | 43 |
44 void insertRange(int start, int length, [T initialValue = null]) { | 44 void insertRange(int start, int length, [T initialValue = null]) { |
45 if (length == 0) { | 45 if (length == 0) { |
46 return; | 46 return; |
47 } | 47 } |
48 if ((length < 0) || (length is! int)) { | 48 if ((length < 0) || (length is! int)) { |
49 throw new IllegalArgumentException("invalid length specified $length"); | 49 throw new ArgumentError("invalid length specified $length"); |
50 } | 50 } |
51 if (start < 0 || start > this.length) { | 51 if (start < 0 || start > this.length) { |
52 throw new IndexOutOfRangeException(start); | 52 throw new IndexOutOfRangeException(start); |
53 } | 53 } |
54 var old_length = this.length; | 54 var old_length = this.length; |
55 this.length = old_length + length; // Will expand if needed. | 55 this.length = old_length + length; // Will expand if needed. |
56 Arrays.copy(this, | 56 Arrays.copy(this, |
57 start, | 57 start, |
58 this, | 58 this, |
59 start + length, | 59 start + length, |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 T next() { | 234 T next() { |
235 if (!hasNext()) { | 235 if (!hasNext()) { |
236 throw const NoMoreElementsException(); | 236 throw const NoMoreElementsException(); |
237 } | 237 } |
238 return _array[_pos++]; | 238 return _array[_pos++]; |
239 } | 239 } |
240 | 240 |
241 final GrowableObjectArray<T> _array; | 241 final GrowableObjectArray<T> _array; |
242 int _pos; | 242 int _pos; |
243 } | 243 } |
OLD | NEW |