stateindex = statecount-1;
groupcount = getGroupCount(pattern);
groupindex = groupcount;
PatternAutomaton automaton = new PatternAutomaton(statecount);
automaton.setGroupCount(groupcount+1);
int finalstate = stateindex--;
automaton.setFinalState(finalstate);
automaton.setType(stateindex, PatternAutomaton.TYPE_GROUPEND);
automaton.setGroupIndex(stateindex, 0);
automaton.setTransitions(stateindex, new int[]{finalstate});
int state = stateindex--;
state = traverse(automaton, pattern, state);
automaton.setType(stateindex, PatternAutomaton.TYPE_GROUPSTART);
automaton.setGroupIndex(stateindex, 0);
automaton.setTransitions(stateindex, new int[]{state});
automaton.setFirstState(stateindex);
this.automaton = automaton;
}