Package org.onebusaway.transit_data.model.tripplanning

Examples of org.onebusaway.transit_data.model.tripplanning.LegBean


    BlockTripInstance blockTripInstanceFrom = builder.getBlockTripInstanceFrom();

    if (blockTripInstanceFrom == null)
      return new TransitLegBuilder();

    LegBean leg = createTransitLegFromBuilder(builder);
    legs.add(leg);

    return new TransitLegBuilder();
  }
View Full Code Here


  private LegBean createTransitLegFromBuilder(TransitLegBuilder builder) {

    BlockTripInstance blockTripInstanceFrom = builder.getBlockTripInstanceFrom();

    LegBean leg = new LegBean();

    leg.setStartTime(builder.getBestDepartureTime());
    leg.setEndTime(builder.getBestArrivalTime());

    double distance = getTransitLegBuilderAsDistance(builder);
    leg.setDistance(distance);

    leg.setMode(MODE_TRANSIT);

    TripEntry trip = blockTripInstanceFrom.getBlockTrip().getTrip();

    TransitLegBean transitLeg = new TransitLegBean();
    leg.setTransitLeg(transitLeg);

    transitLeg.setServiceDate(blockTripInstanceFrom.getServiceDate());

    FrequencyEntry frequencyLabel = blockTripInstanceFrom.getFrequencyLabel();
    if (frequencyLabel != null) {
      FrequencyBean frequency = FrequencyBeanLibrary.getBeanForFrequency(
          blockTripInstanceFrom.getServiceDate(), frequencyLabel);
      transitLeg.setFrequency(frequency);
    }

    TripBean tripBean = _tripBeanService.getTripForId(trip.getId());
    transitLeg.setTrip(tripBean);

    transitLeg.setScheduledDepartureTime(builder.getScheduledDepartureTime());
    transitLeg.setScheduledArrivalTime(builder.getScheduledArrivalTime());

    transitLeg.setPredictedDepartureTime(builder.getPredictedDepartureTime());
    transitLeg.setPredictedArrivalTime(builder.getPredictedArrivalTime());

    String path = getTransitLegBuilderAsPath(builder);
    transitLeg.setPath(path);

    applyFromStopDetailsForTransitLeg(builder, transitLeg, leg);
    applyToStopDetailsForTransitLeg(builder, transitLeg, leg);

    if (leg.getFrom() == null || leg.getTo() == null && path != null) {
      List<CoordinatePoint> points = PolylineEncoder.decode(path);
      if (leg.getFrom() == null)
        leg.setFrom(points.get(0));
      if (leg.getTo() == null)
        leg.setTo(points.get(points.size() - 1));
    }

    return leg;
  }
View Full Code Here

    }

    addPathToStreetLegIfApplicable(streetLeg, path, distance);

    LegBean leg = new LegBean();
    legs.add(leg);

    leg.setStartTime(startTime);
    leg.setEndTime(endTime);

    leg.setMode(getStreetModeAsString(mode));

    leg.setFrom(from);
    leg.setTo(to);
    leg.setDistance(totalDistance);

    leg.setStreetLegs(streetLegs);
  }
