| 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 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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)) { | 87 Collection map(f(E element)) { |
| 88 return Collections.map(this, new GrowableObjectArray.withCapacity(length), f
); | 88 return Collections.map(this, new GrowableObjectArray.withCapacity(length), f
); |
| 89 } | 89 } |
| 90 | 90 |
| 91 Dynamic reduce(Dynamic initialValue, | |
| 92 Dynamic combine(Dynamic previousValue, E element)) { | |
| 93 return Collections.reduce(this, initialValue, combine); | |
| 94 } | |
| 95 | |
| 96 Collection<E> filter(bool f(E element)) { | 91 Collection<E> filter(bool f(E element)) { |
| 97 return Collections.filter(this, new GrowableObjectArray<E>(), f); | 92 return Collections.filter(this, new GrowableObjectArray<E>(), f); |
| 98 } | 93 } |
| 99 | 94 |
| 100 bool every(bool f(E element)) { | 95 bool every(bool f(E element)) { |
| 101 return Collections.every(this, f); | 96 return Collections.every(this, f); |
| 102 } | 97 } |
| 103 | 98 |
| 104 bool some(bool f(E element)) { | 99 bool some(bool f(E element)) { |
| 105 return Collections.some(this, f); | 100 return Collections.some(this, f); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 */ | 213 */ |
| 219 | 214 |
| 220 void forEach(f(E element)) { | 215 void forEach(f(E element)) { |
| 221 Collections.forEach(this, f); | 216 Collections.forEach(this, f); |
| 222 } | 217 } |
| 223 | 218 |
| 224 Collection map(f(E element)) { | 219 Collection map(f(E element)) { |
| 225 return Collections.map(this, new GrowableObjectArray.withCapacity(length), f
); | 220 return Collections.map(this, new GrowableObjectArray.withCapacity(length), f
); |
| 226 } | 221 } |
| 227 | 222 |
| 228 Dynamic reduce(Dynamic initialValue, | |
| 229 Dynamic combine(Dynamic previousValue, E element)) { | |
| 230 return Collections.reduce(this, initialValue, combine); | |
| 231 } | |
| 232 | |
| 233 Collection<E> filter(bool f(E element)) { | 223 Collection<E> filter(bool f(E element)) { |
| 234 return Collections.filter(this, new GrowableObjectArray<E>(), f); | 224 return Collections.filter(this, new GrowableObjectArray<E>(), f); |
| 235 } | 225 } |
| 236 | 226 |
| 237 bool every(bool f(E element)) { | 227 bool every(bool f(E element)) { |
| 238 return Collections.every(this, f); | 228 return Collections.every(this, f); |
| 239 } | 229 } |
| 240 | 230 |
| 241 bool some(bool f(E element)) { | 231 bool some(bool f(E element)) { |
| 242 return Collections.some(this, f); | 232 return Collections.some(this, f); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 if (!hasNext()) { | 308 if (!hasNext()) { |
| 319 throw const NoMoreElementsException(); | 309 throw const NoMoreElementsException(); |
| 320 } | 310 } |
| 321 return _array[_pos++]; | 311 return _array[_pos++]; |
| 322 } | 312 } |
| 323 | 313 |
| 324 final List<E> _array; | 314 final List<E> _array; |
| 325 final int _length; // Cache array length for faster access. | 315 final int _length; // Cache array length for faster access. |
| 326 int _pos; | 316 int _pos; |
| 327 } | 317 } |
| OLD | NEW |