Search in sources :

Example 1 with CSVListener

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;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) CSVListener(org.onebusaway.csv_entities.CSVListener) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) CSVLibrary(org.onebusaway.csv_entities.CSVLibrary) File(java.io.File) IOException(java.io.IOException)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CSVLibrary (org.onebusaway.csv_entities.CSVLibrary)1 CSVListener (org.onebusaway.csv_entities.CSVListener)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1