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 * All operations are defined in terms of `length`, `operator[]`, | 10 * All operations are defined in terms of `length`, `operator[]`, |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 } | 294 } |
295 | 295 |
296 void sort([int compare(E a, E b)]) { | 296 void sort([int compare(E a, E b)]) { |
297 if (compare == null) { | 297 if (compare == null) { |
298 var defaultCompare = Comparable.compare; | 298 var defaultCompare = Comparable.compare; |
299 compare = defaultCompare; | 299 compare = defaultCompare; |
300 } | 300 } |
301 Sort.sort(this, compare); | 301 Sort.sort(this, compare); |
302 } | 302 } |
303 | 303 |
304 void shuffle() { | 304 void shuffle([Random random]) { |
305 Random random = new Random(); | 305 if (random == null) random = new Random(); |
306 int length = this.length; | 306 int length = this.length; |
307 while (length > 1) { | 307 while (length > 1) { |
308 int pos = random.nextInt(length); | 308 int pos = random.nextInt(length); |
309 length -= 1; | 309 length -= 1; |
310 var tmp = this[length]; | 310 var tmp = this[length]; |
311 this[length] = this[pos]; | 311 this[length] = this[pos]; |
312 this[pos] = tmp; | 312 this[pos] = tmp; |
313 } | 313 } |
314 } | 314 } |
315 | 315 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 result.writeAll(this, ', '); | 498 result.writeAll(this, ', '); |
499 result.write(']'); | 499 result.write(']'); |
500 } finally { | 500 } finally { |
501 assert(identical(_toStringList.last, this)); | 501 assert(identical(_toStringList.last, this)); |
502 _toStringList.removeLast(); | 502 _toStringList.removeLast(); |
503 } | 503 } |
504 | 504 |
505 return result.toString(); | 505 return result.toString(); |
506 } | 506 } |
507 } | 507 } |
OLD | NEW |