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);
BaseToken startToken = null;
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++;
}
if (currentState instanceof IndentStartState) {
startToken = (BaseToken) tokens
.get(tokenStartIndex + 1);
}
else {
startToken = (BaseToken) tokens
.get(tokenStartIndex);
}
BaseToken endToken = null;
if (currentState instanceof NonTerminalEndState)
{
endToken = (BaseToken) tokens.get(i - 1);
}
else
{
endToken = token;
}
FrequencyUnitToken fractionToken = null;
if (fsm.equals(iv_EveryOtherHourMachine))
fractionToken = new FrequencyUnitToken(
startToken.getStartOffset(), endToken
.getEndOffset(), FrequencyUnitToken.QUANTITY_24/2);
else if (fsm.equals(iv_SixTimesADayMachine))
fractionToken = new FrequencyUnitToken(
startToken.getStartOffset(), endToken
.getEndOffset(), FrequencyUnitToken.QUANTITY_SIX);
else if (fsm.equals(iv_FiveTimesADayMachine))
fractionToken = new FrequencyUnitToken(
startToken.getStartOffset(), endToken
.getEndOffset(), FrequencyUnitToken.QUANTITY_FIVE);
else if (fsm.equals(iv_FourTimesADayMachine))
fractionToken = new FrequencyUnitToken(
startToken.getStartOffset(), endToken
.getEndOffset(), FrequencyUnitToken.QUANTITY_FOUR);
else if (fsm.equals(iv_ThreeTimesADayMachine))
fractionToken = new FrequencyUnitToken(
startToken.getStartOffset(), endToken
.getEndOffset(), FrequencyUnitToken.QUANTITY_THREE);
else if (fsm.equals(iv_HourlyMachine) || fsm.equals(iv_HourlySuffixMachine))
fractionToken = new FrequencyUnitToken(
startToken.getStartOffset(), endToken
.getEndOffset(), FrequencyUnitToken.QUANTITY_24);
else if (fsm.equals(iv_TwiceADayMachine))
fractionToken = new FrequencyUnitToken(
startToken.getStartOffset(), endToken
.getEndOffset(), FrequencyUnitToken.QUANTITY_TWO);
else if (fsm.equals(iv_DailyMachine) || fsm.equals(iv_DailySuffixMachine))
fractionToken = new FrequencyUnitToken(
startToken.getStartOffset(), endToken
.getEndOffset(), FrequencyUnitToken.QUANTITY_ONE);
else if (fsm.equals(iv_EveryOtherDayMachine))
fractionToken = new FrequencyUnitToken(
startToken.getStartOffset(), endToken
.getEndOffset(), FrequencyUnitToken.QUANTITY_EVERY_OTHER_DAY);
else if (fsm.equals(iv_WeeklyMachine)|| fsm.equals(iv_WeeklySuffixMachine))
fractionToken = new FrequencyUnitToken(
startToken.getStartOffset(), endToken
.getEndOffset(), FrequencyUnitToken.QUANTITY_WEEKLY);
else if (fsm.equals(iv_MonthlySuffixMachine))
fractionToken = new FrequencyUnitToken(
startToken.getStartOffset(), endToken
.getEndOffset(), FrequencyUnitToken.QUANTITY_MONTHLY);
else if (fsm.equals(iv_YearlySuffixMachine))
fractionToken = new FrequencyUnitToken(
startToken.getStartOffset(), endToken
.getEndOffset(), FrequencyUnitToken.QUANTITY_YEARLY);
else
fractionToken = new FrequencyUnitToken(
startToken.getStartOffset(), endToken
.getEndOffset(), FrequencyUnitToken.QUANTITY_PRN);
rangeSet.add(fractionToken);
fsm.reset();
}