Iterator overrideTokenItr = overrideSet.iterator();
// key = start offset, value = override BaseToken object
Map overrideTokenMap = new HashMap();
while (overrideTokenItr.hasNext()) {
BaseToken t = (BaseToken) overrideTokenItr.next();
Integer key = new Integer(t.getStartOffset());
overrideTokenMap.put(key, t);
}
boolean overrideOn = false;
int overrideEndOffset = -1;
for (int i = 0; i < tokens.size(); i++) {
BaseToken token = (BaseToken) tokens.get(i);
Integer key = new Integer(token.getStartOffset());
if (overrideOn) {
if (token.getStartOffset() >= overrideEndOffset) {
overrideOn = false;
overrideEndOffset = -1;
} else {
// step to next iteration of for loop
continue;
}
} else {
if (overrideTokenMap.containsKey(key)) {
// override one or more tokens until the override
// token is complete
token = (BaseToken) overrideTokenMap.get(key);
overrideOn = true;
overrideEndOffset = token.getEndOffset();
}
}
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);
}
rangeSet.add(segmentToken);
fsm.reset();