Chromium Code Reviews| Index: lib/src/set_group.dart |
| diff --git a/lib/src/set_group.dart b/lib/src/set_group.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f647d08eba5909860d639d16ba281aeefaf208ad |
| --- /dev/null |
| +++ b/lib/src/set_group.dart |
| @@ -0,0 +1,38 @@ |
| +// 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 'group_set.dart'; |
| +import 'wrappers.dart'; |
| + |
| +/// A set of sets that provides [set], a view of the union of those sets. |
| +/// |
| +/// This is a convenience class for creating a [GroupSet] whose contents change |
| +/// over the lifetime of a class. For example: |
| +/// |
| +/// ```dart |
| +/// class Engine { |
| +/// Set<Test> get activeTests => _activeTestsGroup.set; |
| +/// final _activeTestsGroup = new SetGroup<Test>(); |
| +/// |
| +/// void addSuite(Suite suite) { |
| +/// _activeTestsGroup.add(suite.tests); |
| +/// _runSuite(suite); |
| +/// _activeTestsGroup.remove(suite.tests); |
| +/// } |
| +/// } |
| +/// ``` |
| +class SetGroup<E> extends DelegatingSet<Set<E>> { |
|
Lasse Reichstein Nielsen
2016/04/23 09:00:47
I do think I'd prefer this class to not be a Set.
floitsch
2016/04/25 16:11:10
Do we even need this class?
I see two ways to avo
nweiz
2016/04/26 21:23:53
Done.
floitsch
2016/04/27 10:56:52
Why?
It's like saying that users expecting an "Ite
Lasse Reichstein Nielsen
2016/04/27 12:17:53
I generally recommend not extending the well-known
floitsch
2016/04/27 12:31:20
I'm not convinced.
A UnionSet supports adding comp
Lasse Reichstein Nielsen
2016/04/27 12:47:00
The GroupSet is just a Set at the interface level.
floitsch
2016/04/27 13:08:47
If that's really necessary, yes. That's how it wor
Lasse Reichstein Nielsen
2016/04/27 14:31:15
I think our difference is mainly in perspective. I
nweiz
2016/04/27 20:47:40
The intent was definitely a view that looks like a
|
| + /// The [GroupSet] that provides a view of the union of sets in [this]. |
| + GroupSet<E> get set => _set; |
| + GroupSet<E> _set; |
|
floitsch
2016/04/25 16:11:10
This should be final.
nweiz
2016/04/26 21:23:53
Unfortunately it can't be; GroupSet's initializer
floitsch
2016/04/27 10:56:52
True. It was, but isn't anymore.
Looking more at
nweiz
2016/04/27 20:47:40
Allowing a UnionSet to be directly based on an exi
Lasse Reichstein Nielsen
2016/04/27 21:03:30
Allowing a UnionSet to be directly based on an exi
nweiz
2016/05/03 01:05:36
Right now it's the former: a class that exposes a
Lasse Reichstein Nielsen
2016/05/03 08:27:13
Yes, so I'm good too :)
|
| + |
| + /// 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 |
| + /// many operations including [length] more efficient. |
| + SetGroup({bool disjoint: false}) : super(new Set<Set<E>>()) { |
| + _set = new GroupSet<E>(this, disjoint: disjoint); |
| + } |
| +} |