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 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); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 } | 77 } |
78 | 78 |
79 /** | 79 /** |
80 * Collection interface. | 80 * Collection interface. |
81 */ | 81 */ |
82 | 82 |
83 void forEach(f(E element)) { | 83 void forEach(f(E element)) { |
84 Collections.forEach(this, f); | 84 Collections.forEach(this, f); |
85 } | 85 } |
86 | 86 |
| 87 Collection map(f(E element)) { |
| 88 return Collections.map(this, new GrowableObjectArray.withCapacity(length), f
); |
| 89 } |
| 90 |
87 Collection<E> filter(bool f(E element)) { | 91 Collection<E> filter(bool f(E element)) { |
88 return Collections.filter(this, new GrowableObjectArray<E>(), f); | 92 return Collections.filter(this, new GrowableObjectArray<E>(), f); |
89 } | 93 } |
90 | 94 |
91 bool every(bool f(E element)) { | 95 bool every(bool f(E element)) { |
92 return Collections.every(this, f); | 96 return Collections.every(this, f); |
93 } | 97 } |
94 | 98 |
95 bool some(bool f(E element)) { | 99 bool some(bool f(E element)) { |
96 return Collections.some(this, f); | 100 return Collections.some(this, f); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 if (!hasNext()) { | 304 if (!hasNext()) { |
301 throw const NoMoreElementsException(); | 305 throw const NoMoreElementsException(); |
302 } | 306 } |
303 return _array[_pos++]; | 307 return _array[_pos++]; |
304 } | 308 } |
305 | 309 |
306 final List<E> _array; | 310 final List<E> _array; |
307 final int _length; // Cache array length for faster access. | 311 final int _length; // Cache array length for faster access. |
308 int _pos; | 312 int _pos; |
309 } | 313 } |
OLD | NEW |