Chromium Code Reviews| Index: lib/src/union_set_controller.dart |
| diff --git a/lib/src/union_set_controller.dart b/lib/src/union_set_controller.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1d0eb743185ee693248ed3baf5e1a17bd2b3f621 |
| --- /dev/null |
| +++ b/lib/src/union_set_controller.dart |
| @@ -0,0 +1,54 @@ |
| +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +import 'union_set.dart'; |
| + |
| +/// A controller that exposes a view of the union of a collection of sets. |
| +/// |
| +/// This is a convenience class for creating a [UnionSet] whose contents change |
| +/// over the lifetime of a class. For example: |
| +/// |
| +/// ```dart |
| +/// class Engine { |
| +/// Set<Test> get activeTests => _activeTestsGroup.set; |
| +/// final _activeTestsGroup = new UnionSetController<Test>(); |
| +/// |
| +/// void addSuite(Suite suite) { |
| +/// _activeTestsGroup.add(suite.tests); |
| +/// _runSuite(suite); |
| +/// _activeTestsGroup.remove(suite.tests); |
| +/// } |
| +/// } |
| +/// ``` |
| +class UnionSetController<E> { |
| + /// The [UnionSet] that provides a view of the union of sets in [this]. |
| + UnionSet<E> get set => _set; |
| + UnionSet<E> _set; |
| + |
| + /// The sets whose union is exposed through [set]. |
| + final _sets = new Set<Set<E>>(); |
| + |
| + /// Creates a set of sets that provides a view of the union of those sets. |
| + /// |
| + /// If [disjoint] is `true`, this assumes that all component sets are |
| + /// disjoint—that is, that they contain no elements in common. This makes |
|
floitsch
2016/04/27 10:56:52
Please don't use non-ascii characters.
Commonmark
nweiz
2016/04/27 20:47:40
See my other comment. This rule isn't part of the
floitsch
2016/05/09 13:19:18
Forgot to answer that one: having non-Ascii tokens
|
| + /// many operations including [length] more efficient. |
| + UnionSetController({bool disjoint: false}) { |
| + _set = new UnionSet<E>(_sets, disjoint: disjoint); |
| + } |
| + |
| + /// Adds the contents of [component] to [set]. |
| + /// |
| + /// If the contents of [component] change over time, [set] will change |
| + /// accordingly. |
| + void add(Set<E> component) { |
| + _sets.add(component); |
| + } |
| + |
| + /// Removes the contents of [component] to [set]. |
| + /// |
| + /// If another set in [this] has overlapping elements with [component], those |
| + /// elements will remain in [set]. |
| + bool remove(Set<E> component) => _sets.remove(component); |
| +} |