Java Code Examples for org.onebusaway.gtfs.model.Trip

The following are top voted examples for showing how to use org.onebusaway.gtfs.model.Trip. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: infotranspub-backend   File: GtfsMappingTest.java   View source code 6 votes vote down vote up
@Test
public void testFrequency() throws CsvEntityIOException, IOException {

  _reader.setDefaultAgencyId("1");

  Trip trip = new Trip();
  trip.setId(new AgencyAndId("1", "trip"));
  _reader.injectEntity(trip);

  StringBuilder b = new StringBuilder();
  b.append("trip_id,start_time,end_time,headway_secs,exact_times\n");
  b.append("trip,08:30:00,09:45:00,300,1\n");

  _reader.readEntities(Frequency.class, new StringReader(b.toString()));

  Frequency frequency = _dao.getFrequencyForId(1);
  assertEquals(30600, frequency.getStartTime());
  assertEquals(35100, frequency.getEndTime());
  assertEquals(1, frequency.getExactTimes());
  assertEquals(300, frequency.getHeadwaySecs());
  assertSame(trip, frequency.getTrip());
}
 
Example 2
Project: infotranspub-backend   File: GtfsEntitySchemaFactory.java   View source code 6 votes vote down vote up
public static List<Class<?>> getEntityClasses() {
  List<Class<?>> entityClasses = new ArrayList<Class<?>>();
  entityClasses.add(FeedInfo.class);
  entityClasses.add(Agency.class);
  entityClasses.add(Block.class);
  entityClasses.add(ShapePoint.class);
  entityClasses.add(Route.class);
  entityClasses.add(Stop.class);
  entityClasses.add(Trip.class);
  entityClasses.add(StopTime.class);
  entityClasses.add(ServiceCalendar.class);
  entityClasses.add(ServiceCalendarDate.class);
  entityClasses.add(FareAttribute.class);
  entityClasses.add(FareRule.class);
  entityClasses.add(Frequency.class);
  entityClasses.add(Pathway.class);
  entityClasses.add(Transfer.class);
  return entityClasses;
}
 
Example 3
Project: infotranspub-backend   File: GtfsEntitySchemaFactory.java   View source code 6 votes vote down vote up
public static Map<Class<?>, Comparator<?>> getEntityComparators() {
  Map<Class<?>, Comparator<?>> comparators = new HashMap<Class<?>, Comparator<?>>();
  comparators.put(Agency.class,
      getComparatorForIdentityBeanType(Agency.class));
  comparators.put(Block.class,
      getComparatorForIdentityBeanType(Block.class));
  comparators.put(Route.class, getComparatorForIdentityBeanType(Route.class));
  comparators.put(Stop.class, getComparatorForIdentityBeanType(Stop.class));
  comparators.put(Trip.class, getComparatorForIdentityBeanType(Trip.class));
  comparators.put(StopTime.class, new StopTimeComparator());
  comparators.put(ShapePoint.class, new ShapePointComparator());
  comparators.put(ServiceCalendar.class, new ServiceCalendarComparator());
  comparators.put(ServiceCalendarDate.class,
      new ServiceCalendarDateComparator());
  return comparators;
}
 
Example 4
Project: infotranspub-backend   File: GtfsRelationalDaoImpl.java   View source code 6 votes vote down vote up
@Override
public List<Trip> getTripsForBlockId(AgencyAndId blockId) {

  if (_tripsByBlockId == null) {
    _tripsByBlockId = new HashMap<AgencyAndId, List<Trip>>();
    for (Trip trip : getAllTrips()) {
      if (trip.getBlockId() != null) {
        AgencyAndId bid = new AgencyAndId(trip.getId().getAgencyId(),
            trip.getBlockId());
        List<Trip> trips = _tripsByBlockId.get(bid);
        if (trips == null) {
          trips = new ArrayList<Trip>();
          _tripsByBlockId.put(bid, trips);
        }
        trips.add(trip);
      }
    }
  }

  return list(_tripsByBlockId.get(blockId));
}
 
