@@ -18,32 +18,34 @@ public static GtfsRealtime.TripUpdate.StopTimeUpdate newStopTimeUpdate(InternalM
1818 }
1919
2020 public static GtfsRealtime .TripUpdate .StopTimeUpdate newStopTimeUpdateFromPrevious (
21- final InternalMessages .StopEstimate stopEstimate ,
22- GtfsRealtime .TripUpdate .StopTimeUpdate previousUpdate ) {
21+ final InternalMessages .StopEstimate stopEstimate , GtfsRealtime .TripUpdate .StopTimeUpdate previousUpdate ) {
2322
2423 GtfsRealtime .TripUpdate .StopTimeUpdate .Builder stopTimeUpdateBuilder = null ;
2524 if (previousUpdate != null ) {
2625 stopTimeUpdateBuilder = previousUpdate .toBuilder ();
2726 } else {
2827 String stopId = stopEstimate .getStopId ();
2928 int stopSequence = stopEstimate .getStopSequence ();
30- stopTimeUpdateBuilder = GtfsRealtime .TripUpdate .StopTimeUpdate .newBuilder ()
31- .setStopId (stopId )
29+ stopTimeUpdateBuilder = GtfsRealtime .TripUpdate .StopTimeUpdate .newBuilder ().setStopId (stopId )
3230 .setStopSequence (stopSequence );
3331 }
3432
3533 switch (stopEstimate .getStatus ()) {
36- case SKIPPED :
37- stopTimeUpdateBuilder .setScheduleRelationship (GtfsRealtime .TripUpdate .StopTimeUpdate .ScheduleRelationship .SKIPPED );
34+ case SKIPPED :
35+ stopTimeUpdateBuilder
36+ .setScheduleRelationship (GtfsRealtime .TripUpdate .StopTimeUpdate .ScheduleRelationship .SKIPPED );
3837 break ;
39- case SCHEDULED :
40- stopTimeUpdateBuilder .setScheduleRelationship (GtfsRealtime .TripUpdate .StopTimeUpdate .ScheduleRelationship .SCHEDULED );
38+ case SCHEDULED :
39+ stopTimeUpdateBuilder
40+ .setScheduleRelationship (GtfsRealtime .TripUpdate .StopTimeUpdate .ScheduleRelationship .SCHEDULED );
4141 break ;
42- case NO_DATA :
42+ case NO_DATA :
4343 //If there is no data for current or previous stop time update, set ScheduleRelationship to NO_DATA
44- if (previousUpdate == null || previousUpdate .getScheduleRelationship () == GtfsRealtime .TripUpdate .StopTimeUpdate .ScheduleRelationship .NO_DATA ) {
45- stopTimeUpdateBuilder .setScheduleRelationship (GtfsRealtime .TripUpdate .StopTimeUpdate .ScheduleRelationship .NO_DATA );
46- //Otherwise use ScheduleRelationship of previous stop time update
44+ if (previousUpdate == null || previousUpdate
45+ .getScheduleRelationship () == GtfsRealtime .TripUpdate .StopTimeUpdate .ScheduleRelationship .NO_DATA ) {
46+ stopTimeUpdateBuilder .setScheduleRelationship (
47+ GtfsRealtime .TripUpdate .StopTimeUpdate .ScheduleRelationship .NO_DATA );
48+ //Otherwise use ScheduleRelationship of previous stop time update
4749 } else {
4850 stopTimeUpdateBuilder .setScheduleRelationship (previousUpdate .getScheduleRelationship ());
4951 }
@@ -54,8 +56,8 @@ public static GtfsRealtime.TripUpdate.StopTimeUpdate newStopTimeUpdateFromPrevio
5456 // GTFS-RT treats times in seconds
5557 long stopEventTimeInSeconds = stopEstimate .getEstimatedTimeUtcMs () / 1000 ;
5658
57- GtfsRealtime .TripUpdate .StopTimeEvent .Builder stopTimeEvent = GtfsRealtime .TripUpdate .StopTimeEvent . newBuilder ()
58- .setTime (stopEventTimeInSeconds );
59+ GtfsRealtime .TripUpdate .StopTimeEvent .Builder stopTimeEvent = GtfsRealtime .TripUpdate .StopTimeEvent
60+ .newBuilder (). setTime (stopEventTimeInSeconds );
5961
6062 //Whether the event was observed in real world (i.e. not an estimate)
6163 final boolean observedTime = stopEstimate .hasObservedTime () && stopEstimate .getObservedTime ();
@@ -64,10 +66,10 @@ public static GtfsRealtime.TripUpdate.StopTimeUpdate newStopTimeUpdateFromPrevio
6466 }
6567
6668 switch (stopEstimate .getType ()) {
67- case ARRIVAL :
69+ case ARRIVAL :
6870 stopTimeUpdateBuilder .setArrival (stopTimeEvent );
6971 break ;
70- case DEPARTURE :
72+ case DEPARTURE :
7173 stopTimeUpdateBuilder .setDeparture (stopTimeEvent );
7274 break ;
7375 }
@@ -83,54 +85,50 @@ public static long lastModified(InternalMessages.StopEstimate estimate) {
8385 public static GtfsRealtime .TripUpdate newTripUpdate (InternalMessages .StopEstimate estimate ) {
8486 final int direction = PubtransFactory .joreDirectionToGtfsDirection (estimate .getTripInfo ().getDirectionId ());
8587 String routeId = RouteIdUtils .normalizeRouteId (estimate .getTripInfo ().getRouteId ());
86-
87- GtfsRealtime .TripDescriptor .ScheduleRelationship scheduleType = mapInternalScheduleTypeToGtfsRt (estimate .getTripInfo ().getScheduleType ());
88-
88+
89+ GtfsRealtime .TripDescriptor .ScheduleRelationship scheduleType = mapInternalScheduleTypeToGtfsRt (
90+ estimate .getTripInfo ().getScheduleType ());
91+
8992 GtfsRealtime .TripDescriptor .Builder tripDescriptor = GtfsRealtime .TripDescriptor .newBuilder ()
90- .setRouteId (routeId )
91- .setDirectionId (direction )
92- .setStartDate (estimate .getTripInfo ().getOperatingDay ()) // Local date as String
93+ .setRouteId (routeId ).setDirectionId (direction ).setStartDate (estimate .getTripInfo ().getOperatingDay ()) // Local date as String
9394 .setStartTime (estimate .getTripInfo ().getStartTime ()) // Local time as String
9495 .setScheduleRelationship (scheduleType );
95-
96+
9697 //Trips outside of static schedule need trip ID to be accepted by OTP
9798 if (scheduleType != GtfsRealtime .TripDescriptor .ScheduleRelationship .SCHEDULED ) {
9899 tripDescriptor .setTripId (generateTripId (estimate .getTripInfo ()));
99100 }
100101
101- GtfsRealtime .TripUpdate .Builder tripUpdateBuilder = GtfsRealtime .TripUpdate .newBuilder ()
102- .setTrip (tripDescriptor )
102+ GtfsRealtime .TripUpdate .Builder tripUpdateBuilder = GtfsRealtime .TripUpdate .newBuilder ().setTrip (tripDescriptor )
103103 .setTimestamp (lastModified (estimate ));
104104
105105 return tripUpdateBuilder .build ();
106106 }
107107
108- private static GtfsRealtime .TripDescriptor .ScheduleRelationship mapInternalScheduleTypeToGtfsRt (InternalMessages .TripInfo .ScheduleType scheduleType ) {
108+ private static GtfsRealtime .TripDescriptor .ScheduleRelationship mapInternalScheduleTypeToGtfsRt (
109+ InternalMessages .TripInfo .ScheduleType scheduleType ) {
109110 switch (scheduleType ) {
110- case ADDED :
111+ case ADDED :
111112 return GtfsRealtime .TripDescriptor .ScheduleRelationship .ADDED ;
112- case UNSCHEDULED :
113+ case UNSCHEDULED :
113114 return GtfsRealtime .TripDescriptor .ScheduleRelationship .UNSCHEDULED ;
114- case SCHEDULED :
115- default :
115+ case SCHEDULED :
116+ default :
116117 return GtfsRealtime .TripDescriptor .ScheduleRelationship .SCHEDULED ;
117118 }
118119 }
119120
120- public static GtfsRealtime .TripUpdate newTripUpdate (InternalMessages .TripCancellation cancellation , long timestampMs ) {
121+ public static GtfsRealtime .TripUpdate newTripUpdate (InternalMessages .TripCancellation cancellation ,
122+ long timestampMs ) {
121123 final int gtfsRtDirection = PubtransFactory .joreDirectionToGtfsDirection (cancellation .getDirectionId ());
122124 String routeId = RouteIdUtils .normalizeRouteId (cancellation .getRouteId ());
123125
124- GtfsRealtime .TripDescriptor tripDescriptor = GtfsRealtime .TripDescriptor .newBuilder ()
125- .setRouteId (routeId )
126- .setDirectionId (gtfsRtDirection )
127- .setStartDate (cancellation .getStartDate ())
126+ GtfsRealtime .TripDescriptor tripDescriptor = GtfsRealtime .TripDescriptor .newBuilder ().setRouteId (routeId )
127+ .setDirectionId (gtfsRtDirection ).setStartDate (cancellation .getStartDate ())
128128 .setStartTime (cancellation .getStartTime ())
129- .setScheduleRelationship (GtfsRealtime .TripDescriptor .ScheduleRelationship .CANCELED )
130- .build ();
129+ .setScheduleRelationship (GtfsRealtime .TripDescriptor .ScheduleRelationship .CANCELED ).build ();
131130
132- GtfsRealtime .TripUpdate .Builder tripUpdateBuilder = GtfsRealtime .TripUpdate .newBuilder ()
133- .setTrip (tripDescriptor )
131+ GtfsRealtime .TripUpdate .Builder tripUpdateBuilder = GtfsRealtime .TripUpdate .newBuilder ().setTrip (tripDescriptor )
134132 .setTimestamp (timestampMs / 1000 );
135133
136134 return tripUpdateBuilder .build ();
@@ -142,6 +140,7 @@ public static GtfsRealtime.TripUpdate newTripUpdate(InternalMessages.TripCancell
142140 * @return Trip ID
143141 */
144142 private static String generateTripId (InternalMessages .TripInfo tripInfo ) {
145- return tripInfo .getRouteId ()+"_" +tripInfo .getOperatingDay ()+"_" +tripInfo .getStartTime ()+"_" +tripInfo .getDirectionId ();
143+ return tripInfo .getRouteId () + "_" + tripInfo .getOperatingDay () + "_" + tripInfo .getStartTime () + "_"
144+ + tripInfo .getDirectionId ();
146145 }
147146}
0 commit comments