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

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

Issue 18282008: Revert "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
« no previous file with comments | « sdk/lib/collection/linked_list.dart ('k') | sdk/lib/collection/maps.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // A list to identify cyclic lists during toString() calls.
32 static List _toStringList = new List();
33
34 // Iterable interface. 31 // Iterable interface.
35 Iterator<E> get iterator => new ListIterator<E>(this); 32 Iterator<E> get iterator => new ListIterator<E>(this);
36 33
37 E elementAt(int index) => this[index]; 34 E elementAt(int index) => this[index];
38 35
39 void forEach(void action(E element)) { 36 void forEach(void action(E element)) {
40 int length = this.length; 37 int length = this.length;
41 for (int i = 0; i < length; i++) { 38 for (int i = 0; i < length; i++) {
42 action(this[i]); 39 action(this[i]);
43 if (length != this.length) { 40 if (length != this.length) {
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 setRange(index, index + iterable.length, iterable); 470 setRange(index, index + iterable.length, iterable);
474 } else { 471 } else {
475 for (E element in iterable) { 472 for (E element in iterable) {
476 this[index++] = element; 473 this[index++] = element;
477 } 474 }
478 } 475 }
479 } 476 }
480 477
481 Iterable<E> get reversed => new ReversedListIterable(this); 478 Iterable<E> get reversed => new ReversedListIterable(this);
482 479
483 String toString() { 480 String toString() => ToString.iterableToString(this);
484 for (int i = 0; i < _toStringList.length; i++) {
485 if (identical(_toStringList[i], this)) { return '[...]'; }
486 }
487
488 var result = new StringBuffer();
489 try {
490 _toStringList.add(this);
491 result.write('[');
492 result.writeAll(this, ', ');
493 result.write(']');
494 } finally {
495 assert(identical(_toStringList.last, this));
496 _toStringList.removeLast();
497 }
498
499 return result.toString();
500 }
501 } 481 }
OLDNEW
« no previous file with comments | « sdk/lib/collection/linked_list.dart ('k') | sdk/lib/collection/maps.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698