| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 * Abstract implementation of a list. | 8 * Abstract implementation of a list. |
| 9 * | 9 * |
| 10 * `ListBase` can be used as a base class for implementing the `List` interface. | 10 * `ListBase` can be used as a base class for implementing the `List` interface. |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 } | 168 } |
| 169 | 169 |
| 170 String join([String separator = ""]) { | 170 String join([String separator = ""]) { |
| 171 if (length == 0) return ""; | 171 if (length == 0) return ""; |
| 172 StringBuffer buffer = new StringBuffer()..writeAll(this, separator); | 172 StringBuffer buffer = new StringBuffer()..writeAll(this, separator); |
| 173 return buffer.toString(); | 173 return buffer.toString(); |
| 174 } | 174 } |
| 175 | 175 |
| 176 Iterable<E> where(bool test(E element)) => new WhereIterable<E>(this, test); | 176 Iterable<E> where(bool test(E element)) => new WhereIterable<E>(this, test); |
| 177 | 177 |
| 178 Iterable/*<T>*/ map/*<T>*/(/*=T*/ f(E element)) => | 178 Iterable<T> map<T>(T f(E element)) => |
| 179 new MappedListIterable/*<E, T>*/(this, f); | 179 new MappedListIterable<E, T>(this, f); |
| 180 | 180 |
| 181 Iterable/*<T>*/ expand/*<T>*/(Iterable/*<T>*/ f(E element)) => | 181 Iterable<T> expand<T>(Iterable<T> f(E element)) => |
| 182 new ExpandIterable<E, dynamic/*=T*/>(this, f); | 182 new ExpandIterable<E, T>(this, f); |
| 183 | 183 |
| 184 E reduce(E combine(E previousValue, E element)) { | 184 E reduce(E combine(E previousValue, E element)) { |
| 185 int length = this.length; | 185 int length = this.length; |
| 186 if (length == 0) throw IterableElementError.noElement(); | 186 if (length == 0) throw IterableElementError.noElement(); |
| 187 E value = this[0]; | 187 E value = this[0]; |
| 188 for (int i = 1; i < length; i++) { | 188 for (int i = 1; i < length; i++) { |
| 189 value = combine(value, this[i]); | 189 value = combine(value, this[i]); |
| 190 if (length != this.length) { | 190 if (length != this.length) { |
| 191 throw new ConcurrentModificationError(this); | 191 throw new ConcurrentModificationError(this); |
| 192 } | 192 } |
| 193 } | 193 } |
| 194 return value; | 194 return value; |
| 195 } | 195 } |
| 196 | 196 |
| 197 dynamic/*=T*/ fold/*<T>*/(var/*=T*/ initialValue, | 197 T fold<T>(T initialValue, |
| 198 dynamic/*=T*/ combine(var/*=T*/ previousValue, E element)) { | 198 T combine(T previousValue, E element)) { |
| 199 var value = initialValue; | 199 var value = initialValue; |
| 200 int length = this.length; | 200 int length = this.length; |
| 201 for (int i = 0; i < length; i++) { | 201 for (int i = 0; i < length; i++) { |
| 202 value = combine(value, this[i]); | 202 value = combine(value, this[i]); |
| 203 if (length != this.length) { | 203 if (length != this.length) { |
| 204 throw new ConcurrentModificationError(this); | 204 throw new ConcurrentModificationError(this); |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 return value; | 207 return value; |
| 208 } | 208 } |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 | 364 |
| 365 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) { | 365 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) { |
| 366 RangeError.checkValidRange(start, end, this.length); | 366 RangeError.checkValidRange(start, end, this.length); |
| 367 int length = end - start; | 367 int length = end - start; |
| 368 if (length == 0) return; | 368 if (length == 0) return; |
| 369 RangeError.checkNotNegative(skipCount, "skipCount"); | 369 RangeError.checkNotNegative(skipCount, "skipCount"); |
| 370 | 370 |
| 371 List<E> otherList; | 371 List<E> otherList; |
| 372 int otherStart; | 372 int otherStart; |
| 373 // TODO(floitsch): Make this accept more. | 373 // TODO(floitsch): Make this accept more. |
| 374 if (iterable is List/*<E>*/) { | 374 if (iterable is List<E>) { |
| 375 otherList = iterable; | 375 otherList = iterable; |
| 376 otherStart = skipCount; | 376 otherStart = skipCount; |
| 377 } else { | 377 } else { |
| 378 otherList = iterable.skip(skipCount).toList(growable: false); | 378 otherList = iterable.skip(skipCount).toList(growable: false); |
| 379 otherStart = 0; | 379 otherStart = 0; |
| 380 } | 380 } |
| 381 if (otherStart + length > otherList.length) { | 381 if (otherStart + length > otherList.length) { |
| 382 throw IterableElementError.tooFew(); | 382 throw IterableElementError.tooFew(); |
| 383 } | 383 } |
| 384 if (otherStart < start) { | 384 if (otherStart < start) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 for (E element in iterable) { | 507 for (E element in iterable) { |
| 508 this[index++] = element; | 508 this[index++] = element; |
| 509 } | 509 } |
| 510 } | 510 } |
| 511 } | 511 } |
| 512 | 512 |
| 513 Iterable<E> get reversed => new ReversedListIterable<E>(this); | 513 Iterable<E> get reversed => new ReversedListIterable<E>(this); |
| 514 | 514 |
| 515 String toString() => IterableBase.iterableToFullString(this, '[', ']'); | 515 String toString() => IterableBase.iterableToFullString(this, '[', ']'); |
| 516 } | 516 } |
| OLD | NEW |