Example 5
Project: infotranspub-backend   File: GtfsReaderTest.java   View source code 6 votes vote down vote up
@Test
public void testFrequency() throws CsvEntityIOException, IOException {

  GtfsReader reader = new GtfsReader();
  reader.setDefaultAgencyId("1");

  Trip trip = new Trip();
  trip.setId(new AgencyAndId("1", "trip"));
  reader.injectEntity(trip);

  StringBuilder b = new StringBuilder();
  b.append("trip_id,start_time,end_time,headway_secs,exact_times\n");
  b.append("trip,08:30:00,09:45:00,300,1\n");

  reader.readEntities(Frequency.class, new StringReader(b.toString()));

  Frequency frequency = reader.getEntityStore().getEntityForId(
      Frequency.class, 1);
  assertEquals(30600, frequency.getStartTime());
  assertEquals(35100, frequency.getEndTime());
  assertEquals(1, frequency.getExactTimes());
  assertEquals(300, frequency.getHeadwaySecs());
  assertSame(trip, frequency.getTrip());
}
 
Example 6
Project: infotranspub-backend   File: GtfsRelationalDaoImplTest.java   View source code 6 votes vote down vote up
@Test
public void testSyntheticGetTripAgencyIdsReferencingServiceId() {

  GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();

  AgencyAndId serviceId = new AgencyAndId("C", "serviceId");

  Trip tripA = new Trip();
  tripA.setId(new AgencyAndId("A", "tripId"));
  tripA.setServiceId(serviceId);
  dao.saveEntity(tripA);

  Trip tripB = new Trip();
  tripB.setId(new AgencyAndId("B", "tripId"));
  tripB.setServiceId(serviceId);
  dao.saveEntity(tripB);

  List<String> agencyIds = dao.getTripAgencyIdsReferencingServiceId(serviceId);
  assertEquals(2, agencyIds.size());
  assertTrue(agencyIds.contains("A"));
  assertTrue(agencyIds.contains("B"));
}
 
Example 7
Project: wsf-gtfsrealtime   File: WSFRealtimeProvider.java   View source code 6 votes vote down vote up
private TripDescriptor buildTripDescriptor(VesselLocationResponse vlr) {
  TripDescriptor.Builder tripDescriptor = TripDescriptor.newBuilder();

  ActivatedTrip activatedTrip = _tripResolutionService.resolve(vlr.getDepartingTerminalID().toString(),
          ts(vlr.getScheduledDeparture().getValue()),
          vlr.getArrivingTerminalID().getValue().toString());

  if (activatedTrip == null) {
    return null;
  }

  Trip trip = activatedTrip.getTrip();
  ServiceDate sd = activatedTrip.getServiceDate();

  tripDescriptor.setTripId(trip.getId().getId());
  tripDescriptor.setRouteId(trip.getRoute().getId().getId());
  tripDescriptor.setStartDate(sd.getAsString());

  return tripDescriptor.build();
}
 
Example 8
Project: gtfsview   File: TripRenderer.java   View source code 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(
        JList list, Object value, int index,
        boolean isSelected, boolean cellHasFocus) {
    super.getListCellRendererComponent(list, value, index,
            isSelected, cellHasFocus);

    if (value != null) {
        Trip trip = (Trip) value;

        if (trip.getTripShortName() != null) {
            setText(trip.getTripShortName());
        } else if (trip.getTripHeadsign() != null) {
            setText(trip.getTripHeadsign());
        } else {
            setText(trip.getId().getId());
        }

    } else {
        setText("Select Trip...");
    }
    return this;
}
 
Example 9
Project: geom2gtfs   File: GtfsQueue.java   View source code 6 votes vote down vote up
public void dumpToWriter(GtfsWriter gtfsWriter) {
    for(Agency agency : agencies){
    	gtfsWriter.handleEntity( agency );
    }
    for(Route route : routes){
    	gtfsWriter.handleEntity(route);
    }
    for(Trip trip : trips){
    	gtfsWriter.handleEntity(trip);
    }
    for(Stop stop : stops){
    	gtfsWriter.handleEntity(stop);
    }
    for(StopTime stoptime : stoptimes){
    	gtfsWriter.handleEntity(stoptime);
    }
    for(Frequency fr : frequencies){
    	gtfsWriter.handleEntity(fr);
    }
    for(ServiceCalendar sc : calendars){
    	gtfsWriter.handleEntity(sc);
    }
}
 
