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