for (int i = 0; i < tokens.size(); i++) {
BaseToken token = (BaseToken) tokens.get(i);
Iterator 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 startToken = (BaseToken) tokens
.get(tokenStartIndex);
BaseToken endToken = token;
RouteToken segmentToken = null;
if (fsm.equals(iv_PatchesMachine)){
segmentToken = new RouteToken(
startToken.getStartOffset(), endToken
.getEndOffset());
segmentToken.setFormMethod(RouteToken.TRANSDERMAL);
}
else if (fsm.equals(iv_GastricMachine)){
segmentToken = new RouteToken(
startToken.getStartOffset(), endToken
.getEndOffset());
segmentToken.setFormMethod(RouteToken.GASTRIC);
}
else if (fsm.equals(iv_TopicalMachine)){
segmentToken = new RouteToken(
startToken.getStartOffset(), endToken
.getEndOffset());
segmentToken.setFormMethod(RouteToken.TOPICAL);
}
else if (fsm.equals(iv_OralMachine)){
segmentToken = new RouteToken(
startToken.getStartOffset(), endToken
.getEndOffset());
segmentToken.setFormMethod(RouteToken.ORAL);
}
else if (fsm.equals(iv_RectalMachine)){
segmentToken = new RouteToken(
startToken.getStartOffset(), endToken
.getEndOffset());
segmentToken.setFormMethod(RouteToken.RECTAL);
}
else if (fsm.equals(iv_InjectMachine)){
segmentToken = new RouteToken(
startToken.getStartOffset(), endToken
.getEndOffset());
segmentToken.setFormMethod(RouteToken.INTRAVENOUS);
}
fractionSet.add(segmentToken);
fsm.reset();
}
}
}
// cleanup
tokenStartMap.clear();
// reset machines
Iterator itr = iv_machineSet.iterator();
while (itr.hasNext()) {
Machine fsm = (Machine) itr.next();
fsm.reset();
}
return fractionSet;
}