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

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

Issue 18837002: Move toString() to collection classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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) 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 10 matching lines...) Expand all
21 * `operator[]` members. It implements write operations using those and 21 * `operator[]` members. It implements write operations using those and
22 * `length=` and `operator[]=` 22 * `length=` and `operator[]=`
23 * 23 *
24 * A fixed-length list should mix this class in, and the [FixedLengthListMixin] 24 * A fixed-length list should mix this class in, and the [FixedLengthListMixin]
25 * as well, in that order, to overwrite the methods that modify the length. 25 * as well, in that order, to overwrite the methods that modify the length.
26 * 26 *
27 * An unmodifiable list should mix [UnmodifiableListMixin] on top of this 27 * An unmodifiable list should mix [UnmodifiableListMixin] on top of this
28 * mixin to prevent all modifications. 28 * mixin to prevent all modifications.
29 */ 29 */
30 abstract class ListMixin<E> implements List<E> { 30 abstract class ListMixin<E> implements List<E> {
31 static List _toStringList = new List();
32
31 // Iterable interface. 33 // Iterable interface.
32 Iterator<E> get iterator => new ListIterator<E>(this); 34 Iterator<E> get iterator => new ListIterator<E>(this);
33 35
34 E elementAt(int index) => this[index]; 36 E elementAt(int index) => this[index];
35 37
36 void forEach(void action(E element)) { 38 void forEach(void action(E element)) {
37 int length = this.length; 39 int length = this.length;
38 for (int i = 0; i < length; i++) { 40 for (int i = 0; i < length; i++) {
39 action(this[i]); 41 action(this[i]);
40 if (length != this.length) { 42 if (length != this.length) {
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 setRange(index, index + iterable.length, iterable); 472 setRange(index, index + iterable.length, iterable);
471 } else { 473 } else {
472 for (E element in iterable) { 474 for (E element in iterable) {
473 this[index++] = element; 475 this[index++] = element;
474 } 476 }
475 } 477 }
476 } 478 }
477 479
478 Iterable<E> get reversed => new ReversedListIterable(this); 480 Iterable<E> get reversed => new ReversedListIterable(this);
479 481
480 String toString() => ToString.iterableToString(this); 482 String toString() {
floitsch 2013/07/08 12:00:50 The ListMixin does not redirect to the Workaround
zarah 2013/07/08 14:35:15 Done.
483 for(int i = 0; i < _toStringList.length; i++) {
484 if(identical(_toStringList[i], this))
485 return '[...]';
486 }
487 _toStringList.add(this);
488 String result = IterableMixinWorkaround.toStringList(this);
489 _toStringList.remove(this);
490 return result;
491 }
481 } 492 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698