Chromium Code Reviews| 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 interface Array<T> extends List<T> { |
|
srdjan
2011/10/18 08:08:21
If this is a temporary definition, please add a co
ngeoffray
2011/10/18 08:15:01
Yes, that's a temporary definition. Added a commen
| |
| 6 factory Array.from(Iterable<T> other) { | |
| 7 GrowableObjectArray<T> array = new GrowableObjectArray<T>(); | |
| 8 for (final e in other) { | |
| 9 array.add(e); | |
| 10 } | |
| 11 return array; | |
| 12 } | |
| 13 | |
| 14 factory Array.fromArray(Array<T> other, int startIndex, int endIndex) { | |
| 15 Array array = new Array<T>(); | |
| 16 if (endIndex > other.length) endIndex = other.length; | |
| 17 if (startIndex < 0) startIndex = 0; | |
| 18 int count = endIndex - startIndex; | |
| 19 if (count > 0) { | |
| 20 array.length = count; | |
| 21 Arrays.copy(other, startIndex, array, 0, count); | |
| 22 } | |
| 23 return array; | |
| 24 } | |
| 25 | |
| 26 factory Array([int length = null]) { | |
| 27 if (length === null) { | |
| 28 return new GrowableObjectArray<T>(); | |
| 29 } else { | |
| 30 return new ObjectArray<T>(length); | |
| 31 } | |
| 32 } | |
| 33 } | 6 } |
| 34 | 7 |
| 35 class ListFactory<T> { | 8 class ListFactory<T> { |
| 36 | 9 |
| 37 factory List.from(Iterable<T> other) { | 10 factory List.from(Iterable<T> other) { |
| 38 GrowableObjectArray<T> list = new GrowableObjectArray<T>(); | 11 GrowableObjectArray<T> list = new GrowableObjectArray<T>(); |
| 39 for (final e in other) { | 12 for (final e in other) { |
| 40 list.add(e); | 13 list.add(e); |
| 41 } | 14 } |
| 42 return list; | 15 return list; |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 if (!hasNext()) { | 302 if (!hasNext()) { |
| 330 throw const NoMoreElementsException(); | 303 throw const NoMoreElementsException(); |
| 331 } | 304 } |
| 332 return _array[_pos++]; | 305 return _array[_pos++]; |
| 333 } | 306 } |
| 334 | 307 |
| 335 final Array<T> _array; | 308 final Array<T> _array; |
| 336 final int _length; // Cache array length for faster access. | 309 final int _length; // Cache array length for faster access. |
| 337 int _pos; | 310 int _pos; |
| 338 } | 311 } |
| OLD | NEW |