// maps a fsm to a token start index
// key = fsm , value = token start index
Map tokenStartMap = new HashMap();
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();
BaseToken startToken = null;
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);
fractionSet.add(fractionToken);
fsm.reset();
}