- private HashSet<E> left = new HashSet<E>();
- private HashSet<E> right = new HashSet<E>();
- public BindingGroup() { }
- public BindingGroup(E e) { add(e, false); }
- public void add(E e, boolean swap) {
- if (e.bg != null) {
- if (e.bg == this) return; /* fixme what if it is in the "other" set? */
- for(E ex : (!swap ? e.bg.left : e.bg.right)) {
- ex.bg = this;
- left.add(ex);
- }
- for(E ex : (!swap ? e.bg.right : e.bg.left)) {
- ex.bg = this;
- right.add(ex);
- }
-
- } else {
- (!swap ? left : right).add(e);
- e.bg = this;
+ private HashSet<E> set = new HashSet<E>();
+ public BindingGroup bind_others;
+ public BindingGroup other() { return bind_others; }
+ public BindingGroup(BindingGroup bind_others) { this.bind_others = bind_others; }
+ public BindingGroup() { this.bind_others = new BindingGroup(this); }
+ public BindingGroup(E e) { this(); set.add(e); }
+ public void add(E e) {
+ if (set.contains(e)) return;
+ for (E epeer : e.bind_peers.set) {
+ epeer.bind_peers = this;
+ epeer.bind_to = bind_others;
+ set.add(epeer);
+ }
+ for (E eother : e.bind_to.set) {
+ bind_others.add(eother);