Example 10
Project: gtfs-java   File: SpecificTransfer.java   View source code 6 votes vote down vote up
private boolean matchesFrom(Trip trip) {
    checkNotNull(trip);
    
    boolean match = false;
    int specificity = getFromSpecificity();
    if (specificity == 0) {
        match = true;
    }
    else if (specificity == 1) {
        if (trip.getRoute().getId().equals(fromRouteId)) {
            match = true;
        }
    }
    else if (specificity == 2) {
        if (trip.getId().equals(fromTripId)) {
            match = true;
        }
    }
    return match;
}
 
Example 11
Project: gtfs-java   File: SpecificTransfer.java   View source code 6 votes vote down vote up
private boolean matchesTo(Trip trip) {
    checkNotNull(trip);

    boolean match = false;
    int specificity = getToSpecificity();
    if (specificity == 0) {
        match = true;
    }
    else if (specificity == 1) {
        if (trip.getRoute().getId().equals(toRouteId)) {
            match = true;
        }
    }
    else if (specificity == 2) {
        if (trip.getId().equals(toTripId)) {
            match = true;
        }
    }
    return match;
}
 
Example 12
Project: gtfs-java   File: StopTransfer.java   View source code 6 votes vote down vote up
/**
 * Get the transfer time that should be used when transferring from a trip to another trip.
 * Note that this function does not check whether another specific transfer exists with the
 * same specificity, what is forbidden by the specifications.    
 * @param fromTrip is the arriving trip
 * @param toTrip is the departing trip
 * @return the transfer time in seconds. May contain special (negative) values which meaning
 *   can be found in the *_TRANSFER constants.
 */
public int getTransferTime(Trip fromTrip, Trip toTrip) {
    // By default the transfer is unknown
    int transferTime = UNKNOWN_TRANSFER;
    
    // Pick the matching specific transfer with the highest specificity
    int maxFoundSpecificity = SpecificTransfer.MIN_SPECIFICITY - 1;
    for (SpecificTransfer specificTransfer : specificTransfers) {
        int specificity = specificTransfer.getSpecificity(); 
        if (specificity > maxFoundSpecificity) {
            if (specificTransfer.matches(fromTrip, toTrip)) {
                // Set the found transfer time
                transferTime = specificTransfer.transferTime;
                maxFoundSpecificity = specificity;
                
                // Break when highest specificity is found
                if (maxFoundSpecificity == SpecificTransfer.MAX_SPECIFICITY) {
                    break;
                }
            }
        }
    }
    
    // Return transfer time
    return transferTime;
}
 
Example 13
Project: gtfs-java   File: TransferTable.java   View source code 6 votes vote down vote up
/**
 * Add a transfer time to the transfer table.
 * 
 * @param fromStop is the arriving stop
 * @param toStop is the departing stop
 * @param fromRoute is the arriving route; is allowed to be null
 * @param toRoute is the departing route; is allowed to be null
 * @param fromTrip is the arriving trip; is allowed to be null
 * @param toTrip is the departing trip; is allowed to be null
 * @param transferTime is the transfer time in seconds. May contain special (negative) values
 *        which meaning can be found in the StopTransfer.*_TRANSFER constants. If no transfer is
 *        found, StopTransfer.UNKNOWN_TRANSFER is returned.
 */
public void addTransferTime(Stop fromStop, Stop toStop, Route fromRoute, Route toRoute, Trip fromTrip, Trip toTrip,
        int transferTime) {
    checkNotNull(fromStop);
    checkNotNull(toStop);
    
    // Check whether this transfer is preferred (or timed)
    if ((transferTime == StopTransfer.PREFERRED_TRANSFER) || (transferTime == StopTransfer.TIMED_TRANSFER)) {
        this.preferredTransfers = true;
    }

    // Lookup whether a transfer between the two stops already exists
    P2<AgencyAndId> stopIdPair = new P2<AgencyAndId>(fromStop.getId(), toStop.getId());
    StopTransfer stopTransfer = this.table.get(stopIdPair);
    if (stopTransfer == null) {
        // If not, create one and add to table
        stopTransfer = new StopTransfer();
        this.table.put(stopIdPair, stopTransfer);
    }
    assert (stopTransfer != null);

    // Create and add a specific transfer to the stop transfer
    SpecificTransfer specificTransfer = new SpecificTransfer(fromRoute, toRoute, fromTrip, toTrip, transferTime);
    stopTransfer.addSpecificTransfer(specificTransfer);
}
 
