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, Integer.valueOf(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;
DrugChangeStatusToken fractionToken = null;
if (fsm.equals(iv_startStatusMachine)) {
fractionToken = new DrugChangeStatusToken(startToken
.getStartOffset(), endToken.getEndOffset(),DrugChangeStatusToken.START);
} else if (fsm.equals(iv_stopStatusMachine)) {
fractionToken = new DrugChangeStatusToken(startToken
.getStartOffset(), endToken.getEndOffset(), DrugChangeStatusToken.STOP);
} else if (fsm.equals(iv_increaseFromStatusMachine)) {
fractionToken = new DrugChangeStatusToken(startToken
.getStartOffset(), endToken.getEndOffset(), DrugChangeStatusToken.INCREASEFROM);
} else if (fsm.equals(iv_decreaseFromStatusMachine)) {
fractionToken = new DrugChangeStatusToken(startToken
.getStartOffset(), endToken.getEndOffset(), DrugChangeStatusToken.DECREASEFROM);
} else if (fsm.equals(iv_increaseStatusMachine)) {
fractionToken = new DrugChangeStatusToken(startToken
.getStartOffset(), endToken.getEndOffset(), DrugChangeStatusToken.INCREASE);
} else if (fsm.equals(iv_decreaseStatusMachine)) {
fractionToken = new DrugChangeStatusToken(startToken
.getStartOffset(), endToken.getEndOffset(), DrugChangeStatusToken.DECREASE);
} else if (fsm.equals(iv_noChangeStatusMachine)) {
fractionToken = new DrugChangeStatusToken(startToken
.getStartOffset(), endToken.getEndOffset(), DrugChangeStatusToken.NOCHANGE);
} else if (fsm.equals(iv_changeStatusMachine)) {
fractionToken = new DrugChangeStatusToken(startToken
.getStartOffset(), endToken.getEndOffset(), DrugChangeStatusToken.OTHER);
} else if (fsm.equals(iv_sumStatusMachine)) {
fractionToken = new DrugChangeStatusToken(startToken
.getStartOffset(), endToken.getEndOffset(), DrugChangeStatusToken.SUM);
} else if (fsm.equals(iv_maxStatusMachine)) {
fractionToken = new DrugChangeStatusToken(startToken
.getStartOffset(), endToken.getEndOffset(), DrugChangeStatusToken.MAX);
}
fractionSet.add(fractionToken);
fsm.reset();
}
}
}
// cleanup
tokenStartMap.clear();
// reset machines
Iterator itr = iv_machineSet.iterator();
while (itr.hasNext()) {
Machine fsm = (Machine) itr.next();
fsm.reset();
}
return fractionSet;
}