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 // TODO(srdjan): Use shared array implementation. | 6 // TODO(srdjan): Use shared array implementation. |
7 class ObjectArray<E> implements List<E> { | 7 class ObjectArray<E> implements List<E> { |
8 | 8 |
9 factory ObjectArray(int length) native "ObjectArray_allocate"; | 9 factory ObjectArray(int length) native "ObjectArray_allocate"; |
10 | 10 |
11 E operator [](int index) native "ObjectArray_getIndexed"; | 11 E operator [](int index) native "ObjectArray_getIndexed"; |
12 | 12 |
13 void operator []=(int index, E value) native "ObjectArray_setIndexed"; | 13 void operator []=(int index, E value) native "ObjectArray_setIndexed"; |
14 | 14 |
15 String toString() { | 15 String toString() { |
16 return Collections.collectionToString(this); | 16 return Collections.collectionToString(this); |
17 } | 17 } |
18 | 18 |
19 int get length() native "ObjectArray_getLength"; | 19 int get length() native "ObjectArray_getLength"; |
20 | 20 |
21 void copyFrom(List src, int srcStart, int dstStart, int count) { | |
22 if (src is ObjectArray) { | |
23 _copyFromObjectArray(src, srcStart, dstStart, count); | |
24 } else { | |
25 Arrays.copy(src, srcStart, this, dstStart, count); | |
26 } | |
27 } | |
28 | |
29 void _copyFromObjectArray(ObjectArray src, | 21 void _copyFromObjectArray(ObjectArray src, |
30 int srcStart, | 22 int srcStart, |
31 int dstStart, | 23 int dstStart, |
32 int count) | 24 int count) |
33 native "ObjectArray_copyFromObjectArray"; | 25 native "ObjectArray_copyFromObjectArray"; |
34 | 26 |
35 void setRange(int start, int length, List<E> from, [int startFrom = 0]) { | 27 void setRange(int start, int length, List<E> from, [int startFrom = 0]) { |
36 if (length < 0) { | 28 if (length < 0) { |
37 throw new IllegalArgumentException("negative length $length"); | 29 throw new IllegalArgumentException("negative length $length"); |
38 } | 30 } |
39 copyFrom(from, startFrom, start, length); | 31 if (from is ObjectArray) { |
| 32 _copyFromObjectArray(from, startFrom, start, length); |
| 33 } else { |
| 34 Arrays.copy(from, startFrom, this, start, length); |
| 35 } |
40 } | 36 } |
41 | 37 |
42 void removeRange(int start, int length) { | 38 void removeRange(int start, int length) { |
43 throw const UnsupportedOperationException( | 39 throw const UnsupportedOperationException( |
44 "Cannot remove range of a non-extendable array"); | 40 "Cannot remove range of a non-extendable array"); |
45 } | 41 } |
46 | 42 |
47 void insertRange(int start, int length, [E initialValue = null]) { | 43 void insertRange(int start, int length, [E initialValue = null]) { |
48 throw const UnsupportedOperationException( | 44 throw const UnsupportedOperationException( |
49 "Cannot insert range in a non-extendable array"); | 45 "Cannot insert range in a non-extendable array"); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 if (!hasNext()) { | 296 if (!hasNext()) { |
301 throw const NoMoreElementsException(); | 297 throw const NoMoreElementsException(); |
302 } | 298 } |
303 return _array[_pos++]; | 299 return _array[_pos++]; |
304 } | 300 } |
305 | 301 |
306 final List<E> _array; | 302 final List<E> _array; |
307 final int _length; // Cache array length for faster access. | 303 final int _length; // Cache array length for faster access. |
308 int _pos; | 304 int _pos; |
309 } | 305 } |
OLD | NEW |