- public Ref() { }
- public void merge(Forest p) { if (p!=this) hp.add(p, true); }
- public <B,C> void invoke(Invokable<Forest.Body<T>,B,C> ivbc, B b, C c) {
- for(Forest.Body<T> bod : this)
- ivbc.invoke(bod, b, c);
- }
- public Iterator<Body<T>> iterator() {
- final Iterator<Forest<T>> ift = hp==null ? null : hp.iterator();
- return new Iterator<Body<T>>() {
- Iterator<Body<T>> ibt = ift==null ? null : ift.hasNext() ? ift.next().iterator() : null;
- public void remove() { throw new RuntimeException("not supported"); }
- public boolean hasNext() {
- if (ibt==null) return false;
- if (ibt.hasNext()) return true;
- ibt = ift.hasNext() ? ift.next().iterator() : null;
- return hasNext();
- }
- public Body<T> next() {
- return ibt.next();
+ private boolean touched = false;
+
+ public Many() { }
+
+ public Tree<T> expand1() throws Ambiguous {
+ touched();
+ if (hp.size() > 1) {
+ HashSet<Forest<T>> hf0 = new HashSet<Forest<T>>();
+ Iterator<Forest<T>> ih = hp.iterator();
+ ih.next().gather(hf0);
+ for(Forest<T> f : hp) {
+ HashSet<Forest<T>> hf1 = new HashSet<Forest<T>>();
+ f.gather(hf1);
+ hf0.retainAll(hf1);