View Full Code Here

    /**
     * Update the legs
     */
    for (int i = 0; i < legs.size(); i++) {

      LegBean leg = legs.get(i);
      TransitLegBean transitLeg = leg.getTransitLeg();

      if (transitLeg != null) {
        LegBean updatedLeg = updateTransitLeg(transitLeg, options);
        legs.set(i, updatedLeg);

        if (firstTransitLegIndex == -1)
          firstTransitLegIndex = i;

      } else if (isStreetLeg(leg)) {

        Date time = new Date(targetTime);

        CoordinatePoint walkFrom = leg.getFrom();
        CoordinatePoint walkTo = leg.getTo();

        /**
         * Adjust the start and end locations for walk-legs to match the query
         * points. This is a hack, since it allows the client to pass in the
         * original unmodified itinerary from a previous to call, but also
         * slightly change their start or end point (aka user walks some
         * distance) without having to understand how to update the itinerary
         * object itself.
         */
        if (i == 0)
          walkFrom = from.getLocation();
        if (i + 1 == legs.size())
          walkTo = to.getLocation();

        GraphPath path = _itinerariesService.getWalkingItineraryBetweenPoints(
            walkFrom, walkTo, time, options);

        if (path == null) {
          throw new IllegalStateException("expected walking path to exist");
        }

        ItineraryBean walkItinerary = getPathAsItinerary(path, options);
        legs.set(i, walkItinerary.getLegs().get(0));
      }
    }

    /**
     * Update the times
     */
    if (firstTransitLegIndex == -1) {

    } else {

      long nextTime = legs.get(firstTransitLegIndex).getStartTime();
      for (int i = firstTransitLegIndex - 1; i >= 0; i--) {

        LegBean leg = legs.get(i);
        if (isStreetLeg(leg)) {
          long duration = leg.getEndTime() - leg.getStartTime();
          leg.setEndTime(nextTime);
          leg.setStartTime(nextTime - duration);
        }

        nextTime = leg.getStartTime();
      }

      long prevTime = legs.get(firstTransitLegIndex).getEndTime();
      for (int i = firstTransitLegIndex + 1; i < legs.size(); i++) {

        LegBean leg = legs.get(i);
        if (isStreetLeg(leg)) {
          long duration = leg.getEndTime() - leg.getStartTime();
          leg.setStartTime(prevTime);
          leg.setEndTime(prevTime + duration);
        }

        prevTime = leg.getEndTime();
      }

      itinerary.setStartTime(nextTime);
      itinerary.setEndTime(prevTime);
    }
View Full Code Here

    itinerary.setProbability(bean.getProbability());
    List<LegV2Bean> legBeans = bean.getLegs();
    if (!CollectionsLibrary.isEmpty(legBeans)) {
      List<LegBean> legs = new ArrayList<LegBean>();
      for (LegV2Bean legBean : legBeans) {
        LegBean leg = reverseLeg(legBean);
        legs.add(leg);
      }
      itinerary.setLegs(legs);
    }
    return itinerary;
View Full Code Here

    return bean;
  }

  public LegBean reverseLeg(LegV2Bean bean) {

    LegBean leg = new LegBean();

    leg.setStartTime(bean.getStartTime());
    leg.setEndTime(bean.getEndTime());
    leg.setFrom(_factory.reversePoint(bean.getFrom()));
    leg.setTo(_factory.reversePoint(bean.getTo()));
    leg.setDistance(bean.getDistance());
    if (_factory.isStringSet(bean.getMode()))
      leg.setMode(bean.getMode());

    TransitLegV2Bean transitLegBean = bean.getTransitLeg();
    if (transitLegBean != null) {
      TransitLegBean transitLeg = reverseTransitLeg(transitLegBean);
      leg.setTransitLeg(transitLeg);
    }

    List<StreetLegV2Bean> streetLegBeans = bean.getStreetLegs();
    if (!CollectionsLibrary.isEmpty(streetLegBeans)) {
      List<StreetLegBean> streetLegs = new ArrayList<StreetLegBean>();
      for (StreetLegV2Bean streetLegBean : streetLegBeans) {
        StreetLegBean streetLeg = reverseStreetLeg(streetLegBean);
        streetLegs.add(streetLeg);
      }
      leg.setStreetLegs(streetLegs);
    }

    return leg;
  }
