checkpoint
[sbp.git] / src / edu / berkeley / sbp / Forest.java
index 7fde86e..e53bfcb 100644 (file)
@@ -127,7 +127,20 @@ public abstract class Forest<T> /*extends PrintableTree<Forest.Body<T>>*/
         public Ref() { }
 
         public Tree<T> expand1() throws Ambiguous {
-            if (hp.size() > 1) throw new Ambiguous(this);
+            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);
+                }
+                HashSet<Tree<T>> ht = new HashSet<Tree<T>>();
+                expand(ht, hf0, new Tree(null, "*"));
+                throw new Ambiguous((Forest<?>)this,
+                                    (HashSet<Tree<?>>)(Object)ht);
+            }
             return hp.iterator().next().expand1();
         }