Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Side by Side Diff: sdk/lib/collection/list.dart

Issue 1937103002: Make dart:collection strong-mode clean. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 if (length == 0) { 302 if (length == 0) {
303 throw IterableElementError.noElement(); 303 throw IterableElementError.noElement();
304 } 304 }
305 E result = this[length - 1]; 305 E result = this[length - 1];
306 length--; 306 length--;
307 return result; 307 return result;
308 } 308 }
309 309
310 void sort([int compare(E a, E b)]) { 310 void sort([int compare(E a, E b)]) {
311 if (compare == null) { 311 if (compare == null) {
312 var defaultCompare = Comparable.compare; 312 Sort.sort(this, Comparable.compare);
313 compare = defaultCompare; 313 } else {
314 Sort.sort(this, compare);
314 } 315 }
315 Sort.sort(this, compare);
316 } 316 }
317 317
318 void shuffle([Random random]) { 318 void shuffle([Random random]) {
319 if (random == null) random = new Random(); 319 if (random == null) random = new Random();
320 int length = this.length; 320 int length = this.length;
321 while (length > 1) { 321 while (length > 1) {
322 int pos = random.nextInt(length); 322 int pos = random.nextInt(length);
323 length -= 1; 323 length -= 1;
324 var tmp = this[length]; 324 var tmp = this[length];
325 this[length] = this[pos]; 325 this[length] = this[pos];
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 this[i] = fill; 361 this[i] = fill;
362 } 362 }
363 } 363 }
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 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) { 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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698