use of org.onebusaway.gtfs.model.Route in project OpenTripPlanner by opentripplanner.
the class IndexAPI method getStopsForRoute.
/**
* Return all stops in any pattern on a given route.
*/
@GET
@Path("/routes/{routeId}/stops")
public Response getStopsForRoute(@PathParam("routeId") String routeIdString) {
AgencyAndId routeId = GtfsLibrary.convertIdFromString(routeIdString);
Route route = index.routeForId.get(routeId);
if (route != null) {
Set<Stop> stops = Sets.newHashSet();
Collection<TripPattern> patterns = index.patternsForRoute.get(route);
for (TripPattern pattern : patterns) {
stops.addAll(pattern.getStops());
}
return Response.status(Status.OK).entity(StopShort.list(stops)).build();
} else {
return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
}
}
use of org.onebusaway.gtfs.model.Route in project OpenTripPlanner by opentripplanner.
the class IndexAPI method getRoute.
/**
* Return specific route in the graph, for the given ID.
*/
@GET
@Path("/routes/{routeId}")
public Response getRoute(@PathParam("routeId") String routeIdString) {
AgencyAndId routeId = GtfsLibrary.convertIdFromString(routeIdString);
Route route = index.routeForId.get(routeId);
if (route != null) {
return Response.status(Status.OK).entity(route).build();
} else {
return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
}
}
use of org.onebusaway.gtfs.model.Route in project OpenTripPlanner by opentripplanner.
the class IndexAPI method getRoutesForStop.
@GET
@Path("/stops/{stopId}/routes")
public Response getRoutesForStop(@PathParam("stopId") String stopId) {
Stop stop = index.stopForId.get(GtfsLibrary.convertIdFromString(stopId));
if (stop == null)
return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
Set<Route> routes = Sets.newHashSet();
for (TripPattern pattern : index.patternsForStop.get(stop)) {
routes.add(pattern.route);
}
return Response.status(Status.OK).entity(RouteShort.list(routes)).build();
}
use of org.onebusaway.gtfs.model.Route in project OpenTripPlanner by opentripplanner.
the class GraphIndexTest method testPatternsCoherent.
/**
* Check that bidirectional relationships between TripPatterns and Trips, Routes, and Stops are coherent.
*/
public void testPatternsCoherent() {
for (Trip trip : graph.index.tripForId.values()) {
TripPattern pattern = graph.index.patternForTrip.get(trip);
assertTrue(pattern.getTrips().contains(trip));
}
/* This one depends on a feed where each TripPattern appears on only one route. */
for (Route route : graph.index.routeForId.values()) {
for (TripPattern pattern : graph.index.patternsForRoute.get(route)) {
assertEquals(pattern.route, route);
}
}
for (Stop stop : graph.index.stopForId.values()) {
for (TripPattern pattern : graph.index.patternsForStop.get(stop)) {
assertTrue(pattern.stopPattern.containsStop(stop.getId().toString()));
}
}
}
use of org.onebusaway.gtfs.model.Route in project OpenTripPlanner by opentripplanner.
the class TripTimesTest method testBikesAllowed.
@Test
public void testBikesAllowed() {
Graph graph = new Graph();
Trip trip = new Trip();
Route route = new Route();
trip.setRoute(route);
List<StopTime> stopTimes = Arrays.asList(new StopTime(), new StopTime());
TripTimes s = new TripTimes(trip, stopTimes, new Deduplicator());
RoutingRequest request = new RoutingRequest(TraverseMode.BICYCLE);
Vertex v = new SimpleConcreteVertex(graph, "", 0.0, 0.0);
request.setRoutingContext(graph, v, v);
State s0 = new State(request);
assertFalse(s.tripAcceptable(s0, 0));
BikeAccess.setForTrip(trip, BikeAccess.ALLOWED);
assertTrue(s.tripAcceptable(s0, 0));
BikeAccess.setForTrip(trip, BikeAccess.NOT_ALLOWED);
assertFalse(s.tripAcceptable(s0, 0));
}
Aggregations