Search in sources :

Example 1 with GtfsDaoImpl

use of org.onebusaway.gtfs.impl.GtfsDaoImpl in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsReaderExampleMain method main.

public static void main(String[] args) throws IOException {
    if (args.length != 1) {
        System.err.println("usage: gtfsPath");
        System.exit(-1);
    }
    GtfsReader reader = new GtfsReader();
    reader.setInputLocation(new File(args[0]));
    /**
     * You can register an entity handler that listens for new objects as they
     * are read
     */
    reader.addEntityHandler(new GtfsEntityHandler());
    /**
     * Or you can use the internal entity store, which has references to all the
     * loaded entities
     */
    GtfsDaoImpl store = new GtfsDaoImpl();
    reader.setEntityStore(store);
    reader.run();
    // Access entities through the store
    Map<AgencyAndId, Route> routesById = store.getEntitiesByIdForEntityType(AgencyAndId.class, Route.class);
    for (Route route : routesById.values()) {
        System.out.println("route: " + route.getShortName());
    }
}
Also used : GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) GtfsDaoImpl(org.onebusaway.gtfs.impl.GtfsDaoImpl) File(java.io.File) Route(org.onebusaway.gtfs.model.Route)

Aggregations

File (java.io.File)1 GtfsDaoImpl (org.onebusaway.gtfs.impl.GtfsDaoImpl)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 Route (org.onebusaway.gtfs.model.Route)1 GtfsReader (org.onebusaway.gtfs.serialization.GtfsReader)1