/** * Converts this FA into an equivalent {@link NFA}. * Note: this is trivial since an FA is just a special kind of NFA, except for the different representation. */ public NFA toNFA() { NFA f = new NFA(); f.alphabet = alphabet; Map m = new HashMap(); // map from old states to new states for (State p : states) { State s = (State) p.clone(); f.states.add(s); m.put(p, s); if (accept.contains(p)) f.accept.add(s); if (p==initial) f.initial = s; } for (Map.Entry e : transitions.entrySet()) { StateSymbolPair ssp = e.getKey(); State q = e.getValue(); Set ns = new HashSet(); ns.add(m.get(q)); f.transitions.put(new StateSymbolPair(m.get(ssp.state), ssp.symbol), ns); } return f; }