| OLD | NEW |
| 1 // Copyright (c) 2011, 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 ListFactory<E> { | 5 class ListFactory<E> { |
| 6 | 6 |
| 7 factory List.from(Iterable<E> other) { | 7 factory List.from(Iterable<E> other) { |
| 8 GrowableObjectArray<E> list = new GrowableObjectArray<E>(); | 8 GrowableObjectArray<E> list = new GrowableObjectArray<E>(); |
| 9 for (final e in other) { | 9 for (final e in other) { |
| 10 list.add(e); | 10 list.add(e); |
| 11 } | 11 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 24 // TODO(srdjan): Use shared array implementation. | 24 // TODO(srdjan): Use shared array implementation. |
| 25 class ObjectArray<E> implements List<E> { | 25 class ObjectArray<E> implements List<E> { |
| 26 | 26 |
| 27 factory ObjectArray(int length) native "ObjectArray_allocate"; | 27 factory ObjectArray(int length) native "ObjectArray_allocate"; |
| 28 | 28 |
| 29 E operator [](int index) native "ObjectArray_getIndexed"; | 29 E operator [](int index) native "ObjectArray_getIndexed"; |
| 30 | 30 |
| 31 void operator []=(int index, E value) native "ObjectArray_setIndexed"; | 31 void operator []=(int index, E value) native "ObjectArray_setIndexed"; |
| 32 | 32 |
| 33 String toString() { | 33 String toString() { |
| 34 return Arrays.asString(this); | 34 return Collections.collectionToString(this); |
| 35 } | 35 } |
| 36 | 36 |
| 37 int get length() native "ObjectArray_getLength"; | 37 int get length() native "ObjectArray_getLength"; |
| 38 | 38 |
| 39 void copyFrom(List src, int srcStart, int dstStart, int count) { | 39 void copyFrom(List src, int srcStart, int dstStart, int count) { |
| 40 if (src is ObjectArray) { | 40 if (src is ObjectArray) { |
| 41 _copyFromObjectArray(src, srcStart, dstStart, count); | 41 _copyFromObjectArray(src, srcStart, dstStart, count); |
| 42 } else { | 42 } else { |
| 43 Arrays.copy(src, srcStart, this, dstStart, count); | 43 Arrays.copy(src, srcStart, this, dstStart, count); |
| 44 } | 44 } |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 bool isEmpty() { | 231 bool isEmpty() { |
| 232 return this.length === 0; | 232 return this.length === 0; |
| 233 } | 233 } |
| 234 | 234 |
| 235 void sort(int compare(E a, E b)) { | 235 void sort(int compare(E a, E b)) { |
| 236 throw const UnsupportedOperationException( | 236 throw const UnsupportedOperationException( |
| 237 "Cannot modify an immutable array"); | 237 "Cannot modify an immutable array"); |
| 238 } | 238 } |
| 239 | 239 |
| 240 String toString() { | 240 String toString() { |
| 241 return Arrays.asString(this); | 241 return Collections.collectionToString(this); |
| 242 } | 242 } |
| 243 | 243 |
| 244 int indexOf(E element, [int start = 0]) { | 244 int indexOf(E element, [int start = 0]) { |
| 245 return Arrays.indexOf(this, element, start, this.length); | 245 return Arrays.indexOf(this, element, start, this.length); |
| 246 } | 246 } |
| 247 | 247 |
| 248 int lastIndexOf(E element, [int start = null]) { | 248 int lastIndexOf(E element, [int start = null]) { |
| 249 if (start === null) start = length - 1; | 249 if (start === null) start = length - 1; |
| 250 return Arrays.lastIndexOf(this, element, start); | 250 return Arrays.lastIndexOf(this, element, start); |
| 251 } | 251 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 if (!hasNext()) { | 304 if (!hasNext()) { |
| 305 throw const NoMoreElementsException(); | 305 throw const NoMoreElementsException(); |
| 306 } | 306 } |
| 307 return _array[_pos++]; | 307 return _array[_pos++]; |
| 308 } | 308 } |
| 309 | 309 |
| 310 final List<E> _array; | 310 final List<E> _array; |
| 311 final int _length; // Cache array length for faster access. | 311 final int _length; // Cache array length for faster access. |
| 312 int _pos; | 312 int _pos; |
| 313 } | 313 } |
| OLD | NEW |