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 part of dart.collection; | 5 part of dart.collection; |
6 | 6 |
7 /** | 7 /** |
8 * This class provides default implementations for Iterables (including Lists). | 8 * This class provides default implementations for Iterables (including Lists). |
9 * | 9 * |
10 * Once Dart receives Mixins it will be replaced with mixin classes. | 10 * Once Dart receives Mixins it will be replaced with mixin classes. |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 } | 272 } |
273 throw new RangeError.value(index); | 273 throw new RangeError.value(index); |
274 } | 274 } |
275 | 275 |
276 static String join(Iterable iterable, [String separator]) { | 276 static String join(Iterable iterable, [String separator]) { |
277 Iterator iterator = iterable.iterator; | 277 Iterator iterator = iterable.iterator; |
278 if (!iterator.moveNext()) return ""; | 278 if (!iterator.moveNext()) return ""; |
279 StringBuffer buffer = new StringBuffer(); | 279 StringBuffer buffer = new StringBuffer(); |
280 if (separator == null || separator == "") { | 280 if (separator == null || separator == "") { |
281 do { | 281 do { |
282 buffer.add("${iterator.current}"); | 282 buffer.write("${iterator.current}"); |
283 } while (iterator.moveNext()); | 283 } while (iterator.moveNext()); |
284 } else { | 284 } else { |
285 buffer.add("${iterator.current}"); | 285 buffer.write("${iterator.current}"); |
286 while (iterator.moveNext()) { | 286 while (iterator.moveNext()) { |
287 buffer.add(separator); | 287 buffer.write(separator); |
288 buffer.add("${iterator.current}"); | 288 buffer.write("${iterator.current}"); |
289 } | 289 } |
290 } | 290 } |
291 return buffer.toString(); | 291 return buffer.toString(); |
292 } | 292 } |
293 | 293 |
294 static String joinList(List list, [String separator]) { | 294 static String joinList(List list, [String separator]) { |
295 if (list.isEmpty) return ""; | 295 if (list.isEmpty) return ""; |
296 if (list.length == 1) return "${list[0]}"; | 296 if (list.length == 1) return "${list[0]}"; |
297 StringBuffer buffer = new StringBuffer(); | 297 StringBuffer buffer = new StringBuffer(); |
298 if (separator == null || separator == "") { | 298 if (separator == null || separator == "") { |
299 for (int i = 0; i < list.length; i++) { | 299 for (int i = 0; i < list.length; i++) { |
300 buffer.add("${list[i]}"); | 300 buffer.write("${list[i]}"); |
301 } | 301 } |
302 } else { | 302 } else { |
303 buffer.add("${list[0]}"); | 303 buffer.write("${list[0]}"); |
304 for (int i = 1; i < list.length; i++) { | 304 for (int i = 1; i < list.length; i++) { |
305 buffer.add(separator); | 305 buffer.write(separator); |
306 buffer.add("${list[i]}"); | 306 buffer.write("${list[i]}"); |
307 } | 307 } |
308 } | 308 } |
309 return buffer.toString(); | 309 return buffer.toString(); |
310 } | 310 } |
311 | 311 |
312 static Iterable where(Iterable iterable, bool f(var element)) { | 312 static Iterable where(Iterable iterable, bool f(var element)) { |
313 return new WhereIterable(iterable, f); | 313 return new WhereIterable(iterable, f); |
314 } | 314 } |
315 | 315 |
316 static Iterable map(Iterable iterable, f(var element)) { | 316 static Iterable map(Iterable iterable, f(var element)) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 * The source of the elements may be a [List] or any [Iterable] with | 394 * The source of the elements may be a [List] or any [Iterable] with |
395 * efficient [Iterable.length] and [Iterable.elementAt]. | 395 * efficient [Iterable.length] and [Iterable.elementAt]. |
396 */ | 396 */ |
397 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { | 397 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { |
398 Iterable<E> _source; | 398 Iterable<E> _source; |
399 /** Create an unmodifiable list backed by [source]. */ | 399 /** Create an unmodifiable list backed by [source]. */ |
400 UnmodifiableListView(Iterable<E> source) : _source = source; | 400 UnmodifiableListView(Iterable<E> source) : _source = source; |
401 int get length => _source.length; | 401 int get length => _source.length; |
402 E operator[](int index) => _source.elementAt(index); | 402 E operator[](int index) => _source.elementAt(index); |
403 } | 403 } |
OLD | NEW |