View Full Code Here

        _css.tripPanelSummaryTrip()));
    summaryPanel.add(new DivWidget("Travel time: about " + duration,
        _css.tripPanelSummaryDuration()));

    for (int i = 0; i < legs.size(); i++) {
      LegBean leg = legs.get(i);

      String mode = leg.getMode();
      if( mode.equals("transit")) {

        TransitLegBean transitLeg = leg.getTransitLeg();
        TripBean tripBean = transitLeg.getTrip();
        RouteBean routeBean = tripBean.getRoute();

        DivPanel panel = new DivPanel();
        panel.addStyleName(_css.tripPanelVehiclePanel());

        DivPanel row1 = new DivPanel(_css.tripPanelVehiclePanelRow1());
        panel.add(row1);

        DataResource busIcon = resources.getBusTripTypeIcon();
        Image image = new Image(busIcon.getUrl());
        image.addStyleName(_css.tripPanelVehiclePanelModeImage());
        row1.add(image);

        int minutes = Math.round((leg.getEndTime() - leg.getStartTime())
            / (1000 * 60));
       
        String routeShortName = getBestName(transitLeg.getRouteShortName(),tripBean.getRouteShortName(), routeBean.getShortName(),"");
        String tripHeadsign = getBestName(transitLeg.getTripHeadsign(),tripBean.getTripHeadsign(),routeBean.getLongName(),"");
       
        row1.add(new DivWidget("Bus - " + routeShortName + " - "
            + tripHeadsign, _css.tripPanelVehiclePanelTitle()));

        String departureTime = _timeFormat.format(new Date(leg.getStartTime()));
        String arrivalTime = _timeFormat.format(new Date(leg.getEndTime()));

        DivPanel row2 = new DivPanel(_css.tripPanelVehiclePanelRow2());
        panel.add(row2);

        DivPanel row3 = new DivPanel(_css.tripPanelVehiclePanelRow3());
        panel.add(row3);

        DivPanel row4 = new DivPanel(_css.tripPanelVehiclePanelRow4());
        panel.add(row4);
       
        String fromStopName = "";
        StopBean fromStop = transitLeg.getFromStop();
        if( fromStop != null)
          fromStopName = fromStop.getName();
       
        String toStopName = "";
        StopBean toStop = transitLeg.getToStop();
        if( toStop != null)
          toStopName = toStop.getName();

        row2.add(new DivWidget(departureTime,
            _css.tripPlanVehiclePanelDepartureTime(),
            _css.tripPlanVehiclePanelA()));
        row2.add(new DivWidget("Depart " + fromStopName,
            _css.tripPlanVehiclePanelDepartureLabel(),
            _css.tripPlanVehiclePanelB()));
        row3.add(new DivWidget("...",
            _css.tripPlanVehiclePanelInTransitLabel(),
            _css.tripPlanVehiclePanelA()));
        row3.add(new DivWidget(minutes + " mins",
            _css.tripPlanVehiclePanelInTransitTime(),
            _css.tripPlanVehiclePanelB()));
        row4.add(new DivWidget(arrivalTime,
            _css.tripPlanVehiclePanelArrivalLabel(),
            _css.tripPlanVehiclePanelA()));
        row4.add(new DivWidget("Arrive " + toStopName,
            _css.tripPlanVehiclePanelArrivalTime(),
            _css.tripPlanVehiclePanelB()));
        _panel.add(panel);

      } else if (mode.equals("walk")) {
       
        DivPanel panel = new DivPanel();
        panel.addStyleName(_css.tripPanelWalkPanel());

        DivPanel row1 = new DivPanel(_css.tripPanelWalkPanelRow1());
        panel.add(row1);

        DataResource walkIcon = resources.getWalkTripTypeIcon();
        Image image = new Image(walkIcon.getUrl());
        image.addStyleName(_css.tripPanelWalkPanelModeImage());
        row1.add(image);

        String target = getWalkToTarget(legs, i, destination);
        row1.add(new DivWidget("Walk to " + target,
            _css.tripPanelWalkPanelTitle()));

        DivPanel row2 = new DivPanel(_css.tripPanelWalkPanelRow2());
        panel.add(row2);
       
        long dur = leg.getEndTime() - leg.getStartTime();

        row2.add(new DivWidget("About "
            + TripBeanSupport.getDurationLabel(dur)));
        _panel.add(panel);
      }
View Full Code Here

  }

  private String getWalkToTarget(List<LegBean> legs, int i,
      String finalDestination) {
    for (; i < legs.size(); i++) {
      LegBean segment = legs.get(i);
      if( segment.getMode().equals("transit")) {
        TransitLegBean transitLeg = segment.getTransitLeg();
        if( transitLeg.getFromStop() != null)
          return transitLeg.getFromStop().getName();
      }
    }
View Full Code Here

TOP

Related Classes of org.onebusaway.transit_data.model.tripplanning.LegBean

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.