66import java .util .*;
77
88public class StopStatusProcessor {
9- private static final List <Hfp .Topic .TransportMode > TRANSPORT_MODES_WITHOUT_EVENTS = Collections .unmodifiableList (Arrays .asList (
10- Hfp .Topic .TransportMode .metro ,
11- Hfp .Topic .TransportMode .ferry ,
12- Hfp .Topic .TransportMode .ubus ,
13- Hfp .Topic .TransportMode .robot
14- ));
9+ private static final List <Hfp .Topic .TransportMode > TRANSPORT_MODES_WITHOUT_EVENTS = Collections
10+ .unmodifiableList (Arrays .asList (Hfp .Topic .TransportMode .metro , Hfp .Topic .TransportMode .ferry ,
11+ Hfp .Topic .TransportMode .ubus , Hfp .Topic .TransportMode .robot ));
1512
1613 private final Map <String , StopStatus > vehicleStopStatus = new HashMap <>(1000 );
1714
1815 public StopStatus getStopStatus (Hfp .Data hfpData ) {
19- return vehicleStopStatus .compute (hfpData .getTopic ().getUniqueVehicleId (), (uniqueVehicleId , previousStopStatus ) -> processStopStatus (previousStopStatus , hfpData ));
16+ return vehicleStopStatus .compute (hfpData .getTopic ().getUniqueVehicleId (),
17+ (uniqueVehicleId , previousStopStatus ) -> processStopStatus (previousStopStatus , hfpData ));
2018 }
2119
2220 private StopStatus processStopStatus (StopStatus previousStopStatus , Hfp .Data hfpData ) {
@@ -30,47 +28,57 @@ private StopStatus processStopStatus(StopStatus previousStopStatus, Hfp.Data hfp
3028 return processStopStatusWithoutEvents (hfpData );
3129 }
3230
33- if (previousStopStatus == null || hfpData .getTopic ().getEventType () == Hfp .Topic .EventType .PDE || hfpData .getTopic ().getEventType () == Hfp .Topic .EventType .PAS ) {
31+ if (previousStopStatus == null || hfpData .getTopic ().getEventType () == Hfp .Topic .EventType .PDE
32+ || hfpData .getTopic ().getEventType () == Hfp .Topic .EventType .PAS ) {
3433 //Set StopStatus to IN_TRANSIT_TO when a vehicle departs from a stop or passes through a stop
35- return new StopStatus (hfpData .getTopic ().getNextStop (), GtfsRealtime .VehiclePosition .VehicleStopStatus .IN_TRANSIT_TO );
34+ return new StopStatus (hfpData .getTopic ().getNextStop (),
35+ GtfsRealtime .VehiclePosition .VehicleStopStatus .IN_TRANSIT_TO );
3636 }
3737
3838 if (hfpData .getTopic ().getEventType () == Hfp .Topic .EventType .DUE ) {
3939 //Set StopStatus to INCOMING_AT when a vehicle is just about to arrive to a stop
40- return new StopStatus (hfpData .getTopic ().getNextStop (), GtfsRealtime .VehiclePosition .VehicleStopStatus .INCOMING_AT );
40+ return new StopStatus (hfpData .getTopic ().getNextStop (),
41+ GtfsRealtime .VehiclePosition .VehicleStopStatus .INCOMING_AT );
4142 }
4243
4344 if (hfpData .getTopic ().getEventType () == Hfp .Topic .EventType .ARS ) {
4445 //Set StopStatus to STOPPED_AT when a vehicle has arrived to a stop
45- return new StopStatus (hfpData .getTopic ().getNextStop (), GtfsRealtime .VehiclePosition .VehicleStopStatus .STOPPED_AT );
46+ return new StopStatus (hfpData .getTopic ().getNextStop (),
47+ GtfsRealtime .VehiclePosition .VehicleStopStatus .STOPPED_AT );
4648 }
4749
4850 //If a vehicle was arriving to a stop and the stop id in the topic has not changed, return previous status
49- if (previousStopStatus .stopStatus == GtfsRealtime .VehiclePosition .VehicleStopStatus .INCOMING_AT &&
50- hfpData .getTopic ().getNextStop ().equals (previousStopStatus .stopId )) {
51+ if (previousStopStatus .stopStatus == GtfsRealtime .VehiclePosition .VehicleStopStatus .INCOMING_AT
52+ && hfpData .getTopic ().getNextStop ().equals (previousStopStatus .stopId )) {
5153 return previousStopStatus ;
5254 }
5355
5456 if (previousStopStatus .stopStatus == GtfsRealtime .VehiclePosition .VehicleStopStatus .STOPPED_AT ) {
55- if (hfpData .getPayload ().hasStop () && String .valueOf (hfpData .getPayload ().getStop ()).equals (hfpData .getTopic ().getNextStop ())) {
57+ if (hfpData .getPayload ().hasStop ()
58+ && String .valueOf (hfpData .getPayload ().getStop ()).equals (hfpData .getTopic ().getNextStop ())) {
5659 //If next_stop has not changed in the topic, the vehicle is still at a stop
5760 return previousStopStatus ;
5861 } else {
5962 //If next_stop has changed, the vehicle is in transit to the next stop
60- return new StopStatus (hfpData .getTopic ().getNextStop (), GtfsRealtime .VehiclePosition .VehicleStopStatus .IN_TRANSIT_TO );
63+ return new StopStatus (hfpData .getTopic ().getNextStop (),
64+ GtfsRealtime .VehiclePosition .VehicleStopStatus .IN_TRANSIT_TO );
6165 }
6266 }
6367
64- return new StopStatus (hfpData .getTopic ().getNextStop (), GtfsRealtime .VehiclePosition .VehicleStopStatus .IN_TRANSIT_TO );
68+ return new StopStatus (hfpData .getTopic ().getNextStop (),
69+ GtfsRealtime .VehiclePosition .VehicleStopStatus .IN_TRANSIT_TO );
6570 }
6671
6772 private StopStatus processStopStatusWithoutEvents (Hfp .Data data ) {
68- if (data .getPayload ().hasStop () && String .valueOf (data .getPayload ().getStop ()).equals (data .getTopic ().getNextStop ())) {
73+ if (data .getPayload ().hasStop ()
74+ && String .valueOf (data .getPayload ().getStop ()).equals (data .getTopic ().getNextStop ())) {
6975 //If the vehicle is near a stop, its payload contains a stop ID -> assume that the vehicle is stopped at the stop
70- return new StopStatus (String .valueOf (data .getPayload ().getStop ()), GtfsRealtime .VehiclePosition .VehicleStopStatus .STOPPED_AT );
76+ return new StopStatus (String .valueOf (data .getPayload ().getStop ()),
77+ GtfsRealtime .VehiclePosition .VehicleStopStatus .STOPPED_AT );
7178 } else {
7279 //Otherwise assume that the vehicle is in transit to the next stop
73- return new StopStatus (data .getTopic ().getNextStop (), GtfsRealtime .VehiclePosition .VehicleStopStatus .IN_TRANSIT_TO );
80+ return new StopStatus (data .getTopic ().getNextStop (),
81+ GtfsRealtime .VehiclePosition .VehicleStopStatus .IN_TRANSIT_TO );
7482 }
7583 }
7684
0 commit comments