Example 14
Project: infotranspub-backend   File: HibernateGtfsRelationalDaoImplCaltrainTest.java   View source code 5 votes vote down vote up
/****
 * {@link Trip} Methods
 ****/

@Test
public void testGetAllTrips() {
  List<Trip> trips = _dao.getAllTrips();
  assertEquals(260, trips.size());
}
 
Example 15
Project: infotranspub-backend   File: HibernateGtfsRelationalDaoImplCaltrainTest.java   View source code 5 votes vote down vote up
@Test
public void testGetTripById() {
  Route route = _dao.getRouteForId(aid("ct_local"));

  Trip trip = _dao.getTripForId(aid("10101272009"));
  assertEquals(aid("10101272009"), trip.getId());
  assertNull(trip.getBlockId());
  assertEquals("0", trip.getDirectionId());
  assertEquals(route, trip.getRoute());
  assertNull(trip.getRouteShortName());
  assertEquals(aid("WD01272009"), trip.getServiceId());
  assertEquals(aid("cal_sj_sf"), trip.getShapeId());
  assertEquals("101", trip.getTripShortName());
  assertEquals("San Jose to San Francisco", trip.getTripHeadsign());
}
 
Example 16
Project: infotranspub-backend   File: HibernateGtfsRelationalImplBartTest.java   View source code 5 votes vote down vote up
@Test
public void testFrequenciesForTrip() {
  Trip trip = _dao.getTripForId(new AgencyAndId("AirBART", "M-FSAT1DN"));
  List<Frequency> frequencies = _dao.getFrequenciesForTrip(trip);
  assertEquals(1, frequencies.size());

  Frequency frequency = frequencies.get(0);
  assertEquals(5 * 60 * 60, frequency.getStartTime());
  assertEquals(6 * 60 * 60, frequency.getEndTime());
  assertEquals(trip, frequency.getTrip());
  assertEquals(1200, frequency.getHeadwaySecs());
}
 
Example 17
Project: infotranspub-backend   File: StopTimeComparator.java   View source code 5 votes vote down vote up
@Override
public int compare(StopTime o1, StopTime o2) {
  Trip trip1 = o1.getTrip();
  Trip trip2 = o2.getTrip();
  int c = trip1.getId().compareTo(trip2.getId());
  
  if( c == 0)
    c = o1.getStopSequence() - o2.getStopSequence();
  
  return c;
}
 
Example 18
Project: infotranspub-backend   File: GtfsReader.java   View source code 5 votes vote down vote up
public GtfsReader() {

    _entityClasses.add(Agency.class);
    _entityClasses.add(Block.class);
    _entityClasses.add(ShapePoint.class);
    _entityClasses.add(Route.class);
    _entityClasses.add(Stop.class);
    _entityClasses.add(Trip.class);
    _entityClasses.add(StopTime.class);
    _entityClasses.add(ServiceCalendar.class);
    _entityClasses.add(ServiceCalendarDate.class);
    _entityClasses.add(FareAttribute.class);
    _entityClasses.add(FareRule.class);
    _entityClasses.add(Frequency.class);
    _entityClasses.add(Pathway.class);
    _entityClasses.add(Transfer.class);
    _entityClasses.add(FeedInfo.class);

    CsvTokenizerStrategy tokenizerStrategy = new CsvTokenizerStrategy();
    tokenizerStrategy.getCsvParser().setTrimInitialWhitespace(true);
    setTokenizerStrategy(tokenizerStrategy);
    
    setTrimValues(true);

    /**
     * Prep the Entity Schema Factories
     */
    DefaultEntitySchemaFactory schemaFactory = createEntitySchemaFactory();
    setEntitySchemaFactory(schemaFactory);

    CsvEntityContext ctx = getContext();
    ctx.put(KEY_CONTEXT, _context);

    addEntityHandler(new EntityHandlerImpl());
  }
 
