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 /** |
11 * Mixin implementation of [Set]. | 11 * Mixin implementation of [Set]. |
12 * | 12 * |
13 * This class provides a base implementation of a `Set` that depends only | 13 * This class provides a base implementation of a `Set` that depends only |
14 * on the abstract members: [add], [contains], [lookup], [remove], | 14 * on the abstract members: [add], [contains], [lookup], [remove], |
15 * [iterator], [length] and [toSet]. | 15 * [iterator], [length] and [toSet]. |
16 * | 16 * |
17 * Some of the methods assume that `toSet` creates a modifiable set. | 17 * Some of the methods assume that `toSet` creates a modifiable set. |
18 * If using this mixin for an unmodifiable set, | 18 * If using this mixin for an unmodifiable set, |
19 * where `toSet` should return an unmodifiable set, | 19 * where `toSet` should return an unmodifiable set, |
20 * it's necessary to reimplement | 20 * it's necessary to reimplement |
21 * [retainAll], [union], [intersection] and [difference]. | 21 * [retainAll], [union], [intersection] and [difference]. |
22 * | 22 * |
23 * Implementations of `Set` using this mixin should consider also implementing | 23 * Implementations of `Set` using this mixin should consider also implementing |
24 * `clear` in constant time. The default implementation works by removing every | 24 * `clear` in constant time. The default implementation works by removing every |
25 * element. | 25 * element. |
26 */ | 26 */ |
27 abstract class SetMixin<E> implements Set<E> { | 27 abstract class SetMixin<E> implements Set<E> { |
28 // This class reimplements all of [IterableMixin]. | 28 // This class reimplements all of [IterableMixin]. |
29 // If/when Dart mixins get more powerful, we should just create a single | 29 // If/when Dart mixins get more powerful, we should just create a single |
30 // Mixin class from IterableMixin and the new methods of thisclass. | 30 // Mixin class from IterableMixin and the new methods of this class. |
31 | 31 |
32 bool add(E element); | 32 bool add(E element); |
33 | 33 |
34 bool contains(Object element); | 34 bool contains(Object element); |
35 | 35 |
36 E lookup(Object element); | 36 E lookup(Object element); |
37 | 37 |
38 bool remove(Object element); | 38 bool remove(Object element); |
39 | 39 |
40 Iterator<E> get iterator; | 40 Iterator<E> get iterator; |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 abstract class SetBase<E> extends SetMixin<E> { | 302 abstract class SetBase<E> extends SetMixin<E> { |
303 /** | 303 /** |
304 * Convert a `Set` to a string as `{each, element, as, string}`. | 304 * Convert a `Set` to a string as `{each, element, as, string}`. |
305 * | 305 * |
306 * Handles circular references where converting one of the elements | 306 * Handles circular references where converting one of the elements |
307 * to a string ends up converting [set] to a string again. | 307 * to a string ends up converting [set] to a string again. |
308 */ | 308 */ |
309 static String setToString(Set set) => | 309 static String setToString(Set set) => |
310 IterableBase.iterableToFullString(set, '{', '}'); | 310 IterableBase.iterableToFullString(set, '{', '}'); |
311 } | 311 } |
OLD | NEW |