Package org.onebusaway.gtfs.model

Examples of org.onebusaway.gtfs.model.Route


    return metadata;
  }

  private Route getRouteForJourney(JourneyHeaderElement journey) {
    AgencyAndId routeId = getRouteIdForJourney(journey);
    Route route = _dao.getRouteForId(routeId);
    if (route == null) {
      route = new Route();
      route.setAgency(getAgencyForId(routeId.getAgencyId()));
      route.setId(routeId);
      route.setShortName(journey.getRouteIdentifier());
      route.setType(getRouteTypeForJourney(journey));
      RouteMetadata metaData = _routeMetadataById.get(routeId);
      if (metaData != null) {
        for (String id : _preferredDirectionIdsForRouteDetails) {
          String longName = metaData.getRouteLongNameForDirectionId(id);
          if (longName != null) {
            route.setLongName(longName);
            break;
          }
        }
        for (String id : _preferredDirectionIdsForRouteDetails) {
          String routeUrl = metaData.getRouteUrlForDirectionId(id);
          if (routeUrl != null) {
            route.setUrl(routeUrl);
            break;
          }
        }
      }
      _dao.saveEntity(route);
View Full Code Here


          newRide.firstStop = ((HopEdge) backEdge).getBeginStop();

          newRide.route = routeId;
          Trip trip = state.getBackTrip();
          Route route = trip.getRoute();
          int type = route.getType();
          newRide.classifier = type;
          String shortName = route.getShortName();
          if (shortName == null ) {
            newRide.classifier = SUBWAY;
          } else if (shortName.equals("BxM4C")) {
            newRide.classifier = EXPENSIVE_EXPRESS_BUS;
          } else if (shortName.startsWith("X")
View Full Code Here

   /** 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();
       }
View Full Code Here

   /** Return all stop patterns used by trips on the given route. */
   @GET
   @Path("/routes/{routeId}/patterns")
   public Response getPatternsForRoute (@PathParam("routeId") String routeIdString) {
       AgencyAndId routeId = GtfsLibrary.convertIdFromString(routeIdString);
       Route route = index.routeForId.get(routeId);
       if (route != null) {
           Collection<TripPattern> patterns = index.patternsForRoute.get(route);
           return Response.status(Status.OK).entity(PatternShort.list(patterns)).build();
       } else {
           return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
View Full Code Here

   /** 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());
View Full Code Here

   /** 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());
View Full Code Here

    /**
     * Test different specific transfers
     */
    public void testSpecificTransfer() {
        // Setup from trip with route
        Route fromRoute = new Route();
        fromRoute.setId(new AgencyAndId("A1", "R1"));
        Trip fromTrip = new Trip();
        fromTrip.setId(new AgencyAndId("A1", "T1"));
        fromTrip.setRoute(fromRoute);
       
        // Setup to trip with route
        Route toRoute = new Route();
        toRoute.setId(new AgencyAndId("A1", "R2"));
        Trip toTrip = new Trip();
        toTrip.setId(new AgencyAndId("A1", "T2"));
        toTrip.setRoute(toRoute);
       
        // Create full SpecificTransfer
        SpecificTransfer s1 = new SpecificTransfer(fromRoute.getId(), toRoute.getId(), fromTrip.getId(), toTrip.getId(), 1);
        assertTrue(s1.matches(fromTrip, toTrip));
        assertTrue(s1.getSpecificity() == SpecificTransfer.MAX_SPECIFICITY);
        assertTrue(s1.transferTime == 1);
       
        // Create empty SpecificTransfer
        SpecificTransfer s2 = new SpecificTransfer((AgencyAndId) null, null, null, null, 2);
        assertTrue(s2.matches(fromTrip, toTrip));
        assertTrue(s2.getSpecificity() == SpecificTransfer.MIN_SPECIFICITY);
        assertTrue(s2.transferTime == 2);
       
        // Create SpecificTransfer one trip missing
        SpecificTransfer s3 = new SpecificTransfer(fromRoute.getId(), toRoute.getId(), null, toTrip.getId(), 3);
        assertTrue(s3.matches(fromTrip, toTrip));
        assertTrue(s3.getSpecificity() == 3);
        assertTrue(s3.transferTime == 3);
       
        // Create SpecificTransfer one trip different
        SpecificTransfer s4 = new SpecificTransfer(fromRoute.getId(), toRoute.getId(), new AgencyAndId("A1", "T3"), toTrip.getId(), 4);
        assertFalse(s4.matches(fromTrip, toTrip));
        assertTrue(s4.getSpecificity() == SpecificTransfer.MAX_SPECIFICITY);
        assertTrue(s4.transferTime == 4);
       
        // Create SpecificTransfer one trip and route missing
        SpecificTransfer s5 = new SpecificTransfer(null, toRoute.getId(), null, toTrip.getId(), 5);
        assertTrue(s5.matches(fromTrip, toTrip));
        assertTrue(s5.getSpecificity() == 2);
        assertTrue(s5.transferTime == 5);
       
        // Create SpecificTransfer one trip only
View Full Code Here

public class TestRouteMatcher extends TestCase {

    public void testRouteMatcher() {

        Route r1 = new Route();
        r1.setId(new AgencyAndId("A1", "42"));
        r1.setShortName("R1");
        Route r2 = new Route();
        r2.setId(new AgencyAndId("A1", "43"));
        r2.setShortName("R2");
        Route r1b = new Route();
        r1b.setId(new AgencyAndId("A2", "42"));
        r1b.setShortName("R1");
        Route r3 = new Route();
        r3.setId(new AgencyAndId("A1", "44"));
        r3.setShortName("R3_b");

        RouteMatcher emptyMatcher = RouteMatcher.emptyMatcher();
        assertFalse(emptyMatcher.matches(r1));
        assertFalse(emptyMatcher.matches(r1b));
        assertFalse(emptyMatcher.matches(r2));

        RouteMatcher matcherR1i = RouteMatcher.parse("A1__42");
        assertTrue(matcherR1i.matches(r1));
        assertFalse(matcherR1i.matches(r1b));
        assertFalse(matcherR1i.matches(r2));

        RouteMatcher matcherR2n = RouteMatcher.parse("A1_R2");
        assertFalse(matcherR2n.matches(r1));
        assertFalse(matcherR2n.matches(r1b));
        assertTrue(matcherR2n.matches(r2));

        RouteMatcher matcherR1R2 = RouteMatcher.parse("A1_R1,A1__43,A2__43");
        assertTrue(matcherR1R2.matches(r1));
        assertFalse(matcherR1R2.matches(r1b));
        assertTrue(matcherR1R2.matches(r2));

        RouteMatcher matcherR1n = RouteMatcher.parse("_R1");
        assertTrue(matcherR1n.matches(r1));
        assertTrue(matcherR1n.matches(r1b));
        assertFalse(matcherR1n.matches(r2));

        RouteMatcher matcherR1R1bR2 = RouteMatcher.parse("A1_R1,A2_R1,A1_R2");
        assertTrue(matcherR1R1bR2.matches(r1));
        assertTrue(matcherR1R1bR2.matches(r1b));
        assertTrue(matcherR1R1bR2.matches(r2));

        RouteMatcher matcherR3e = RouteMatcher.parse("A1_R3 b");
        assertFalse(matcherR3e.matches(r1));
        assertFalse(matcherR3e.matches(r1b));
        assertFalse(matcherR3e.matches(r2));
        assertTrue(matcherR3e.matches(r3));

        RouteMatcher nullList = RouteMatcher.parse(null);
        assertTrue(nullList == RouteMatcher.emptyMatcher());

        RouteMatcher emptyList = RouteMatcher.parse("");
        assertTrue(emptyList == RouteMatcher.emptyMatcher());

        RouteMatcher degenerate = RouteMatcher.parse(",,,");
        assertTrue(degenerate == RouteMatcher.emptyMatcher());

        boolean thrown = false;
        try {
            RouteMatcher badMatcher = RouteMatcher.parse("A1_R1_42");
        } catch (IllegalArgumentException e) {
            thrown = true;
        }
        assertTrue(thrown);
       
        Route r1c = new Route();
        r1c.setId(new AgencyAndId("A_1", "R_42"));
        r1c.setShortName("R_42");

        RouteMatcher matcherR1c = RouteMatcher.parse("A\\_1_R 42");
        assertTrue(matcherR1c.matches(r1c));
        assertFalse(matcherR1c.matches(r1));
        assertFalse(matcherR1c.matches(r1b));
View Full Code Here

        Stop toStopParent = new Stop();
        toStopParent.setId(new AgencyAndId("A1", "S3"));
        toStop.setParentStation("S3");
       
        // Setup from trip with route
        Route fromRoute = new Route();
        fromRoute.setId(new AgencyAndId("A1", "R1"));
        Trip fromTrip = new Trip();
        fromTrip.setId(new AgencyAndId("A1", "T1"));
        fromTrip.setRoute(fromRoute);
       
        // Setup to trip with route
        Route toRoute = new Route();
        toRoute.setId(new AgencyAndId("A1", "R2"));
        Trip toTrip = new Trip();
        toTrip.setId(new AgencyAndId("A1", "T2"));
        toTrip.setRoute(toRoute);
       
        // Setup second to trip with route
        Route toRoute2 = new Route();
        toRoute2.setId(new AgencyAndId("A1", "R3"));
        Trip toTrip2 = new Trip();
        toTrip2.setId(new AgencyAndId("A1", "T3"));
        toTrip2.setRoute(toRoute2);
       
        // Create transfer table
View Full Code Here

    /**
     * Test different stop transfers
     */
    public void testStopTransfer() {
        // Setup from trip with route
        Route fromRoute = new Route();
        fromRoute.setId(new AgencyAndId("A1", "R1"));
        Trip fromTrip = new Trip();
        fromTrip.setId(new AgencyAndId("A1", "T1"));
        fromTrip.setRoute(fromRoute);
       
        // Setup to trip with route
        Route toRoute = new Route();
        toRoute.setId(new AgencyAndId("A1", "R2"));
        Trip toTrip = new Trip();
        toTrip.setId(new AgencyAndId("A1", "T2"));
        toTrip.setRoute(toRoute);
       
        // Setup second to trip with route
        Route toRoute2 = new Route();
        toRoute2.setId(new AgencyAndId("A1", "R3"));
        Trip toTrip2 = new Trip();
        toTrip2.setId(new AgencyAndId("A1", "T3"));
        toTrip2.setRoute(toRoute2);
       
        // Create StopTransfer
        StopTransfer transfer = new StopTransfer();
        assertEquals(StopTransfer.UNKNOWN_TRANSFER, transfer.getTransferTime(fromTrip, toTrip));
        assertEquals(StopTransfer.UNKNOWN_TRANSFER, transfer.getTransferTime(fromTrip, toTrip2));
       
        // Add empty SpecificTransfer, specificity 0
        transfer.addSpecificTransfer(new SpecificTransfer((AgencyAndId) null, null, null, null, StopTransfer.FORBIDDEN_TRANSFER));
        assertEquals(StopTransfer.FORBIDDEN_TRANSFER, transfer.getTransferTime(fromTrip, toTrip));
        assertEquals(StopTransfer.FORBIDDEN_TRANSFER, transfer.getTransferTime(fromTrip, toTrip2));
       
        // Add SpecificTransfer one route, specificity 1
        transfer.addSpecificTransfer(new SpecificTransfer(null, toRoute2.getId(), null, null, StopTransfer.PREFERRED_TRANSFER));
        assertEquals(StopTransfer.FORBIDDEN_TRANSFER, transfer.getTransferTime(fromTrip, toTrip));
        assertEquals(StopTransfer.PREFERRED_TRANSFER, transfer.getTransferTime(fromTrip, toTrip2));
       
        // Add SpecificTransfer one trip (and one ignored route), specificity 2
        transfer.addSpecificTransfer(new SpecificTransfer(null, toRoute2.getId(), null, toTrip2.getId(), StopTransfer.TIMED_TRANSFER));
        assertEquals(StopTransfer.FORBIDDEN_TRANSFER, transfer.getTransferTime(fromTrip, toTrip));
        assertEquals(StopTransfer.TIMED_TRANSFER, transfer.getTransferTime(fromTrip, toTrip2));
       
        // Add SpecificTransfer one trip and one route, specificity 3
        transfer.addSpecificTransfer(new SpecificTransfer(fromRoute.getId(), toRoute2.getId(), fromTrip.getId(), null, StopTransfer.UNKNOWN_TRANSFER));
        assertEquals(StopTransfer.FORBIDDEN_TRANSFER, transfer.getTransferTime(fromTrip, toTrip));
        assertEquals(StopTransfer.UNKNOWN_TRANSFER, transfer.getTransferTime(fromTrip, toTrip2));
       
        // Add SpecificTransfer one route, specificity 1
        transfer.addSpecificTransfer(new SpecificTransfer(fromRoute.getId(), null, null, null, 3));
View Full Code Here

TOP

Related Classes of org.onebusaway.gtfs.model.Route

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.