| 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 [Iterable] mixin implements all [Iterable] members except `iterator`. | 8 * This [Iterable] mixin implements all [Iterable] members except `iterator`. |
| 9 * | 9 * |
| 10 * All other methods are implemented in terms of `iterator`. | 10 * All other methods are implemented in terms of `iterator`. |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 } | 179 } |
| 180 result = element; | 180 result = element; |
| 181 foundMatching = true; | 181 foundMatching = true; |
| 182 } | 182 } |
| 183 } | 183 } |
| 184 if (foundMatching) return result; | 184 if (foundMatching) return result; |
| 185 throw IterableElementError.noElement(); | 185 throw IterableElementError.noElement(); |
| 186 } | 186 } |
| 187 | 187 |
| 188 E elementAt(int index) { | 188 E elementAt(int index) { |
| 189 if (index is! int || index < 0) throw new RangeError.value(index); | 189 if (index is! int) throw new ArgumentError.notNull("index"); |
| 190 int remaining = index; | 190 RangeError.checkNotNegative(index, "index"); |
| 191 int elementIndex = 0; |
| 191 for (E element in this) { | 192 for (E element in this) { |
| 192 if (remaining == 0) return element; | 193 if (index == elementIndex) return element; |
| 193 remaining--; | 194 elementIndex++; |
| 194 } | 195 } |
| 195 throw new RangeError.value(index); | 196 throw new RangeError.index(index, this, "index", null, elementIndex); |
| 196 } | 197 } |
| 197 | 198 |
| 199 |
| 198 String toString() => IterableBase.iterableToShortString(this, '(', ')'); | 200 String toString() => IterableBase.iterableToShortString(this, '(', ')'); |
| 199 } | 201 } |
| 200 | 202 |
| 201 /** | 203 /** |
| 202 * Base class for implementing [Iterable]. | 204 * Base class for implementing [Iterable]. |
| 203 * | 205 * |
| 204 * This class implements all methods of [Iterable] except [Iterable.iterator] | 206 * This class implements all methods of [Iterable] except [Iterable.iterator] |
| 205 * in terms of `iterator`. | 207 * in terms of `iterator`. |
| 206 */ | 208 */ |
| 207 abstract class IterableBase<E> implements Iterable<E> { | 209 abstract class IterableBase<E> implements Iterable<E> { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 } | 375 } |
| 374 result = element; | 376 result = element; |
| 375 foundMatching = true; | 377 foundMatching = true; |
| 376 } | 378 } |
| 377 } | 379 } |
| 378 if (foundMatching) return result; | 380 if (foundMatching) return result; |
| 379 throw IterableElementError.noElement(); | 381 throw IterableElementError.noElement(); |
| 380 } | 382 } |
| 381 | 383 |
| 382 E elementAt(int index) { | 384 E elementAt(int index) { |
| 383 if (index is! int || index < 0) throw new RangeError.value(index); | 385 if (index is! int) throw new ArgumentError.notNull("index"); |
| 384 int remaining = index; | 386 RangeError.checkNotNegative(index, "index"); |
| 387 int elementIndex = 0; |
| 385 for (E element in this) { | 388 for (E element in this) { |
| 386 if (remaining == 0) return element; | 389 if (index == elementIndex) return element; |
| 387 remaining--; | 390 elementIndex++; |
| 388 } | 391 } |
| 389 throw new RangeError.value(index); | 392 throw new RangeError.index(index, this, "index", null, elementIndex); |
| 390 } | 393 } |
| 391 | 394 |
| 392 /** | 395 /** |
| 393 * Returns a string representation of (some of) the elements of `this`. | 396 * Returns a string representation of (some of) the elements of `this`. |
| 394 * | 397 * |
| 395 * Elements are represented by their own `toString` results. | 398 * Elements are represented by their own `toString` results. |
| 396 * | 399 * |
| 397 * The representation always contains the first three elements. | 400 * The representation always contains the first three elements. |
| 398 * If there are less than a hundred elements in the iterable, it also | 401 * If there are less than a hundred elements in the iterable, it also |
| 399 * contains the last two elements. | 402 * contains the last two elements. |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 length += ELLIPSIS_SIZE + OVERHEAD; | 591 length += ELLIPSIS_SIZE + OVERHEAD; |
| 589 } | 592 } |
| 590 } | 593 } |
| 591 if (elision != null) { | 594 if (elision != null) { |
| 592 parts.add(elision); | 595 parts.add(elision); |
| 593 } | 596 } |
| 594 parts.add(penultimateString); | 597 parts.add(penultimateString); |
| 595 parts.add(ultimateString); | 598 parts.add(ultimateString); |
| 596 } | 599 } |
| 597 } | 600 } |
| OLD | NEW |