for (int i = 0; i < tokens.size(); i++) {
BaseToken token = (BaseToken) tokens.get(i);
Iterator<Machine> machineItr = iv_machineSet.iterator();
while (machineItr.hasNext()) {
Machine fsm = (Machine) machineItr.next();
fsm.input(token);
State currentState = fsm.getCurrentState();
if (currentState.getStartStateFlag()) {
tokenStartMap.put(fsm, new Integer(i));
}
if (currentState.getEndStateFlag()) {
Object o = tokenStartMap.get(fsm);
int tokenStartIndex;
if (o == null) {
// By default, all machines start with
// token zero.
tokenStartIndex = 0;
} else {
tokenStartIndex = ((Integer) o).intValue();
// skip ahead over single token we don't want
tokenStartIndex++;
}
BaseToken endToken = null;
if (currentState instanceof NonTerminalEndState) {
endToken = (BaseToken) tokens.get(i - 1);
} else {
endToken = token;
}
BaseToken startToken = (BaseToken) tokens
.get(tokenStartIndex);
SubSectionIndicator subs = null;
if (fsm.equals(iv_subSectionIDConfirmMachine)) {
subs = new SubSectionIndicator(startToken
.getStartOffset(), endToken.getEndOffset(),
SubSectionIndicator.CONFIRMED_STATUS);
} else if (fsm.equals(iv_subSectionIDNegateMachine)) {
subs = new SubSectionIndicator(startToken
.getStartOffset(), endToken.getEndOffset(),
SubSectionIndicator.NEGATED_STATUS);
} else if (fsm.equals(iv_subSectionIDProbableMachine)) {
subs = new SubSectionIndicator(startToken
.getStartOffset(), endToken.getEndOffset(),
SubSectionIndicator.PROBABLE_STATUS);
}
outSet.add(subs);
fsm.reset();
}
}
}
// cleanup
tokenStartMap.clear();
// reset machines
Iterator<Machine> itr = iv_machineSet.iterator();
while (itr.hasNext()) {
Machine fsm = (Machine) itr.next();
fsm.reset();
}
return outSet;
}