Example 19
Project: infotranspub-backend   File: GtfsReader.java   View source code 5 votes vote down vote up
public void handleEntity(Object entity) {

      if (entity instanceof Agency) {
        Agency agency = (Agency) entity;
        if (agency.getId() == null) {
          if (_defaultAgencyId == null)
            agency.setId(agency.getName());
          else
            agency.setId(_defaultAgencyId);
        }

        // If we already have this agency from a previous load, then we don't
        // add it or save it to the entity store
        if (_agencies.contains(agency))
          return;

        _agencies.add((Agency) entity);
      } else if (entity instanceof Pathway) {
        Pathway pathway = (Pathway) entity;
        registerAgencyId(Pathway.class, pathway.getId());
      } else if (entity instanceof Route) {
        Route route = (Route) entity;
        registerAgencyId(Route.class, route.getId());
      } else if (entity instanceof Trip) {
        Trip trip = (Trip) entity;
        registerAgencyId(Trip.class, trip.getId());
      } else if (entity instanceof Stop) {
        Stop stop = (Stop) entity;
        registerAgencyId(Stop.class, stop.getId());
      } else if (entity instanceof FareAttribute) {
        FareAttribute fare = (FareAttribute) entity;
        registerAgencyId(FareAttribute.class, fare.getId());
      }

      if (entity instanceof IdentityBean<?>) {
        _entityStore.saveEntity(entity);
      }

    }
 
Example 20
Project: infotranspub-backend   File: GtfsRelationalDaoImpl.java   View source code 5 votes vote down vote up
@Override
public List<StopTime> getStopTimesForTrip(Trip trip) {

  if (_stopTimesByTrip == null) {
    _stopTimesByTrip = mapToValueList(getAllStopTimes(), "trip", Trip.class);
    for (List<StopTime> stopTimes : _stopTimesByTrip.values())
      Collections.sort(stopTimes);
  }

  return list(_stopTimesByTrip.get(trip));
}
 
Example 21
Project: infotranspub-backend   File: GtfsRelationalDaoImpl.java   View source code 5 votes vote down vote up
@Override
public List<Trip> getTripsForShapeId(AgencyAndId shapeId) {
  if (_tripsByShapeId == null) {
    _tripsByShapeId = mapToValueList(getAllTrips(), "shapeId",
        AgencyAndId.class);
  }
  return list(_tripsByShapeId.get(shapeId));
}
 
Example 22
Project: infotranspub-backend   File: GtfsRelationalDaoImpl.java   View source code 5 votes vote down vote up
@Override
public List<Trip> getTripsForServiceId(AgencyAndId serviceId) {
  if (_tripsByServiceId == null) {
    _tripsByServiceId = mapToValueList(getAllTrips(), "serviceId",
        AgencyAndId.class);
  }
  return list(_tripsByServiceId.get(serviceId));
}
 
Example 23
Project: infotranspub-backend   File: GtfsRelationalDaoImpl.java   View source code 5 votes vote down vote up
@Override
public List<Frequency> getFrequenciesForTrip(Trip trip) {
  if (_frequenciesByTrip == null)
    _frequenciesByTrip = mapToValueList(getAllFrequencies(), "trip",
        Trip.class);
  return list(_frequenciesByTrip.get(trip));
}
 
Example 24
Project: infotranspub-backend   File: GtfsRelationalDaoImplTest.java   View source code 5 votes vote down vote up
@Test
public void testTestAgency() throws IOException {
  String agencyId = "agency";
  GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
  GtfsTestData.readGtfs(dao, GtfsTestData.getTestAgencyGtfs(), agencyId);
  List<Trip> trips = dao.getTripsForBlockId(new AgencyAndId(agencyId, "block.1"));
  assertEquals(2, trips.size());
}
 
Example 25
Project: gtfsview   File: GtfsViewController.java   View source code 5 votes vote down vote up
public Collection<AgencyAndId> getShapesForAgency(Agency agency) {
    Set<AgencyAndId> agencyShapes = new HashSet<>();

    for (Route r : dao.getRoutesForAgency(agency)) {
        for (Trip t : dao.getTripsForRoute(r)) {
            AgencyAndId shapeId = t.getShapeId();
            if (shapeId != null) {
                agencyShapes.add(shapeId);
            }
        }
    }
    return agencyShapes;
}
 
