AutomatonSpecification subautomaton) {
AutomatonSpecification newAutomaton = new NaiveAutomatonSpecification();
if (numberOfOccurences == 0) {
State state = newAutomaton.addState();
newAutomaton.markAsInitial(state);
newAutomaton.markAsFinal(state);
}
if (numberOfOccurences > 0) {
newAutomaton = subautomaton.clone();
for (int i = 1; i < numberOfOccurences; i++) {
State newState = newAutomaton.addState();
for (State state : newAutomaton.allStates()) {
if (newAutomaton.isFinal(state)) {
newAutomaton.addTransition(state, newState, new EpsilonTransitionLabel());
newAutomaton.unmarkAsFinalState(state);
}
}
newAutomaton.insert(newState, subautomaton);
}
State newState = newAutomaton.addState();
newAutomaton.insert(newState, subautomaton);
for (State state : newAutomaton.allStates()) {
if (newAutomaton.isFinal(state)) {
newAutomaton.addTransition(state, newState, new EpsilonTransitionLabel());
}