OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /** | 5 /** |
6 * Base implementations of [Set]. | 6 * Base implementations of [Set]. |
7 */ | 7 */ |
8 part of dart.collection; | 8 part of dart.collection; |
9 | 9 |
10 /** | 10 /** |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 new EfficientLengthMappedIterable<E, dynamic>(this, f); | 124 new EfficientLengthMappedIterable<E, dynamic>(this, f); |
125 | 125 |
126 E get single { | 126 E get single { |
127 if (length > 1) throw IterableElementError.tooMany(); | 127 if (length > 1) throw IterableElementError.tooMany(); |
128 Iterator it = iterator; | 128 Iterator it = iterator; |
129 if (!it.moveNext()) throw IterableElementError.noElement(); | 129 if (!it.moveNext()) throw IterableElementError.noElement(); |
130 E result = it.current; | 130 E result = it.current; |
131 return result; | 131 return result; |
132 } | 132 } |
133 | 133 |
134 String toString() => _setToString(this); | 134 String toString() => IterableBase.iterableToFullString(this, '{', '}'); |
135 | 135 |
136 // Copied from IterableMixin. | 136 // Copied from IterableMixin. |
137 // Should be inherited if we had multi-level mixins. | 137 // Should be inherited if we had multi-level mixins. |
138 | 138 |
139 Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f); | 139 Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f); |
140 | 140 |
141 Iterable expand(Iterable f(E element)) => | 141 Iterable expand(Iterable f(E element)) => |
142 new ExpandIterable<E, dynamic>(this, f); | 142 new ExpandIterable<E, dynamic>(this, f); |
143 | 143 |
144 void forEach(void f(E element)) { | 144 void forEach(void f(E element)) { |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 * Some of the methods assume that `toSet` creates a modifiable set. | 291 * Some of the methods assume that `toSet` creates a modifiable set. |
292 * If using this base class for an unmodifiable set, | 292 * If using this base class for an unmodifiable set, |
293 * where `toSet` should return an unmodifiable set, | 293 * where `toSet` should return an unmodifiable set, |
294 * it's necessary to reimplement | 294 * it's necessary to reimplement |
295 * [retainAll], [union], [intersection] and [difference]. | 295 * [retainAll], [union], [intersection] and [difference]. |
296 * | 296 * |
297 * Implementations of `Set` using this base should consider also implementing | 297 * Implementations of `Set` using this base should consider also implementing |
298 * `clear` in constant time. The default implementation works by removing every | 298 * `clear` in constant time. The default implementation works by removing every |
299 * element. | 299 * element. |
300 */ | 300 */ |
301 abstract class SetBase<E> = Object with SetMixin<E>; | 301 abstract class SetBase<E> extends SetMixin<E> { |
| 302 /** |
| 303 * Convert a `Set` to a string as `{each, element, as, string}`. |
| 304 * |
| 305 * Handles circular references where converting one of the elements |
| 306 * to a string ends up converting [set] to a string again. |
| 307 */ |
| 308 static String setToString(Set set) => |
| 309 IterableBase.iterableToFullString(set, '{', '}'); |
| 310 } |
OLD | NEW |