use of org.onebusaway.gtfs.model.Trip in project OpenTripPlanner by opentripplanner.
the class IndexAPI method getTripsForRoute.
/**
* Return all trips in any pattern on the given route.
*/
@GET
@Path("/routes/{routeId}/trips")
public Response getTripsForRoute(@PathParam("routeId") String routeIdString) {
AgencyAndId routeId = GtfsLibrary.convertIdFromString(routeIdString);
Route route = index.routeForId.get(routeId);
if (route != null) {
List<Trip> trips = Lists.newArrayList();
Collection<TripPattern> patterns = index.patternsForRoute.get(route);
for (TripPattern pattern : patterns) {
trips.addAll(pattern.getTrips());
}
return Response.status(Status.OK).entity(TripShort.list(trips)).build();
} else {
return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
}
}
use of org.onebusaway.gtfs.model.Trip in project OpenTripPlanner by opentripplanner.
the class IndexAPI method getStopsForTrip.
@GET
@Path("/trips/{tripId}/stops")
public Response getStopsForTrip(@PathParam("tripId") String tripIdString) {
AgencyAndId tripId = GtfsLibrary.convertIdFromString(tripIdString);
Trip trip = index.tripForId.get(tripId);
if (trip != null) {
TripPattern pattern = index.patternForTrip.get(trip);
Collection<Stop> stops = 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.Trip in project OpenTripPlanner by opentripplanner.
the class IndexAPI method getGeometryForTrip.
/**
* Return geometry for the trip as a packed coordinate sequence
*/
@GET
@Path("/trips/{tripId}/geometry")
public Response getGeometryForTrip(@PathParam("tripId") String tripIdString) {
AgencyAndId tripId = GtfsLibrary.convertIdFromString(tripIdString);
Trip trip = index.tripForId.get(tripId);
if (trip != null) {
TripPattern tripPattern = index.patternForTrip.get(trip);
return getGeometryForPattern(tripPattern.code);
} else {
return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
}
}
use of org.onebusaway.gtfs.model.Trip in project OpenTripPlanner by opentripplanner.
the class IndexAPI method getTrip.
// Not implemented, results would be too voluminous.
// @Path("/trips")
@GET
@Path("/trips/{tripId}")
public Response getTrip(@PathParam("tripId") String tripIdString) {
AgencyAndId tripId = GtfsLibrary.convertIdFromString(tripIdString);
Trip trip = index.tripForId.get(tripId);
if (trip != null) {
return Response.status(Status.OK).entity(trip).build();
} else {
return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
}
}
use of org.onebusaway.gtfs.model.Trip 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()));
}
}
}
Aggregations