| OLD | NEW |
| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 if (length == 0) throw new StateError("No elements"); | 56 if (length == 0) throw new StateError("No elements"); |
| 57 return this[length - 1]; | 57 return this[length - 1]; |
| 58 } | 58 } |
| 59 | 59 |
| 60 E get single { | 60 E get single { |
| 61 if (length == 0) throw new StateError("No elements"); | 61 if (length == 0) throw new StateError("No elements"); |
| 62 if (length > 1) throw new StateError("Too many elements"); | 62 if (length > 1) throw new StateError("Too many elements"); |
| 63 return this[0]; | 63 return this[0]; |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool contains(E element) { | 66 bool contains(Object element) { |
| 67 int length = this.length; | 67 int length = this.length; |
| 68 for (int i = 0; i < length; i++) { | 68 for (int i = 0; i < length; i++) { |
| 69 if (this[i] == element) return true; | 69 if (this[i] == element) return true; |
| 70 if (length != this.length) { | 70 if (length != this.length) { |
| 71 throw new ConcurrentModificationError(this); | 71 throw new ConcurrentModificationError(this); |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 return false; | 74 return false; |
| 75 } | 75 } |
| 76 | 76 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 89 int length = this.length; | 89 int length = this.length; |
| 90 for (int i = 0; i < length; i++) { | 90 for (int i = 0; i < length; i++) { |
| 91 if (test(this[i])) return true; | 91 if (test(this[i])) return true; |
| 92 if (length != this.length) { | 92 if (length != this.length) { |
| 93 throw new ConcurrentModificationError(this); | 93 throw new ConcurrentModificationError(this); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 return false; | 96 return false; |
| 97 } | 97 } |
| 98 | 98 |
| 99 E firstWhere(bool test(E element), { E orElse() }) { | 99 dynamic firstWhere(bool test(E element), { Object orElse() }) { |
| 100 int length = this.length; | 100 int length = this.length; |
| 101 for (int i = 0; i < length; i++) { | 101 for (int i = 0; i < length; i++) { |
| 102 E element = this[i]; | 102 E element = this[i]; |
| 103 if (test(element)) return element; | 103 if (test(element)) return element; |
| 104 if (length != this.length) { | 104 if (length != this.length) { |
| 105 throw new ConcurrentModificationError(this); | 105 throw new ConcurrentModificationError(this); |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 if (orElse != null) return orElse(); | 108 if (orElse != null) return orElse(); |
| 109 throw new StateError("No matching element"); | 109 throw new StateError("No matching element"); |
| 110 } | 110 } |
| 111 | 111 |
| 112 E lastWhere(bool test(E element), { E orElse() }) { | 112 dynamic lastWhere(bool test(E element), { Object orElse() }) { |
| 113 int length = this.length; | 113 int length = this.length; |
| 114 for (int i = length - 1; i >= 0; i--) { | 114 for (int i = length - 1; i >= 0; i--) { |
| 115 E element = this[i]; | 115 E element = this[i]; |
| 116 if (test(element)) return element; | 116 if (test(element)) return element; |
| 117 if (length != this.length) { | 117 if (length != this.length) { |
| 118 throw new ConcurrentModificationError(this); | 118 throw new ConcurrentModificationError(this); |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 if (orElse != null) return orElse(); | 121 if (orElse != null) return orElse(); |
| 122 throw new StateError("No matching element"); | 122 throw new StateError("No matching element"); |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 } | 378 } |
| 379 } | 379 } |
| 380 } | 380 } |
| 381 | 381 |
| 382 void replaceRange(int start, int end, Iterable<E> newContents) { | 382 void replaceRange(int start, int end, Iterable<E> newContents) { |
| 383 // TODO(floitsch): Optimize this. | 383 // TODO(floitsch): Optimize this. |
| 384 removeRange(start, end); | 384 removeRange(start, end); |
| 385 insertAll(start, newContents); | 385 insertAll(start, newContents); |
| 386 } | 386 } |
| 387 | 387 |
| 388 int indexOf(E element, [int startIndex = 0]) { | 388 int indexOf(Object element, [int startIndex = 0]) { |
| 389 if (startIndex >= this.length) { | 389 if (startIndex >= this.length) { |
| 390 return -1; | 390 return -1; |
| 391 } | 391 } |
| 392 if (startIndex < 0) { | 392 if (startIndex < 0) { |
| 393 startIndex = 0; | 393 startIndex = 0; |
| 394 } | 394 } |
| 395 for (int i = startIndex; i < this.length; i++) { | 395 for (int i = startIndex; i < this.length; i++) { |
| 396 if (this[i] == element) { | 396 if (this[i] == element) { |
| 397 return i; | 397 return i; |
| 398 } | 398 } |
| 399 } | 399 } |
| 400 return -1; | 400 return -1; |
| 401 } | 401 } |
| 402 | 402 |
| 403 /** | 403 /** |
| 404 * Returns the last index in the list [a] of the given [element], starting | 404 * Returns the last index in the list [a] of the given [element], starting |
| 405 * the search at index [startIndex] to 0. | 405 * the search at index [startIndex] to 0. |
| 406 * Returns -1 if [element] is not found. | 406 * Returns -1 if [element] is not found. |
| 407 */ | 407 */ |
| 408 int lastIndexOf(E element, [int startIndex]) { | 408 int lastIndexOf(Object element, [int startIndex]) { |
| 409 if (startIndex == null) { | 409 if (startIndex == null) { |
| 410 startIndex = this.length - 1; | 410 startIndex = this.length - 1; |
| 411 } else { | 411 } else { |
| 412 if (startIndex < 0) { | 412 if (startIndex < 0) { |
| 413 return -1; | 413 return -1; |
| 414 } | 414 } |
| 415 if (startIndex >= this.length) { | 415 if (startIndex >= this.length) { |
| 416 startIndex = this.length - 1; | 416 startIndex = this.length - 1; |
| 417 } | 417 } |
| 418 } | 418 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 for (E element in iterable) { | 472 for (E element in iterable) { |
| 473 this[index++] = element; | 473 this[index++] = element; |
| 474 } | 474 } |
| 475 } | 475 } |
| 476 } | 476 } |
| 477 | 477 |
| 478 Iterable<E> get reversed => new ReversedListIterable(this); | 478 Iterable<E> get reversed => new ReversedListIterable(this); |
| 479 | 479 |
| 480 String toString() => ToString.iterableToString(this); | 480 String toString() => ToString.iterableToString(this); |
| 481 } | 481 } |
| OLD | NEW |