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

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

Issue 12380086: Implement missing functions on ListBase. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase after revert. Created 7 years, 9 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 | « no previous file | tests/corelib/corelib.status » ('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.dev; 5 part of dart._collection.dev;
6 6
7 /** 7 /**
8 * Class implementing the read-operations on [List]. 8 * Class implementing the read-operations on [List].
9 * 9 *
10 * Implements all read-only operations, except [:operator[]:] and [:length:], 10 * Implements all read-only operations, except [:operator[]:] and [:length:],
11 * in terms of those two operations. 11 * in terms of those two operations.
12 */ 12 */
13 abstract class ListBase<E> extends ListIterable<E> implements List<E> { 13 abstract class ListBase<E> extends ListIterable<E> implements List<E> {
14 // List interface. 14 // List interface.
15 int get length; 15 int get length;
16 E operator[](int index); 16 E operator[](int index);
17 17
18 // Collection interface. 18 // Collection interface.
19 // Implement in a fully mutable specialized class if necessary. 19 // Implement in a fully mutable specialized class if necessary.
20 // The fixed-length and unmodifiable lists throw on all members 20 // The fixed-length and unmodifiable lists throw on all members
21 // of the collection interface. 21 // of the collection interface.
22 22
23 // Iterable interface. 23 // Iterable interface.
24 E elementAt(int index) { 24 E elementAt(int index) {
25 return this[index]; 25 return this[index];
26 } 26 }
27
27 Map<int, E> asMap() { 28 Map<int, E> asMap() {
28 return new ListMapView(this); 29 return new ListMapView(this);
29 } 30 }
30 31
32 List<E> getRange(int start, int length) {
33 if (start < 0 || start > this.length) {
34 throw new RangeError.range(start, 0, this.length);
35 }
36 if (length < 0 || start + length > this.length) {
37 throw new RangeError.range(length, 0, this.length - start);
38 }
39 List<E> result = new List<E>(length);
40 for (int i = 0; i < length; i++) {
41 result[i] = this[start + i];
42 }
43 return result;
44 }
45
46 int indexOf(E element, [int start = 0]) {
47 return Arrays.indexOf(this, element, start, this.length);
48 }
49
50 int lastIndexOf(E element, [int start = null]) {
51 if (start == null) start = length - 1;
52 return Arrays.lastIndexOf(this, element, start);
53 }
54
55 Iterable<E> get reversed => new ReversedListIterable(this);
31 } 56 }
32 57
33 /** 58 /**
34 * Abstract class implementing the non-length changing operations of [List]. 59 * Abstract class implementing the non-length changing operations of [List].
35 * 60 *
36 * All modifications are performed using [[]=]. 61 * All modifications are performed using [[]=].
37 */ 62 */
38 abstract class FixedLengthListBase<E> extends ListBase<E> { 63 abstract class FixedLengthListBase<E> extends ListBase<E> {
39 void operator[]=(int index, E value); 64 void operator[]=(int index, E value);
40 65
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 void retainAll(Iterable elements) { 108 void retainAll(Iterable elements) {
84 throw new UnsupportedError( 109 throw new UnsupportedError(
85 "Cannot remove from a fixed-length list"); 110 "Cannot remove from a fixed-length list");
86 } 111 }
87 112
88 void removeMatching(bool test(E element)) { 113 void removeMatching(bool test(E element)) {
89 throw new UnsupportedError( 114 throw new UnsupportedError(
90 "Cannot remove from a fixed-length list"); 115 "Cannot remove from a fixed-length list");
91 } 116 }
92 117
118 void retainMatching(bool test(E element)) {
119 throw new UnsupportedError(
120 "Cannot remove from a fixed-length list");
121 }
122
93 void clear() { 123 void clear() {
94 throw new UnsupportedError( 124 throw new UnsupportedError(
95 "Cannot clear a fixed-length list"); 125 "Cannot clear a fixed-length list");
96 } 126 }
97 127
98 E removeAt(int index) { 128 E removeAt(int index) {
99 throw new UnsupportedError( 129 throw new UnsupportedError(
100 "Cannot remove from a fixed-length list"); 130 "Cannot remove from a fixed-length list");
101 } 131 }
102 132
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 void retainAll(Iterable elements) { 189 void retainAll(Iterable elements) {
160 throw new UnsupportedError( 190 throw new UnsupportedError(
161 "Cannot remove from an unmodifiable list"); 191 "Cannot remove from an unmodifiable list");
162 } 192 }
163 193
164 void removeMatching(bool test(E element)) { 194 void removeMatching(bool test(E element)) {
165 throw new UnsupportedError( 195 throw new UnsupportedError(
166 "Cannot remove from an unmodifiable list"); 196 "Cannot remove from an unmodifiable list");
167 } 197 }
168 198
199 void retainMatching(bool test(E element)) {
200 throw new UnsupportedError(
201 "Cannot remove from an unmodifiable list");
202 }
203
169 void sort([Comparator<E> compare]) { 204 void sort([Comparator<E> compare]) {
170 throw new UnsupportedError( 205 throw new UnsupportedError(
171 "Cannot modify an unmodifiable list"); 206 "Cannot modify an unmodifiable list");
172 } 207 }
173 208
174 void clear() { 209 void clear() {
175 throw new UnsupportedError( 210 throw new UnsupportedError(
176 "Cannot clear an unmodifiable list"); 211 "Cannot clear an unmodifiable list");
177 } 212 }
178 213
(...skipping 14 matching lines...) Expand all
193 228
194 void removeRange(int start, int length) { 229 void removeRange(int start, int length) {
195 throw new UnsupportedError( 230 throw new UnsupportedError(
196 "Cannot remove from an unmodifiable list"); 231 "Cannot remove from an unmodifiable list");
197 } 232 }
198 233
199 void insertRange(int start, int length, [E initialValue]) { 234 void insertRange(int start, int length, [E initialValue]) {
200 throw new UnsupportedError( 235 throw new UnsupportedError(
201 "Cannot insert range in an unmodifiable list"); 236 "Cannot insert range in an unmodifiable list");
202 } 237 }
203
204 List<E> getRange(int start, int length) {
205 if (start < 0 || start > this.length) {
206 throw new RangeError.range(start, 0, this.length);
207 }
208 if (length < 0 || start + length > this.length) {
209 throw new RangeError.range(length, 0, this.length - start);
210 }
211 List<E> result = new List<E>(length);
212 for (int i = 0; i < length; i++) {
213 result[i] = this[start + i];
214 }
215 return result;
216 }
217 } 238 }
218 239
219 /** An empty fixed-length list. */ 240 /** An empty fixed-length list. */
220 class EmptyList<E> extends FixedLengthListBase<E> { 241 class EmptyList<E> extends FixedLengthListBase<E> {
221 int get length => 0; 242 int get length => 0;
222 E operator[](int index) { throw new RangeError.value(index); } 243 E operator[](int index) { throw new RangeError.value(index); }
223 void operator []=(int index, E value) { throw new RangeError.value(index); } 244 void operator []=(int index, E value) { throw new RangeError.value(index); }
224 Iterable<E> skip(int count) => const EmptyIterable(); 245 Iterable<E> skip(int count) => const EmptyIterable();
225 Iterable<E> take(int count) => const EmptyIterable(); 246 Iterable<E> take(int count) => const EmptyIterable();
226 Iterable<E> get reversed => const EmptyIterable(); 247 Iterable<E> get reversed => const EmptyIterable();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 } 316 }
296 317
297 E remove(int key) { 318 E remove(int key) {
298 throw new UnsupportedError("Cannot modify an unmodifiable map"); 319 throw new UnsupportedError("Cannot modify an unmodifiable map");
299 } 320 }
300 321
301 void clear() { 322 void clear() {
302 throw new UnsupportedError("Cannot modify an unmodifiable map"); 323 throw new UnsupportedError("Cannot modify an unmodifiable map");
303 } 324 }
304 } 325 }
OLDNEW
« no previous file with comments | « no previous file | tests/corelib/corelib.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698