/* * (non-Javadoc) * * @see rationals.transformations.UnaryTransformation#transform(rationals.Automaton) */ public Automaton transform(Automaton a) { Automaton b = new Automaton(); Map qm = new HashMap(); for (Iterator i = a.states().iterator(); i.hasNext(); ) { State q = (State) i.next(); State p = b.addState(q.isInitial(), q.isTerminal()); qm.put(q, p); } Set alph = new HashSet(); for (Iterator it = a.states().iterator(); it.hasNext(); ) { State q = (State) it.next(); alph.addAll(alphabet); for (Iterator i2 = a.delta(q).iterator(); i2.hasNext(); ) { Transition tr = (Transition) i2.next(); try { b.addTransition( new Transition((State) qm.get(tr.start()), tr.label(), (State) qm.get(tr.end()))); } catch (NoSuchStateException e) { } alph.remove(tr.label()); } for (Iterator i2 = alph.iterator(); i2.hasNext(); ) { try { b.addTransition(new Transition(q, i2.next(), q)); } catch (NoSuchStateException e) { } } alph.clear(); } return b; }
/** @param s */ private void assertNoEpsilon(Set s) { for (Iterator i = s.iterator(); i.hasNext(); ) { Transition tr = (Transition) i.next(); assertTrue("Transition " + tr + " labelled with epsilon", tr.label() != null); } }