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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 } | 82 } |
83 | 83 |
84 E get single { | 84 E get single { |
85 if (length == 0) throw IterableElementError.noElement(); | 85 if (length == 0) throw IterableElementError.noElement(); |
86 if (length > 1) throw IterableElementError.tooMany(); | 86 if (length > 1) throw IterableElementError.tooMany(); |
87 return this[0]; | 87 return this[0]; |
88 } | 88 } |
89 | 89 |
90 bool contains(Object element) { | 90 bool contains(Object element) { |
91 int length = this.length; | 91 int length = this.length; |
92 for (int i = 0; i < this.length; i++) { | 92 for (int i = 0; i < length; i++) { |
93 if (this[i] == element) return true; | 93 if (this[i] == element) return true; |
94 if (length != this.length) { | 94 if (length != this.length) { |
95 throw new ConcurrentModificationError(this); | 95 throw new ConcurrentModificationError(this); |
96 } | 96 } |
97 } | 97 } |
98 return false; | 98 return false; |
99 } | 99 } |
100 | 100 |
101 bool every(bool test(E element)) { | 101 bool every(bool test(E element)) { |
102 int length = this.length; | 102 int length = this.length; |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 for (E element in iterable) { | 511 for (E element in iterable) { |
512 this[index++] = element; | 512 this[index++] = element; |
513 } | 513 } |
514 } | 514 } |
515 } | 515 } |
516 | 516 |
517 Iterable<E> get reversed => new ReversedListIterable<E>(this); | 517 Iterable<E> get reversed => new ReversedListIterable<E>(this); |
518 | 518 |
519 String toString() => IterableBase.iterableToFullString(this, '[', ']'); | 519 String toString() => IterableBase.iterableToFullString(this, '[', ']'); |
520 } | 520 } |
OLD | NEW |