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 ArrayFactory<T> { | 5 class ArrayFactory<T> { |
6 factory Array.from(Iterable<T> other) { | 6 factory Array.from(Iterable<T> other) { |
7 GrowableObjectArray<T> array = new GrowableObjectArray<T>(); | 7 GrowableObjectArray<T> array = new GrowableObjectArray<T>(); |
8 for (final e in other) { | 8 for (final e in other) { |
9 array.add(e); | 9 array.add(e); |
10 } | 10 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 void _copyFromObjectArray(ObjectArray src, | 89 void _copyFromObjectArray(ObjectArray src, |
90 int srcStart, | 90 int srcStart, |
91 int dstStart, | 91 int dstStart, |
92 int count) | 92 int count) |
93 native "ObjectArray_copyFromObjectArray"; | 93 native "ObjectArray_copyFromObjectArray"; |
94 | 94 |
95 void setRange(int start, int length, List<T> from, [int startFrom = 0]) { | 95 void setRange(int start, int length, List<T> from, [int startFrom = 0]) { |
| 96 if (length < 0) throw new IllegalArgumentException(length); |
96 copyFrom(from, start, startFrom, count); | 97 copyFrom(from, start, startFrom, count); |
97 } | 98 } |
98 | 99 |
99 void removeRange(int start, int length) { | 100 void removeRange(int start, int length) { |
100 throw const NotImplementedException(); | 101 throw const UnsupportedOperationException( |
| 102 "Cannot remove range of a non-extendable array"); |
101 } | 103 } |
102 | 104 |
103 void insertRange(int start, int length, [T initialValue = null]) { | 105 void insertRange(int start, int length, [T initialValue = null]) { |
104 throw const NotImplementedException(); | 106 throw const NotImplementedException(); |
105 } | 107 } |
106 | 108 |
107 List<T> getRange(int start, int length) { | 109 List<T> getRange(int start, int length) { |
108 throw const NotImplementedException(); | 110 throw const NotImplementedException(); |
109 } | 111 } |
110 | 112 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 throw const UnsupportedOperationException( | 207 throw const UnsupportedOperationException( |
206 "Cannot modify an immutable array"); | 208 "Cannot modify an immutable array"); |
207 } | 209 } |
208 | 210 |
209 void setRange(int start, int length, List<T> from, [int startFrom = 0]) { | 211 void setRange(int start, int length, List<T> from, [int startFrom = 0]) { |
210 throw const UnsupportedOperationException( | 212 throw const UnsupportedOperationException( |
211 "Cannot modify an immutable array"); | 213 "Cannot modify an immutable array"); |
212 } | 214 } |
213 | 215 |
214 void removeRange(int start, int length) { | 216 void removeRange(int start, int length) { |
215 throw const NotImplementedException(); | 217 throw const UnsupportedOperationException( |
| 218 "Cannot remove range of an immutable array"); |
216 } | 219 } |
217 | 220 |
218 void insertRange(int start, int length, [T initialValue = null]) { | 221 void insertRange(int start, int length, [T initialValue = null]) { |
219 throw const NotImplementedException(); | 222 throw const NotImplementedException(); |
220 } | 223 } |
221 | 224 |
222 List<T> getRange(int start, int length) { | 225 List<T> getRange(int start, int length) { |
223 throw const NotImplementedException(); | 226 throw const NotImplementedException(); |
224 } | 227 } |
225 | 228 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 if (!hasNext()) { | 321 if (!hasNext()) { |
319 throw const NoMoreElementsException(); | 322 throw const NoMoreElementsException(); |
320 } | 323 } |
321 return _array[_pos++]; | 324 return _array[_pos++]; |
322 } | 325 } |
323 | 326 |
324 final Array<T> _array; | 327 final Array<T> _array; |
325 final int _length; // Cache array length for faster access. | 328 final int _length; // Cache array length for faster access. |
326 int _pos; | 329 int _pos; |
327 } | 330 } |
OLD | NEW |