/** expand this forest into a set of trees */
public HashSet<Tree<T>> expand(boolean toss) {
- TreeMaker<T> ret = new TreeMaker<T>(toss);
+ final HashSet<Tree<T>> hs = new HashSet<Tree<T>>();
+ TreeMaker<T> ret = new TreeMaker<T>(toss) {
+ public void add(Tree<T> t) { hs.add(t); }
+ };
visit(ret, null, null);
- if (toss && ret.size() > 1) throw new Ambiguous(this);
- return ret;
+ if (toss && hs.size() > 1) throw new Ambiguous(this);
+ return hs;
}
static <T> Forest<T> singleton(Input.Location loc) { return create(loc, null, new Forest[] { }, false, true); }
}
public abstract <B,C> void visit(Invokable<Forest.Body<T>,B,C> ivbc, B b, C c);
- private static class TreeMaker<T> extends HashSet<Tree<T>> implements Invokable<Forest.Body<T>,Boolean,Integer> {
+ private static abstract class TreeMaker<T> /*extends HashSet<Tree<T>>*/ implements Invokable<Forest.Body<T>,Boolean,Integer> {
public ArrayList<Tree<T>> toks = new ArrayList<Tree<T>>();
private boolean toss;
public TreeMaker(boolean toss) { this.toss = toss; }
+ public abstract void add(Tree<T> t);
public void invoke(Forest.Body<T> bod, Boolean o, Integer i) {
if (i==null) {
ArrayList<Tree<T>> toks = this.toks;