private void fixupTransitLeg(Leg leg, State state, TransitIndexService transitIndex) {
    Edge en = state.getBackEdge();
    leg.route = en.getName();
    Trip trip = state.getBackTrip();
    leg.headsign = state.getBackDirection();
    if (trip != null) {
      // this is the stop headsign
      // leg.headsign = "This is the headsign";
      // handle no stop headsign
      if (leg.headsign == null) leg.headsign = trip.getTripHeadsign();

      leg.tripId = trip.getId().getId();
      leg.agencyId = trip.getId().getAgencyId();
      leg.tripShortName = trip.getTripShortName();
      leg.routeShortName = trip.getRoute().getShortName();
      leg.routeLongName = trip.getRoute().getLongName();
      leg.routeColor = trip.getRoute().getColor();
      leg.routeTextColor = trip.getRoute().getTextColor();
      leg.routeId = trip.getRoute().getId().getId();
      if (transitIndex != null) {
        Agency agency = transitIndex.getAgency(leg.agencyId);
        leg.agencyName = agency.getName();
        leg.agencyUrl = agency.getUrl();
      }
    }
    leg.mode = state.getBackMode().toString();
    leg.startTime = makeCalendar(state.getBackState());
  }
 private void transitIndexWithBreakRequired(TransitIndexService transitIndex) {
   transitIndexRequired(transitIndex);
   if (transitIndex.getOvernightBreak() == -1) {
     throw new RuntimeException(
         "TransitIndexBuilder could not find an overnight break "
             + "in the transit schedule; first/last trips are undefined");
   }
 }
  /** Returns the first trip of the service day. */
  public TripPlan generateFirstTrip(RoutingRequest request) {
    Graph graph = graphService.getGraph(request.getRouterId());

    TransitIndexService transitIndex = graph.getService(TransitIndexService.class);
    transitIndexWithBreakRequired(transitIndex);

    request.setArriveBy(false);

    TimeZone tz = graph.getTimeZone();

    GregorianCalendar calendar = new GregorianCalendar(tz);
    calendar.setTimeInMillis(request.dateTime * 1000);
    calendar.set(Calendar.HOUR, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.AM_PM, 0);
    calendar.set(Calendar.SECOND, transitIndex.getOvernightBreak());

    request.dateTime = calendar.getTimeInMillis() / 1000;
    return generate(request);
  }
 public RoutingContext(
     RoutingRequest traverseOptions, Graph graph, Vertex from, Vertex to, boolean findPlaces) {
   this.opt = traverseOptions;
   this.graph = graph;
   if (findPlaces) {
     // normal mode, search for vertices based on fromPlace and toPlace
     fromVertex = graph.streetIndex.getVertexForPlace(opt.getFromPlace(), opt);
     toVertex = graph.streetIndex.getVertexForPlace(opt.getToPlace(), opt, fromVertex);
     if (opt.intermediatePlaces != null) {
       for (NamedPlace intermediate : opt.intermediatePlaces) {
         Vertex vertex = graph.streetIndex.getVertexForPlace(intermediate, opt);
         intermediateVertices.add(vertex);
       }
     }
   } else {
     // debug mode, force endpoint vertices to those specified rather than searching
     fromVertex = from;
     toVertex = to;
   }
   if (opt.getStartingTransitStopId() != null) {
     TransitIndexService tis = graph.getService(TransitIndexService.class);
     if (tis == null) {
       throw new RuntimeException(
           "Next/Previous/First/Last trip "
               + "functionality depends on the transit index. Rebuild "
               + "the graph with TransitIndexBuilder");
     }
     AgencyAndId stopId = opt.getStartingTransitStopId();
     startingStop = tis.getPreBoardEdge(stopId).getToVertex();
   }
   origin = opt.arriveBy ? toVertex : fromVertex;
   target = opt.arriveBy ? fromVertex : toVertex;
   calendarService = graph.getCalendarService();
   transferTable = graph.getTransferTable();
   timetableSnapshot = null;
   setServiceDays();
   if (opt.batch) remainingWeightHeuristic = new TrivialRemainingWeightHeuristic();
   else remainingWeightHeuristic = heuristicFactory.getInstanceForSearch(opt);
 }
 private void fixupTransitLeg(Leg leg, State state, TransitIndexService transitIndex) {
   EdgeNarrative en = state.getBackEdgeNarrative();
   leg.route = en.getName();
   Trip trip = en.getTrip();
   if (trip != null) {
     leg.headsign = trip.getTripHeadsign();
     leg.tripId = trip.getId().getId();
     leg.agencyId = trip.getId().getAgencyId();
     leg.tripShortName = trip.getTripShortName();
     leg.routeShortName = trip.getRoute().getShortName();
     leg.routeLongName = trip.getRoute().getLongName();
     leg.routeColor = trip.getRoute().getColor();
     leg.routeTextColor = trip.getRoute().getTextColor();
     if (transitIndex != null) {
       Agency agency = transitIndex.getAgency(leg.agencyId);
       leg.agencyName = agency.getName();
       leg.agencyUrl = agency.getUrl();
     }
   }
   leg.mode = en.getMode().toString();
   leg.startTime = makeCalendar(state.getBackState());
 }