Skip to content

Commit 7fe6337

Browse files
authored
Merge pull request #85 from HSLdevcom/feature/64987-integrate-autoformatter
Feature/64987 integrate autoformatter
2 parents c4ca0ec + 9b2ef72 commit 7fe6337

19 files changed

Lines changed: 442 additions & 513 deletions

.github/workflows/test-and-build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ jobs:
1313
distribution: 'temurin'
1414
java-version: '11'
1515
cache: 'maven'
16+
- name: Run Spotless Apply
17+
run: mvn spotless:apply
18+
env:
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1620
- name: Build with Maven
1721
run: mvn --file pom.xml clean install
1822
env:

eclipse-java-formatter.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<profiles version="13">
3+
<profile kind="CodeFormatterProfile" name="Custom-4spaces-NoCommentSplit" version="13">
4+
5+
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>
6+
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/>
7+
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/>
8+
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
9+
10+
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="120"/>
11+
12+
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="9999"/>
13+
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="false"/>
14+
<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="false"/>
15+
<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="false"/>
16+
17+
</profile>
18+
</profiles>

pom.xml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1010
<maven.compiler.source>11</maven.compiler.source>
1111
<maven.compiler.target>11</maven.compiler.target>
12-
<common.version>2.0.3-RC6</common.version>
12+
<common.version>2.0.5</common.version>
13+
<spotlessMavenPlugin.version>2.43.0</spotlessMavenPlugin.version>
14+
<googleJavaFormat.version>1.17.0</googleJavaFormat.version>
1315
</properties>
1416

1517
<repositories>
@@ -113,6 +115,32 @@
113115
<artifactId>maven-surefire-plugin</artifactId>
114116
<version>2.22.2</version>
115117
</plugin>
118+
<plugin>
119+
<groupId>com.diffplug.spotless</groupId>
120+
<artifactId>spotless-maven-plugin</artifactId>
121+
<version>${spotlessMavenPlugin.version}</version>
122+
<configuration>
123+
<java>
124+
<eclipse>
125+
<file>${project.basedir}/eclipse-java-formatter.xml</file>
126+
</eclipse>
127+
</java>
128+
</configuration>
129+
<executions>
130+
<execution>
131+
<id>spotless-check</id>
132+
<goals>
133+
<goal>check</goal>
134+
</goals>
135+
</execution>
136+
<execution>
137+
<id>spotless-apply</id>
138+
<goals>
139+
<goal>apply</goal>
140+
</goals>
141+
</execution>
142+
</executions>
143+
</plugin>
116144
</plugins>
117145

118146
</build>

src/main/java/fi/hsl/transitdata/vehicleposition/application/StopStatusProcessor.java

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@
66
import java.util.*;
77

88
public 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

Comments
 (0)