question: static Automaton reverse ( Automaton a , Set < Integer > initialStates ) { if ( Operations . isEmpty ( a ) ) { return new Automaton ( ) ; } int numStates = a . getNumStates ( ) ; Automaton . Builder builder = new Automaton . Builder ( ) ; builder . createState ( ) ; for ( int s = 0 ; s < numStates ; s ++ ) { builder . createState ( ) ; } builder . setAccept ( 1 , true ) ; Transition t = new Transition ( ) ; for ( int s = 0 ; s < numStates ; s ++ ) { int numTransitions = a . getNumTransitions ( s ) ; a . initTransition ( s , t ) ; for ( int i = 0 ; i < numTransitions ; i ++ ) { a . getNextTransition ( t ) ; builder . addTransition ( t . dest + 1 , s + 1 , t . min , t . max ) ; } } Automaton result = builder . finish ( ) ; int s = 0 ; BitSet acceptStates = a . getAcceptStates ( ) ; while ( s < numStates && ( s = acceptStates . nextSetBit ( s ) ) != - 1 ) { result . addEpsilon ( 0 , s + 1 ) ; if ( initialStates != null ) { initialStates . add ( s + 1 ) ; } s ++ ; } result . finishState ( ) ; return result ; }
target:  Reverses the automaton, returning the new initial states. 