use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class PropertyMethodResolverImplTest method testUseCsvFieldMappings.
@Test
public void testUseCsvFieldMappings() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
DefaultEntitySchemaFactory factory = GtfsEntitySchemaFactory.createEntitySchemaFactory();
EntitySchema entitySchema = factory.getSchema(Route.class);
_schemaCache.addEntitySchema(entitySchema);
PropertyMethod method = _resolver.getPropertyMethod(Route.class, "route_id");
Route route = new Route();
AgencyAndId id = new AgencyAndId("1", "10");
route.setId(id);
assertSame(id, method.invoke(route));
}
use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class PropertyMethodResolverImplTest method testRouteTripsVirtualMethod.
@Test
public void testRouteTripsVirtualMethod() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
Route route = new Route();
route.setId(new AgencyAndId("1", "r0"));
_dao.saveEntity(route);
Trip trip = new Trip();
trip.setId(new AgencyAndId("1", "t0"));
trip.setRoute(route);
_dao.saveEntity(trip);
PropertyMethod method = _resolver.getPropertyMethod(Route.class, "trips");
assertEquals(Arrays.asList(trip), method.invoke(route));
}
use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class CheckForLengthyRouteNames method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
// this is inneficient, but if there are ever so many routes or a route
// with such a long name that it matters, then their gtfs is effectively broken
// or whatever is running the transform is woefully insufficient to work on anything
// to do with trips, shapes, or stoptimes
Collection<Route> routes = dao.getAllRoutes();
Stack<String> longestRouteNames = new Stack();
String longestNames = "";
String tooLongNames = "";
String namesWithDuplicateParts = "";
for (Route route : routes) {
String name = route.getLongName();
if (name.length() > logIfLongerThan) {
tooLongNames += name + "\n";
}
String[] nameParts = name.split(" ");
for (int i = 0; i < nameParts.length - 1; i++) {
if (nameParts[i].equals(nameParts[i + 1])) {
namesWithDuplicateParts += name + "\n";
}
}
if (longestRouteNames.size() < nLongestNames) {
longestRouteNames.push(name);
} else {
if (longestRouteNames.lastElement().length() < name.length()) {
longestRouteNames.pop();
longestRouteNames.push(name);
}
}
longestRouteNames.sort((a, b) -> {
return a.length() < b.length() ? 1 : -1;
});
}
for (String name : longestRouteNames) {
longestNames += name + "\n";
}
_log.info("Route names with duplicate words: \n" + namesWithDuplicateParts);
_log.info("Route names that are too long: \n" + tooLongNames);
_log.info("Longest Route names: \n" + longestNames);
}
use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class MTASubwayShuttleRouteStrategy method getShuttleRoute.
private Route getShuttleRoute(GtfsMutableRelationalDao dao, Route orig) {
Route shuttleRoute = new Route(orig);
AgencyAndId id = new AgencyAndId(shuttleRoute.getId().getAgencyId(), shuttleRoute.getId().getId() + SHUTTLE_ID_SUFFIX);
shuttleRoute.setId(id);
shuttleRoute.setShortName(shuttleRoute.getShortName() + SHUTTLE_ID_SUFFIX);
shuttleRoute.setLongName(shuttleRoute.getLongName() + SHUTTLE_NAME_SUFFIX);
shuttleRoute.setType(SHUTTLE_ROUTE_TYPE);
dao.saveEntity(shuttleRoute);
return shuttleRoute;
}
use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class MergeRouteFive method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
RemoveEntityLibrary removeEntityLibrary = new RemoveEntityLibrary();
String agency = dao.getAllTrips().iterator().next().getId().getAgencyId();
// Merge route 5X into route 5, then remove route 5X
Route routeFive = dao.getRouteForId(new AgencyAndId(agency, "5"));
Route routeFiveX = dao.getRouteForId(new AgencyAndId(agency, "5X"));
if (routeFive != null && routeFiveX != null) {
for (Trip trip : dao.getTripsForRoute(routeFiveX)) {
trip.setRoute(routeFive);
}
dao.removeEntity(routeFiveX);
}
}
Aggregations