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

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

Issue 14425003: Make List.remove return boolean. (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; 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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 void add(E element) { 235 void add(E element) {
236 this[this.length++] = element; 236 this[this.length++] = element;
237 } 237 }
238 238
239 void addAll(Iterable<E> iterable) { 239 void addAll(Iterable<E> iterable) {
240 for (E element in iterable) { 240 for (E element in iterable) {
241 this[this.length++] = element; 241 this[this.length++] = element;
242 } 242 }
243 } 243 }
244 244
245 void remove(Object element) { 245 bool remove(Object element) {
246 for (int i = 0; i < this.length; i++) { 246 for (int i = 0; i < this.length; i++) {
247 if (this[i] == element) { 247 if (this[i] == element) {
248 this.setRange(i, i + this.length - 1, this, i + 1); 248 this.setRange(i, this.length - 1, this, i + 1);
249 this.length -= 1; 249 this.length -= 1;
250 return; 250 return true;
251 } 251 }
252 } 252 }
253 return false;
253 } 254 }
254 255
255 void removeWhere(bool test(E element)) { 256 void removeWhere(bool test(E element)) {
256 _filter(this, test, false); 257 _filter(this, test, false);
257 } 258 }
258 259
259 void retainWhere(bool test(E element)) { 260 void retainWhere(bool test(E element)) {
260 _filter(this, test, true); 261 _filter(this, test, true);
261 } 262 }
262 263
(...skipping 24 matching lines...) Expand all
287 E removeLast() { 288 E removeLast() {
288 if (length == 0) { 289 if (length == 0) {
289 throw new StateError("No elements"); 290 throw new StateError("No elements");
290 } 291 }
291 E result = this[length - 1]; 292 E result = this[length - 1];
292 length--; 293 length--;
293 return result; 294 return result;
294 } 295 }
295 296
296 void sort([Comparator<E> compare]) { 297 void sort([Comparator<E> compare]) {
298 if (compare == null) compare = Comparable.compare;
297 Sort.sort(this, compare); 299 Sort.sort(this, compare);
298 } 300 }
299 301
300 Map<int, E> asMap() { 302 Map<int, E> asMap() {
301 return new ListMapView(this); 303 return new ListMapView(this);
302 } 304 }
303 305
304 void _rangeCheck(int start, int end) { 306 void _rangeCheck(int start, int end) {
305 if (start < 0 || start > this.length) { 307 if (start < 0 || start > this.length) {
306 throw new RangeError.range(start, 0, this.length); 308 throw new RangeError.range(start, 0, this.length);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 for (E element in iterable) { 467 for (E element in iterable) {
466 this[index++] = element; 468 this[index++] = element;
467 } 469 }
468 } 470 }
469 } 471 }
470 472
471 Iterable<E> get reversed => new ReversedListIterable(this); 473 Iterable<E> get reversed => new ReversedListIterable(this);
472 474
473 String toString() => ToString.iterableToString(this); 475 String toString() => ToString.iterableToString(this);
474 } 476 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/lib/js_array.dart ('k') | sdk/lib/collection/queue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698