@@ -171,16 +171,19 @@ private static int[] findLeaveEdgesForTrip(GtfsStorage staticGtfs, String feedKe
171
171
Trip trip = feed .trips .get (tripUpdate .getTrip ().getTripId ());
172
172
StopTime next = feed .getOrderedStopTimesForTrip (trip .trip_id ).iterator ().next ();
173
173
int station = staticGtfs .getStationNodes ().get (new GtfsStorage .FeedIdWithStopId (feedKey , next .stop_id ));
174
- Optional <PtGraph .PtEdge > firstBoarding = StreamSupport .stream (staticGtfs .getPtGraph ().backEdgesAround (station ).spliterator (), false )
174
+ Optional <PtGraph .PtEdge > firstAlighting = StreamSupport .stream (staticGtfs .getPtGraph ().backEdgesAround (station ).spliterator (), false )
175
175
.flatMap (e -> StreamSupport .stream (staticGtfs .getPtGraph ().backEdgesAround (e .getAdjNode ()).spliterator (), false ))
176
176
.flatMap (e -> StreamSupport .stream (staticGtfs .getPtGraph ().backEdgesAround (e .getAdjNode ()).spliterator (), false ))
177
177
.filter (e -> e .getType () == GtfsStorage .EdgeType .ALIGHT )
178
178
.filter (e -> normalize (e .getAttrs ().tripDescriptor ).equals (tripUpdate .getTrip ()))
179
- .findAny ();
180
- int n = firstBoarding .get ().getAdjNode ();
181
- Stream <PtGraph .PtEdge > boardEdges = evenIndexed (nodes (hopDwellChain (staticGtfs , n )))
179
+ .min (Comparator .comparingInt (e -> e .getAttrs ().stop_sequence ));
180
+ if (firstAlighting .isEmpty ()) {
181
+ return null ;
182
+ }
183
+ int n = firstAlighting .get ().getAdjNode ();
184
+ Stream <PtGraph .PtEdge > leaveEdges = evenIndexed (nodes (hopDwellChain (staticGtfs , n )))
182
185
.mapToObj (e -> alightForBaseNode (staticGtfs , e ));
183
- return collectWithPadding (boardEdges );
186
+ return collectWithPadding (leaveEdges );
184
187
}
185
188
186
189
private static int [] findBoardEdgesForTrip (GtfsStorage staticGtfs , String feedKey , GTFSFeed feed , GtfsRealtime .TripUpdate tripUpdate ) {
@@ -192,7 +195,10 @@ private static int[] findBoardEdgesForTrip(GtfsStorage staticGtfs, String feedKe
192
195
.flatMap (e -> StreamSupport .stream (staticGtfs .getPtGraph ().edgesAround (e .getAdjNode ()).spliterator (), false ))
193
196
.filter (e -> e .getType () == GtfsStorage .EdgeType .BOARD )
194
197
.filter (e -> normalize (e .getAttrs ().tripDescriptor ).equals (tripUpdate .getTrip ()))
195
- .findAny ();
198
+ .min (Comparator .comparingInt (e -> e .getAttrs ().stop_sequence ));
199
+ if (firstBoarding .isEmpty ()) {
200
+ return null ;
201
+ }
196
202
int n = firstBoarding .get ().getAdjNode ();
197
203
Stream <PtGraph .PtEdge > boardEdges = evenIndexed (nodes (hopDwellChain (staticGtfs , n )))
198
204
.mapToObj (e -> boardForAdjNode (staticGtfs , e ));
0 commit comments