Example 26
Project: gtfsview   File: GtfsViewController.java   View source code 5 votes vote down vote up
public Collection<AgencyAndId> getShapesForRoute(Route route) {
    Set<AgencyAndId> shapesForRoute = new HashSet<>();
    for (Trip t : dao.getTripsForRoute(route)) {
        if (t.getShapeId() != null) {
            shapesForRoute.add(t.getShapeId());
        }
    }
    return shapesForRoute;
}
 
Example 27
Project: gtfsview   File: GtfsViewController.java   View source code 5 votes vote down vote up
public Collection<AgencyAndId> getShapeForTrip(Trip trip) {
    AgencyAndId shapeId = trip.getShapeId();
    if (shapeId != null) {
        return Collections.singleton(shapeId);
    } else {
        return Collections.EMPTY_LIST;
    }

}
 
Example 28
Project: gtfsview   File: GtfsViewController.java   View source code 5 votes vote down vote up
public Collection<Trip> getTripsForRouteAndShape(Route route, AgencyAndId shape) {
    Collection<Trip> tripsForRoute = dao.getTripsForRoute(route);
    List<Trip> tripsForRouteAndShape = new ArrayList<>(tripsForRoute.size());

    for (Trip t : tripsForRoute) {
        if (t.getShapeId() != null && t.getShapeId().equals(shape)) {
            tripsForRouteAndShape.add(t);
        }
    }

    return tripsForRouteAndShape;
}
 
Example 29
Project: gtfsview   File: GtfsViewController.java   View source code 5 votes vote down vote up
public Collection<Route> getRoutesForShape(AgencyAndId shape) {
    Collection<Trip> trips = dao.getTripsForShapeId(shape);
    Set<Route> routes = new HashSet<>();

    for (Trip t : trips) {
        routes.add(t.getRoute());
    }

    return routes;
}
 
Example 30
Project: gtfsview   File: GtfsViewMain.java   View source code 5 votes vote down vote up
private void tripListValueChanged(ListSelectionEvent evt) {//GEN-FIRST:event_tripListValueChanged
    refreshLists(evt);

    Trip selectedTrip = tripList.getSelectedValue();

    if (selectedTrip != null) {
        final Collection<StopTime> stopTimes = gvc.getStopTimesForTrip(selectedTrip);
        sttm.setStopTimes(stopTimes);

        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                ((JSObject) engine.executeScript("window")).call("addStopTimesToMap", new ArrayList<StopTime>(stopTimes));
            }
        });

    } else {
        sttm.setStopTimes(Collections.EMPTY_LIST);

        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                ((JSObject) engine.executeScript("window")).call("removeStopTimes");
            }
        });

    }
}
 
Example 31
Project: gtfs-validator   File: GtfsStatisticsService.java   View source code 5 votes vote down vote up
public Integer getTripCount(String agencyId) {
	int count = 0;
	Collection<Trip> trips = gtfsDao.getAllTrips();
	for (Trip trip : trips) {
		if (agencyId.equals(trip.getRoute().getAgency().getId())) {
			count++;
		}
	}
	return count;
}
 
Example 32
Project: gtfs-java   File: PlanGenerator.java   View source code 5 votes vote down vote up
/**
 * Add trip-related fields to a {@link Leg}.
 *
 * @param leg The leg to add the trip-related fields to
 * @param states The states that go with the leg
 */
private void addTripFields(Leg leg, State[] states) {
    Trip trip = states[states.length - 1].getBackTrip();
    
    if (trip != null) {
        Route route = trip.getRoute();
        Agency agency = route.getAgency();
        ServiceDay serviceDay = states[states.length - 1].getServiceDay();
        
        leg.agencyId = agency.getId();
        leg.agencyName = agency.getName();
        leg.agencyUrl = agency.getUrl();
        leg.headsign = states[states.length - 1].getBackDirection();
        leg.route = states[states.length - 1].getBackEdge().getName();
        leg.routeColor = route.getColor();
        leg.routeId = route.getId().getId();
        leg.routeLongName = route.getLongName();
        leg.routeShortName = route.getShortName();
        leg.routeTextColor = route.getTextColor();
        leg.routeType = route.getType();
        leg.tripId = trip.getId().getId();
        leg.tripShortName = trip.getTripShortName();
        leg.tripBlockId = trip.getBlockId();
        
        if (serviceDay != null) {
            leg.serviceDate = serviceDay.getServiceDate().getAsString();
        }
        
        if (leg.headsign == null) {
            leg.headsign = trip.getTripHeadsign();
        }
    }
}
 
