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

Side by Side Diff: runtime/lib/array.dart

Issue 24740003: Add List.shuffle(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Adddress comments Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
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 5
6 // TODO(srdjan): Use shared array implementation. 6 // TODO(srdjan): Use shared array implementation.
7 class _ObjectArray<E> implements List<E> { 7 class _ObjectArray<E> implements List<E> {
8 static final int _classId = (new _ObjectArray(0))._cid; 8 static final int _classId = (new _ObjectArray(0))._cid;
9 9
10 factory _ObjectArray(length) native "ObjectArray_allocate"; 10 factory _ObjectArray(length) native "ObjectArray_allocate";
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 195 }
196 196
197 bool get isNotEmpty => !isEmpty; 197 bool get isNotEmpty => !isEmpty;
198 198
199 Iterable<E> get reversed => IterableMixinWorkaround.reversedList(this); 199 Iterable<E> get reversed => IterableMixinWorkaround.reversedList(this);
200 200
201 void sort([int compare(E a, E b)]) { 201 void sort([int compare(E a, E b)]) {
202 IterableMixinWorkaround.sortList(this, compare); 202 IterableMixinWorkaround.sortList(this, compare);
203 } 203 }
204 204
205 void shuffle() {
206 IterableMixinWorkaround.shuffleList(this);
207 }
208
205 int indexOf(Object element, [int start = 0]) { 209 int indexOf(Object element, [int start = 0]) {
206 return Arrays.indexOf(this, element, start, this.length); 210 return Arrays.indexOf(this, element, start, this.length);
207 } 211 }
208 212
209 int lastIndexOf(Object element, [int start = null]) { 213 int lastIndexOf(Object element, [int start = null]) {
210 if (start == null) start = length - 1; 214 if (start == null) start = length - 1;
211 return Arrays.lastIndexOf(this, element, start); 215 return Arrays.lastIndexOf(this, element, start);
212 } 216 }
213 217
214 Iterator<E> get iterator { 218 Iterator<E> get iterator {
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 453
450 bool get isNotEmpty => !isEmpty; 454 bool get isNotEmpty => !isEmpty;
451 455
452 Iterable<E> get reversed => IterableMixinWorkaround.reversedList(this); 456 Iterable<E> get reversed => IterableMixinWorkaround.reversedList(this);
453 457
454 void sort([int compare(E a, E b)]) { 458 void sort([int compare(E a, E b)]) {
455 throw new UnsupportedError( 459 throw new UnsupportedError(
456 "Cannot modify an immutable array"); 460 "Cannot modify an immutable array");
457 } 461 }
458 462
463 void shuffle() {
464 throw new UnsupportedError(
465 "Cannot modify an immutable array");
466 }
467
459 String toString() { 468 String toString() {
460 return IterableMixinWorkaround.toStringIterable(this, '[', ']'); 469 return IterableMixinWorkaround.toStringIterable(this, '[', ']');
461 } 470 }
462 471
463 int indexOf(Object element, [int start = 0]) { 472 int indexOf(Object element, [int start = 0]) {
464 return Arrays.indexOf(this, element, start, this.length); 473 return Arrays.indexOf(this, element, start, this.length);
465 } 474 }
466 475
467 int lastIndexOf(Object element, [int start = null]) { 476 int lastIndexOf(Object element, [int start = null]) {
468 if (start == null) start = length - 1; 477 if (start == null) start = length - 1;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 } 558 }
550 _position = _length; 559 _position = _length;
551 _current = null; 560 _current = null;
552 return false; 561 return false;
553 } 562 }
554 563
555 E get current { 564 E get current {
556 return _current; 565 return _current;
557 } 566 }
558 } 567 }
OLDNEW
« no previous file with comments | « pkg/unmodifiable_collection/lib/unmodifiable_collection.dart ('k') | runtime/lib/growable_array.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698