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

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

Issue 13774006: Moving ListBase, FixedLengthListMixin and UmodifiableListMixin to collection. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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.dev; 5 part of dart._collection.dev;
6 6
7 /** 7 /**
8 * Base implementation of a [List] class. 8 * Base implementation of a [List] class.
9 * 9 *
10 * This class can be used as a mixin. 10 * This class can be used as a mixin.
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 throw new UnsupportedError( 612 throw new UnsupportedError(
613 "Cannot remove from an unmodifiable list"); 613 "Cannot remove from an unmodifiable list");
614 } 614 }
615 615
616 void insertRange(int start, int length, [E initialValue]) { 616 void insertRange(int start, int length, [E initialValue]) {
617 throw new UnsupportedError( 617 throw new UnsupportedError(
618 "Cannot insert range in an unmodifiable list"); 618 "Cannot insert range in an unmodifiable list");
619 } 619 }
620 } 620 }
621 621
622
623 /**
624 * Abstract implementation of a list.
625 *
626 * All operations are defined in terms of `length`, `operator[]`,
627 * `operator[]=` and `length=`, which need to be implemented.
628 */
629 abstract class ListBase<E> extends ListMixin<E> implements List<E> {}
630
631 /**
632 * Abstract implementation of a fixed-length list.
633 *
634 * All operations are defined in terms of `length`, `operator[]` and
635 * `operator[]=`, which need to be implemented.
636 */
637 abstract class FixedLengthListBase<E> extends ListBase<E>
638 with FixedLengthListMixin<E> {}
639
640 /**
641 * Abstract implementation of an unmodifiable list.
642 *
643 * All operations are defined in terms of `length` and `operator[]`,
644 * which need to be implemented.
645 */
646 abstract class UnmodifiableListBase<E> extends ListBase<E>
647 with UnmodifiableListMixin<E> {}
648
649 /** An empty fixed-length (and therefore unmodifiable) list. */
650 class EmptyList<E> extends FixedLengthListBase<E> {
651 int get length => 0;
652 E operator[](int index) { throw new RangeError.value(index); }
653 void operator []=(int index, E value) { throw new RangeError.value(index); }
654 Iterable<E> skip(int count) => const EmptyIterable();
655 Iterable<E> take(int count) => const EmptyIterable();
656 Iterable<E> get reversed => const EmptyIterable();
657 void sort([int compare(E a, E b)]) {}
658 }
659
660 class ReversedListIterable<E> extends ListIterable<E> { 622 class ReversedListIterable<E> extends ListIterable<E> {
661 Iterable<E> _source; 623 Iterable<E> _source;
662 ReversedListIterable(this._source); 624 ReversedListIterable(this._source);
663 625
664 int get length => _source.length; 626 int get length => _source.length;
665 627
666 E elementAt(int index) => _source.elementAt(_source.length - 1 - index); 628 E elementAt(int index) => _source.elementAt(_source.length - 1 - index);
667 } 629 }
668 630
669 /** 631 /**
670 * An [Iterable] of the UTF-16 code units of a [String] in index order. 632 * An [Iterable] of the UTF-16 code units of a [String] in index order.
671 */ 633 */
672 class CodeUnits extends UnmodifiableListBase<int> { 634 class CodeUnits extends ListMixin<int> with UnmodifiableListMixin<int> {
673 /** The string that this is the code units of. */ 635 /** The string that this is the code units of. */
674 String _string; 636 String _string;
675 637
676 CodeUnits(this._string); 638 CodeUnits(this._string);
677 639
678 int get length => _string.length; 640 int get length => _string.length;
679 int operator[](int i) => _string.codeUnitAt(i); 641 int operator[](int i) => _string.codeUnitAt(i);
680 } 642 }
681 643
682 class _ListIndicesIterable extends ListIterable<int> { 644 class _ListIndicesIterable extends ListIterable<int> {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 } 689 }
728 690
729 E remove(int key) { 691 E remove(int key) {
730 throw new UnsupportedError("Cannot modify an unmodifiable map"); 692 throw new UnsupportedError("Cannot modify an unmodifiable map");
731 } 693 }
732 694
733 void clear() { 695 void clear() {
734 throw new UnsupportedError("Cannot modify an unmodifiable map"); 696 throw new UnsupportedError("Cannot modify an unmodifiable map");
735 } 697 }
736 } 698 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698