Example 33
Project: gtfs-java   File: Timetable.java   View source code 5 votes vote down vote up
/**
 * Check transfer table rules. Given the last alight time from the State, return the boarding
 * time t0 adjusted for this particular trip's minimum transfer time, or -1 if boarding this
 * trip is not allowed. FIXME adjustedTime can legitimately be -1! But negative times might as
 * well be zero.
 */
private int adjustTimeForTransfer(State state, Stop currentStop, Trip trip, boolean boarding, ServiceDay serviceDay, int t0) {
    if (!state.isEverBoarded()) {
        // This is the first boarding not a transfer.
        return t0;
    }
    TransferTable transferTable = state.getOptions().getRoutingContext().transferTable;
    int transferTime = transferTable.getTransferTime(state.getPreviousStop(), currentStop, state.getPreviousTrip(), trip,
            boarding);
    // Check whether back edge is TimedTransferEdge
    if (state.getBackEdge() instanceof TimedTransferEdge) {
        // Transfer must be of type TIMED_TRANSFER
        if (transferTime != StopTransfer.TIMED_TRANSFER) { return -1; }
    }
    if (transferTime == StopTransfer.UNKNOWN_TRANSFER) { return t0; // no special rules, just
                                                                    // board
    }
    if (transferTime == StopTransfer.FORBIDDEN_TRANSFER) {
        // This transfer is forbidden
        return -1;
    }
    // There is a minimum transfer time to make this transfer. Ensure that it is respected.
    int minTime = serviceDay.secondsSinceMidnight(state.getLastAlightedTimeSeconds());
    if (boarding) {
        minTime += transferTime;
        if (minTime > t0) { return minTime; }
    } else {
        minTime -= transferTime;
        if (minTime < t0) { return minTime; }
    }
    return t0;
}
 
Example 34
Project: gtfs-java   File: RoutingRequest.java   View source code 5 votes vote down vote up
/**
 * tripIsBanned is a misnomer: this checks whether the agency or route are banned. banning of
 * individual trips is actually performed inside the trip search, in TripTimes.tripAcceptable.
 */
public boolean tripIsBanned(Trip trip) {
    /* check if agency is banned for this plan */
    if (this.bannedAgencies != null) {
        if (this.bannedAgencies.contains(trip.getId().getAgencyId())) { return true; }
    }
    
    /* check if route banned for this plan */
    if (this.bannedRoutes != null) {
        Route route = trip.getRoute();
        if (this.bannedRoutes.matches(route)) { return true; }
    }
    
    return false;
}
 
Example 35
Project: gtfs-java   File: SpecificTransfer.java   View source code 5 votes vote down vote up
public SpecificTransfer(Route fromRoute, Route toRoute, Trip fromTrip, Trip toTrip, int transferTime) {
    if (fromRoute != null) {
        this.fromRouteId = fromRoute.getId();
    }
    else {
        this.fromRouteId = null;
    }
    
    if (toRoute != null) {
        this.toRouteId = toRoute.getId();
    }
    else {
        this.toRouteId = null;
    }
    
    if (fromTrip != null) {
        this.fromTripId = fromTrip.getId();
    }
    else {
        this.fromTripId = null;
    }
    
    if (toTrip != null) {
        this.toTripId = toTrip.getId();
    }
    else {
        this.toTripId = null;
    }

    this.transferTime = transferTime;
}
 
Example 36
Project: gtfs-java   File: TripTimes.java   View source code 5 votes vote down vote up
/**
 * The provided stopTimes are assumed to be pre-filtered, valid, and monotonically increasing.
 * The non-interpolated stoptimes should already be marked at timepoints by a previous filtering
 * step.
 */
