Package com.google.transit.realtime.GtfsRealtime.TripUpdate

Examples of com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate


                Iterator<StopTimeUpdate> updates = tripUpdate.getStopTimeUpdateList().iterator();
                if (!updates.hasNext()) {
                    LOG.warn("Won't apply zero-length trip update to trip {}.", tripId);
                    return false;
                }
                StopTimeUpdate update = updates.next();

                int numStops = newTimes.getNumStops();
                Integer delay = null;

                for (int i = 0; i < numStops; i++) {
                    boolean match = false;
                    if (update != null) {
                        if (update.hasStopSequence()) {
                            match = update.getStopSequence() == newTimes.getStopSequence(i);
                        } else if (update.hasStopId()) {
                            match = pattern.getStop(i).getId().getId().equals(update.getStopId());
                        }
                    }

                    if (match) {
                        StopTimeUpdate.ScheduleRelationship scheduleRelationship =
                                update.hasScheduleRelationship() ? update.getScheduleRelationship()
                                : StopTimeUpdate.ScheduleRelationship.SCHEDULED;
                        if (scheduleRelationship == StopTimeUpdate.ScheduleRelationship.SKIPPED) {
                            // TODO: Handle partial trip cancellations
                            LOG.warn("Partially canceled trips are currently unsupported." +
                                    " Skipping TripUpdate.");
                            return false;
                        } else if (scheduleRelationship ==
                                StopTimeUpdate.ScheduleRelationship.NO_DATA) {
                            newTimes.updateArrivalDelay(i, 0);
                            newTimes.updateDepartureDelay(i, 0);
                            delay = 0;
                        } else {
                            long today = updateServiceDate.getAsDate(timeZone).getTime() / 1000;

                            if (update.hasArrival()) {
                                StopTimeEvent arrival = update.getArrival();
                                if (arrival.hasDelay()) {
                                    delay = arrival.getDelay();
                                    if (arrival.hasTime()) {
                                        newTimes.updateArrivalTime(i,
                                                (int) (arrival.getTime() - today));
                                    } else {
                                        newTimes.updateArrivalDelay(i, delay);
                                    }
                                } else if (arrival.hasTime()) {
                                    newTimes.updateArrivalTime(i,
                                            (int) (arrival.getTime() - today));
                                    delay = newTimes.getArrivalDelay(i);
                                } else {
                                    LOG.error("Arrival time at index {} is erroneous.", i);
                                    return false;
                                }
                            } else {
                                if (delay == null) {
                                    newTimes.updateArrivalTime(i, TripTimes.UNAVAILABLE);
                                } else {
                                    newTimes.updateArrivalDelay(i, delay);
                                }
                            }

                            if (update.hasDeparture()) {
                                StopTimeEvent departure = update.getDeparture();
                                if (departure.hasDelay()) {
                                    delay = departure.getDelay();
                                    if (departure.hasTime()) {
                                        newTimes.updateDepartureTime(i,
                                                (int) (departure.getTime() - today));
View Full Code Here


    }

    if (tripUpdate.getStopTimeUpdateCount() == 0)
      return false;

    StopTimeUpdate stopTimeUpdate = tripUpdate.getStopTimeUpdate(0);
    if (!(stopTimeUpdate.hasArrival() || stopTimeUpdate.hasDeparture()))
      return false;

    boolean hasDelay = false;
    if (stopTimeUpdate.hasDeparture()) {
      StopTimeEvent departure = stopTimeUpdate.getDeparture();
      hasDelay |= departure.hasDelay();
      hasDelay |= departure.hasTime();
    }
    if (stopTimeUpdate.hasArrival()) {
      StopTimeEvent arrival = stopTimeUpdate.getArrival();
      hasDelay |= arrival.hasDelay();
      hasDelay |= arrival.hasTime();
    }
    return hasDelay;
  }
View Full Code Here

      assertEquals("t0", tripUpdate.getTrip().getTripId());
      assertEquals("r1", tripUpdate.getTrip().getRouteId());
      assertEquals("v1", tripUpdate.getVehicle().getId());
      assertEquals(1234, tripUpdate.getTimestamp());
      assertEquals(1, tripUpdate.getStopTimeUpdateCount());
      StopTimeUpdate stopTimeUpdate = tripUpdate.getStopTimeUpdate(0);
      assertEquals("s2", stopTimeUpdate.getStopId());
      assertEquals(now / 1000 + 5 * 60, stopTimeUpdate.getDeparture().getTime());
    }
    {
      FeedEntity entity = feed.getEntity(1);
      assertEquals("2", entity.getId());
      TripUpdate tripUpdate = entity.getTripUpdate();
      assertEquals("t1", tripUpdate.getTrip().getTripId());
      assertEquals("r1", tripUpdate.getTrip().getRouteId());
      assertEquals("v2", tripUpdate.getVehicle().getId());
      assertEquals(5678, tripUpdate.getTimestamp());
      assertEquals(1, tripUpdate.getStopTimeUpdateCount());
      StopTimeUpdate stopTimeUpdate = tripUpdate.getStopTimeUpdate(0);
      assertEquals("s3", stopTimeUpdate.getStopId());
      assertEquals(now / 1000 + 10 * 60,
          stopTimeUpdate.getDeparture().getTime());
    }
  }
View Full Code Here

TOP

Related Classes of com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate

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.