| 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 E removeLast() { | 295 E removeLast() { |
| 296 if (length == 0) { | 296 if (length == 0) { |
| 297 throw IterableElementError.noElement(); | 297 throw IterableElementError.noElement(); |
| 298 } | 298 } |
| 299 E result = this[length - 1]; | 299 E result = this[length - 1]; |
| 300 length--; | 300 length--; |
| 301 return result; | 301 return result; |
| 302 } | 302 } |
| 303 | 303 |
| 304 void sort([int compare(E a, E b)]) { | 304 void sort([int compare(E a, E b)]) { |
| 305 if (compare == null) { | 305 Sort.sort(this, compare == null ? Comparable.compare : compare); |
| 306 var defaultCompare = Comparable.compare; | |
| 307 compare = defaultCompare; | |
| 308 } | |
| 309 Sort.sort(this, compare); | |
| 310 } | 306 } |
| 311 | 307 |
| 312 void shuffle([Random random]) { | 308 void shuffle([Random random]) { |
| 313 if (random == null) random = new Random(); | 309 if (random == null) random = new Random(); |
| 314 int length = this.length; | 310 int length = this.length; |
| 315 while (length > 1) { | 311 while (length > 1) { |
| 316 int pos = random.nextInt(length); | 312 int pos = random.nextInt(length); |
| 317 length -= 1; | 313 length -= 1; |
| 318 var tmp = this[length]; | 314 var tmp = this[length]; |
| 319 this[length] = this[pos]; | 315 this[length] = this[pos]; |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 for (E element in iterable) { | 491 for (E element in iterable) { |
| 496 this[index++] = element; | 492 this[index++] = element; |
| 497 } | 493 } |
| 498 } | 494 } |
| 499 } | 495 } |
| 500 | 496 |
| 501 Iterable<E> get reversed => new ReversedListIterable<E>(this); | 497 Iterable<E> get reversed => new ReversedListIterable<E>(this); |
| 502 | 498 |
| 503 String toString() => IterableBase.iterableToFullString(this, '[', ']'); | 499 String toString() => IterableBase.iterableToFullString(this, '[', ']'); |
| 504 } | 500 } |
| OLD | NEW |