use of org.onebusaway.csv_entities.CSVListener in project onebusaway-application-modules by camsys.
the class StifTask method loadTripToDSCOverrides.
private Map<AgencyAndId, String> loadTripToDSCOverrides(String path) throws Exception {
final Map<AgencyAndId, String> results = new HashMap<AgencyAndId, String>();
CSVListener listener = new CSVListener() {
int count = 0;
int tripIdIndex;
int dscIndex;
@Override
public void handleLine(List<String> line) throws Exception {
if (line.size() != 2)
throw new Exception("Each Trip ID to DSC CSV line must contain two columns.");
if (count == 0) {
count++;
tripIdIndex = line.indexOf("trip_id");
dscIndex = line.indexOf("dsc");
if (tripIdIndex == -1 || dscIndex == -1) {
throw new Exception("Trip ID to DSC CSV must contain a header with column names 'trip_id' and 'dsc'.");
}
return;
}
results.put(AgencyAndIdLibrary.convertFromString(line.get(tripIdIndex)), line.get(dscIndex));
}
};
File source = new File(path);
new CSVLibrary().parse(source, listener);
return results;
}
Aggregations