public TripTimes(Trip trip, List<StopTime> stopTimes, Deduplicator deduplicator) {
    this.trip = trip;
    int nStops = stopTimes.size();
    int[] departures = new int[nStops];
    int[] arrivals = new int[nStops];
    int[] sequences = new int[nStops];
    BitSet timepoints = new BitSet(nStops);
    // Times are always shifted to zero. This is essential for frequencies and deduplication.
    this.timeShift = stopTimes.get(0).getArrivalTime();
    int s = 0;
    for (StopTime st : stopTimes) {
        departures[s] = st.getDepartureTime() - this.timeShift;
        arrivals[s] = st.getArrivalTime() - this.timeShift;
        sequences[s] = st.getStopSequence();
        timepoints.set(s, st.getTimepoint() == 1);
        s++;
    }
    this.scheduledDepartureTimes = deduplicator.deduplicateIntArray(departures);
    this.scheduledArrivalTimes = deduplicator.deduplicateIntArray(arrivals);
    this.stopSequences = deduplicator.deduplicateIntArray(sequences);
    this.headsigns = deduplicator.deduplicateStringArray(makeHeadsignsArray(stopTimes));
    // We set these to null to indicate that this is a non-updated/scheduled TripTimes.
    // We cannot point to the scheduled times because they are shifted, and updated times are
    // not.
    this.arrivalTimes = null;
    this.departureTimes = null;
    this.timepoints = deduplicator.deduplicateBitSet(timepoints);
    LOG.trace("trip {} has timepoint at indexes {}", trip, timepoints);
}
 
Example 37
Project: gtfs-java   File: State.java   View source code 5 votes vote down vote up
/**
 * Get the back trip of the given state. For time dependent transit, State will find the right
 * thing to do.
 */
public Trip getBackTrip() {
    if (this.backEdge instanceof TablePatternEdge) {
        return this.stateData.tripTimes.trip;
    } else {
        return this.backEdge.getTrip();
    }
}
 
Example 38
Project: gtfs-java   File: TripTimeShort.java   View source code 5 votes vote down vote up
/**
 * must pass in both table and trip, because tripTimes do not have stops.
 */
public static List<TripTimeShort> fromTripTimes(Timetable table, Trip trip) {
    TripTimes times = table.getTripTimes(table.getTripIndex(trip.getId()));
    List<TripTimeShort> out = Lists.newArrayList();
    // one per stop, not one per hop, thus the <= operator
    for (int i = 0; i < times.getNumStops(); ++i) {
        out.add(new TripTimeShort(times, i, table.pattern.getStop(i)));
    }
    return out;
}
 
Example 39
Project: gtfs-java   File: TransferTable.java   View source code 5 votes vote down vote up
/**
 * Get the transfer time that should be used when transferring from a trip to another trip. Note
 * that this function does not check whether another specific transfer exists with the same
 * specificity, what is forbidden by the specifications.
 * 
 * @param fromStopId is the id of the arriving stop
 * @param toStopId is the id of the departing stop
 * @param fromTrip is the arriving trip
 * @param toTrip is the departing trip
 * @return the transfer time in seconds. May contain special (negative) values which meaning can
 *         be found in the StopTransfer.*_TRANSFER constants. If no transfer is found,
 *         StopTransfer.UNKNOWN_TRANSFER is returned.
 */
private int getTransferTime(AgencyAndId fromStopId, AgencyAndId toStopId, Trip fromTrip, Trip toTrip) {
    checkNotNull(fromStopId);
    checkNotNull(toStopId);

    // Define transfer time to return
    int transferTime = StopTransfer.UNKNOWN_TRANSFER;
    // Lookup transfer between two stops
    StopTransfer stopTransfer = this.table.get(new P2<AgencyAndId>(fromStopId, toStopId));
    if (stopTransfer != null) {
        // Lookup correct transfer time between two stops and two trips
        transferTime = stopTransfer.getTransferTime(fromTrip, toTrip);
    }
    return transferTime;
}
 
Example 40
Project: gtfs-java   File: TripPattern.java   View source code 5 votes vote down vote up
public void dumpServices() {
    Set<AgencyAndId> services = Sets.newHashSet();
    for (Trip trip : this.trips) {
        services.add(trip.getServiceId());
    }
    LOG.info("route {} : {}", this.route, services);
}