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 * `ListBase` can be used as a base class for implementing the `List` interface. | 10 * `ListBase` can be used as a base class for implementing the `List` interface. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 int length = this.length; | 113 int length = this.length; |
114 for (int i = 0; i < length; i++) { | 114 for (int i = 0; i < length; i++) { |
115 if (test(this[i])) return true; | 115 if (test(this[i])) return true; |
116 if (length != this.length) { | 116 if (length != this.length) { |
117 throw new ConcurrentModificationError(this); | 117 throw new ConcurrentModificationError(this); |
118 } | 118 } |
119 } | 119 } |
120 return false; | 120 return false; |
121 } | 121 } |
122 | 122 |
123 dynamic firstWhere(bool test(E element), { Object orElse() }) { | 123 E firstWhere(bool test(E element), { E orElse() }) { |
124 int length = this.length; | 124 int length = this.length; |
125 for (int i = 0; i < length; i++) { | 125 for (int i = 0; i < length; i++) { |
126 E element = this[i]; | 126 E element = this[i]; |
127 if (test(element)) return element; | 127 if (test(element)) return element; |
128 if (length != this.length) { | 128 if (length != this.length) { |
129 throw new ConcurrentModificationError(this); | 129 throw new ConcurrentModificationError(this); |
130 } | 130 } |
131 } | 131 } |
132 if (orElse != null) return orElse(); | 132 if (orElse != null) return orElse(); |
133 throw IterableElementError.noElement(); | 133 throw IterableElementError.noElement(); |
134 } | 134 } |
135 | 135 |
136 dynamic lastWhere(bool test(E element), { Object orElse() }) { | 136 E lastWhere(bool test(E element), { E orElse() }) { |
137 int length = this.length; | 137 int length = this.length; |
138 for (int i = length - 1; i >= 0; i--) { | 138 for (int i = length - 1; i >= 0; i--) { |
139 E element = this[i]; | 139 E element = this[i]; |
140 if (test(element)) return element; | 140 if (test(element)) return element; |
141 if (length != this.length) { | 141 if (length != this.length) { |
142 throw new ConcurrentModificationError(this); | 142 throw new ConcurrentModificationError(this); |
143 } | 143 } |
144 } | 144 } |
145 if (orElse != null) return orElse(); | 145 if (orElse != null) return orElse(); |
146 throw IterableElementError.noElement(); | 146 throw IterableElementError.noElement(); |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 for (E element in iterable) { | 495 for (E element in iterable) { |
496 this[index++] = element; | 496 this[index++] = element; |
497 } | 497 } |
498 } | 498 } |
499 } | 499 } |
500 | 500 |
501 Iterable<E> get reversed => new ReversedListIterable<E>(this); | 501 Iterable<E> get reversed => new ReversedListIterable<E>(this); |
502 | 502 |
503 String toString() => IterableBase.iterableToFullString(this, '[', ']'); | 503 String toString() => IterableBase.iterableToFullString(this, '[', ']'); |
504 } | 504 } |
OLD | NEW |