use of org.onebusaway.admin.model.ui.DataValidationMode in project onebusaway-application-modules by camsys.
the class FixedRouteParserServiceImpl method parseRecord.
/**
* Parses a csv record representing one line of a FixedRouteDataValidation
* report. If the line is part of the mode currently being processed, it
* is added to that DataValidationMode object. If it is for a new mode, the
* current mode is added to the parsedModes list and the record being
* parsed becomes the new current mode.
*
* @param record the record to be parsed
* @param currentMode the DataValidationMode currently being built
* @param parsedModes the list of modes already created.
* @return the DataValidationMode currently being built
*/
private DataValidationMode parseRecord(CSVRecord record, DataValidationMode currentMode, List<DataValidationMode> parsedModes) {
if (record.size() < 8 || record.get(4).isEmpty() || !record.get(4).matches("^\\d+$")) {
// Stop count should be numeric
return currentMode;
}
// Create the StopCt for this line (every line should have a stop count)
DataValidationStopCt currentStopCt = new DataValidationStopCt();
currentStopCt.setStopCt(Integer.parseInt(record.get(4)));
int[] stopCtTrips = { 0, 0, 0 };
for (int i = 0; i < 3; i++) {
try {
int tripCt = Integer.parseInt(record.get(5 + i));
stopCtTrips[i] = tripCt;
} catch (NumberFormatException ex) {
// Do nothing, leave array value at 0.
}
}
currentStopCt.setTripCts(stopCtTrips);
String modeName = record.get(0);
String routeName = record.get(1);
String headsign = record.get(2);
String dirName = record.get(3);
// If routeName is prefixed with the route number, extract the route number
String routeNum = "";
if (routeName.length() > 0) {
int idx = routeName.substring(0, Math.min(5, routeName.length())).indexOf("-");
if (idx > 0) {
routeNum = routeName.substring(0, idx).trim();
routeName = routeName.substring(idx + 1);
}
}
if (modeName.length() > 0) {
// new mode
if (routeName.isEmpty()) {
// this shouldn't happen. Any line with a mode
return currentMode;
// name should also have a route name.
}
if (currentMode != null) {
parsedModes.add(currentMode);
}
currentMode = new DataValidationMode(modeName, routeNum, routeName, headsign, dirName);
currentRoute = currentMode.getRoutes().first();
currentHeadsign = currentRoute.getHeadsignCounts().first();
currentDirection = currentHeadsign.getDirCounts().first();
SortedSet<DataValidationStopCt> stopCountsList = currentDirection.getStopCounts();
stopCountsList.add(currentStopCt);
} else if (routeName.length() > 0) {
// New route for current mode
currentRoute = new DataValidationRouteCounts(routeNum, routeName, headsign, dirName);
currentMode.getRoutes().add(currentRoute);
currentHeadsign = currentRoute.getHeadsignCounts().first();
currentDirection = currentHeadsign.getDirCounts().first();
SortedSet<DataValidationStopCt> stopCountsList = currentDirection.getStopCounts();
stopCountsList.add(currentStopCt);
} else if (headsign.length() > 0) {
currentHeadsign = new DataValidationHeadsignCts(headsign, dirName);
currentRoute.getHeadsignCounts().add(currentHeadsign);
currentDirection = currentHeadsign.getDirCounts().first();
SortedSet<DataValidationStopCt> stopCountsList = currentDirection.getStopCounts();
stopCountsList.add(currentStopCt);
} else if (dirName.length() > 0) {
currentDirection = new DataValidationDirectionCts(dirName);
currentHeadsign.getDirCounts().add(currentDirection);
SortedSet<DataValidationStopCt> stopCountsList = currentDirection.getStopCounts();
stopCountsList.add(currentStopCt);
} else if (dirName.isEmpty()) {
SortedSet<DataValidationStopCt> stopCountsList = currentDirection.getStopCounts();
stopCountsList.add(currentStopCt);
}
return currentMode;
}
Aggregations