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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 int remaining = index; | 275 int remaining = index; |
276 for (dynamic element in iterable) { | 276 for (dynamic element in iterable) { |
277 if (remaining == 0) return element; | 277 if (remaining == 0) return element; |
278 remaining--; | 278 remaining--; |
279 } | 279 } |
280 throw new RangeError.value(index); | 280 throw new RangeError.value(index); |
281 } | 281 } |
282 | 282 |
283 static String join(Iterable iterable, [String separator]) { | 283 static String join(Iterable iterable, [String separator]) { |
284 StringBuffer buffer = new StringBuffer(); | 284 StringBuffer buffer = new StringBuffer(); |
285 buffer.writeAll(iterable, separator == null ? "" : separator); | 285 buffer.writeAll(iterable, separator); |
286 return buffer.toString(); | 286 return buffer.toString(); |
287 } | 287 } |
288 | 288 |
289 static String joinList(List list, [String separator]) { | 289 static String joinList(List list, [String separator]) { |
290 if (list.isEmpty) return ""; | 290 if (list.isEmpty) return ""; |
291 if (list.length == 1) return "${list[0]}"; | 291 if (list.length == 1) return "${list[0]}"; |
292 StringBuffer buffer = new StringBuffer(); | 292 StringBuffer buffer = new StringBuffer(); |
293 if (separator == null || separator == "") { | 293 if (separator.isEmpty) { |
294 for (int i = 0; i < list.length; i++) { | 294 for (int i = 0; i < list.length; i++) { |
295 buffer.write("${list[i]}"); | 295 buffer.write(list[i]); |
296 } | 296 } |
297 } else { | 297 } else { |
298 buffer.write("${list[0]}"); | 298 buffer.write(list[0]); |
299 for (int i = 1; i < list.length; i++) { | 299 for (int i = 1; i < list.length; i++) { |
300 buffer.write(separator); | 300 buffer.write(separator); |
301 buffer.write("${list[i]}"); | 301 buffer.write(list[i]); |
302 } | 302 } |
303 } | 303 } |
304 return buffer.toString(); | 304 return buffer.toString(); |
305 } | 305 } |
306 | 306 |
307 static Iterable where(Iterable iterable, bool f(var element)) { | 307 static Iterable where(Iterable iterable, bool f(var element)) { |
308 return new WhereIterable(iterable, f); | 308 return new WhereIterable(iterable, f); |
309 } | 309 } |
310 | 310 |
311 static Iterable map(Iterable iterable, f(var element)) { | 311 static Iterable map(Iterable iterable, f(var element)) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 * The source of the elements may be a [List] or any [Iterable] with | 429 * The source of the elements may be a [List] or any [Iterable] with |
430 * efficient [Iterable.length] and [Iterable.elementAt]. | 430 * efficient [Iterable.length] and [Iterable.elementAt]. |
431 */ | 431 */ |
432 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { | 432 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { |
433 Iterable<E> _source; | 433 Iterable<E> _source; |
434 /** Create an unmodifiable list backed by [source]. */ | 434 /** Create an unmodifiable list backed by [source]. */ |
435 UnmodifiableListView(Iterable<E> source) : _source = source; | 435 UnmodifiableListView(Iterable<E> source) : _source = source; |
436 int get length => _source.length; | 436 int get length => _source.length; |
437 E operator[](int index) => _source.elementAt(index); | 437 E operator[](int index) => _source.elementAt(index); |
438 } | 438 } |
OLD | NEW |