From d94f7307e228c5ccd363879d67a214fe30ed21a2 Mon Sep 17 00:00:00 2001 From: FKD13 <44001949+FKD13@users.noreply.github.com> Date: Fri, 29 Mar 2024 16:22:25 +0100 Subject: [PATCH] apply even more lombok --- src/main/java/telraam/App.java | 33 +++----- src/main/java/telraam/AppConfiguration.java | 46 ++-------- .../java/telraam/api/responses/Saying.java | 26 ++---- .../java/telraam/api/responses/Template.java | 8 +- .../monitoring/BatonDetectionManager.java | 10 +-- .../telraam/monitoring/BatonStatusHolder.java | 14 ++-- .../monitoring/StationDetectionManager.java | 6 +- .../monitoring/models/BatonDetection.java | 54 ++---------- .../monitoring/models/BatonStatus.java | 83 ++----------------- .../monitoring/models/LapCountForTeam.java | 9 +- .../monitoring/models/TeamLapInfo.java | 13 ++- src/main/java/telraam/station/Fetcher.java | 2 +- .../websocket/WebSocketMessageSingleton.java | 4 +- 13 files changed, 70 insertions(+), 238 deletions(-) diff --git a/src/main/java/telraam/App.java b/src/main/java/telraam/App.java index 4e6eb03..5b1644e 100644 --- a/src/main/java/telraam/App.java +++ b/src/main/java/telraam/App.java @@ -10,6 +10,8 @@ import io.federecio.dropwizard.swagger.SwaggerBundleConfiguration; import jakarta.servlet.DispatcherType; import jakarta.servlet.FilterRegistration; +import lombok.Getter; +import lombok.Setter; import org.eclipse.jetty.servlets.CrossOriginFilter; import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer; import org.jdbi.v3.core.Jdbi; @@ -33,10 +35,18 @@ import java.util.logging.Logger; public class App extends Application { - private static Logger logger = Logger.getLogger(App.class.getName()); + private static final Logger logger = Logger.getLogger(App.class.getName()); + + @Getter private AppConfiguration config; + + @Getter private Environment environment; + + @Getter private Jdbi database; + + @Setter private boolean testing; public static void main(String[] args) throws Exception { @@ -49,10 +59,6 @@ public App() { testing = true; } - public void setTesting(boolean testing) { - this.testing = testing; - } - @Override public String getName() { return "hello-world"; @@ -72,7 +78,7 @@ protected SwaggerBundleConfiguration getSwaggerBundleConfiguration(AppConfigurat } @Override - public void run(AppConfiguration configuration, Environment environment) throws IOException { + public void run(AppConfiguration configuration, Environment environment) { this.config = configuration; this.environment = environment; // Add database @@ -122,9 +128,6 @@ public void run(AppConfiguration configuration, Environment environment) throws // Set up lapper algorithms Set lappers = new HashSet<>(); - // Old viterbi lapper is disabled - //lappers.add(new ViterbiLapper(this.database)); - lappers.add(new ExternalLapper(this.database)); lappers.add(new RobustLapper(this.database)); @@ -147,16 +150,4 @@ public void run(AppConfiguration configuration, Environment environment) throws logger.info("Up and running!"); } - - public AppConfiguration getConfig() { - return config; - } - - public Environment getEnvironment() { - return environment; - } - - public Jdbi getDatabase() { - return database; - } } diff --git a/src/main/java/telraam/AppConfiguration.java b/src/main/java/telraam/AppConfiguration.java index 15eefbc..c338c65 100644 --- a/src/main/java/telraam/AppConfiguration.java +++ b/src/main/java/telraam/AppConfiguration.java @@ -6,53 +6,25 @@ import io.federecio.dropwizard.swagger.SwaggerBundleConfiguration; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; import telraam.api.responses.Template; public class AppConfiguration extends Configuration { @NotNull + @Getter @Setter private String template; @NotNull + @Getter @Setter private String defaultName = "Stranger"; + @JsonProperty("swagger") + public SwaggerBundleConfiguration swaggerBundleConfiguration; + @Valid @NotNull - private DataSourceFactory database = new DataSourceFactory(); - - @JsonProperty - public String getTemplate() { - return template; - } - - @JsonProperty - public void setTemplate(String template) { - this.template = template; - } - - public Template buildTemplate() { - return new Template(template, defaultName); - } - - @JsonProperty - public String getDefaultName() { - return defaultName; - } - - @JsonProperty - public void setDefaultName(String name) { - this.defaultName = name; - } - - @JsonProperty("database") - public DataSourceFactory getDataSourceFactory() { - return database; - } - + @Getter @Setter @JsonProperty("database") - public void setDataSourceFactory(DataSourceFactory factory) { - this.database = factory; - } - - @JsonProperty("swagger") - public SwaggerBundleConfiguration swaggerBundleConfiguration; + private DataSourceFactory dataSourceFactory = new DataSourceFactory(); } diff --git a/src/main/java/telraam/api/responses/Saying.java b/src/main/java/telraam/api/responses/Saying.java index 79afdf9..5750eea 100644 --- a/src/main/java/telraam/api/responses/Saying.java +++ b/src/main/java/telraam/api/responses/Saying.java @@ -1,30 +1,16 @@ package telraam.api.responses; -import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; import org.hibernate.validator.constraints.Length; +@Getter +@NoArgsConstructor +@AllArgsConstructor public class Saying { private long id; @Length(max = 3) private String content; - - public Saying() { - // Jackson deserialization - } - - public Saying(long id, String content) { - this.id = id; - this.content = content; - } - - @JsonProperty - public long getId() { - return id; - } - - @JsonProperty - public String getContent() { - return content; - } } \ No newline at end of file diff --git a/src/main/java/telraam/api/responses/Template.java b/src/main/java/telraam/api/responses/Template.java index ce15c84..d41829d 100644 --- a/src/main/java/telraam/api/responses/Template.java +++ b/src/main/java/telraam/api/responses/Template.java @@ -1,18 +1,16 @@ package telraam.api.responses; +import lombok.AllArgsConstructor; + import java.util.Optional; import static java.lang.String.format; +@AllArgsConstructor public class Template { private final String content; private final String defaultName; - public Template(String content, String defaultName) { - this.content = content; - this.defaultName = defaultName; - } - public String render(Optional name) { return format(content, name.orElse(defaultName)); } diff --git a/src/main/java/telraam/monitoring/BatonDetectionManager.java b/src/main/java/telraam/monitoring/BatonDetectionManager.java index db6b10b..f48dafd 100644 --- a/src/main/java/telraam/monitoring/BatonDetectionManager.java +++ b/src/main/java/telraam/monitoring/BatonDetectionManager.java @@ -12,12 +12,12 @@ import java.util.Map; public class BatonDetectionManager { - private DetectionDAO detectionDAO; - private TeamDAO teamDAO; - private BatonSwitchoverDAO batonSwitchoverDAO; + private final DetectionDAO detectionDAO; + private final TeamDAO teamDAO; + private final BatonSwitchoverDAO batonSwitchoverDAO; // Map of a baton id to it's detections - private Map> batonDetectionMap = new HashMap<>(); + private final Map> batonDetectionMap = new HashMap<>(); private Integer handledDetectionId = 0; public BatonDetectionManager(DetectionDAO detectionDAO, TeamDAO teamDAO, BatonSwitchoverDAO batonSwitchoverDAO) { @@ -60,7 +60,7 @@ public Map> getBatonDetections() { } var batonDetections = batonDetectionMap.get(batonId); var team = teamMap.get(batonTeamMap.get(batonId)); - var batonDetection = new BatonDetection(Math.toIntExact(d.getTimestamp().getTime() / 1000), d.getRssi(), d.getStationId(), batonId, team.getName()); + var batonDetection = new BatonDetection(Math.toIntExact(d.getTimestamp().getTime() / 1000), d.getRssi(), batonId /* FIXME: BatonDetection expects a teamId here? */, d.getStationId(), team.getName()); batonDetections.add(batonDetection); }); return batonDetectionMap; diff --git a/src/main/java/telraam/monitoring/BatonStatusHolder.java b/src/main/java/telraam/monitoring/BatonStatusHolder.java index b791e0e..ea2d39c 100644 --- a/src/main/java/telraam/monitoring/BatonStatusHolder.java +++ b/src/main/java/telraam/monitoring/BatonStatusHolder.java @@ -15,15 +15,15 @@ public class BatonStatusHolder { // Map from batonMac to batonStatus - private HashMap batonStatusMap = new HashMap<>(); - private HashMap batonIdToMac = new HashMap<>(); + private final HashMap batonStatusMap = new HashMap<>(); + private final HashMap batonIdToMac = new HashMap<>(); - private BatonDAO batonDAO; - private DetectionDAO detectionDAO; + private final BatonDAO batonDAO; + private final DetectionDAO detectionDAO; - public BatonStatusHolder(BatonDAO BDAO, DetectionDAO DDAO) { - batonDAO = BDAO; - detectionDAO = DDAO; + public BatonStatusHolder(BatonDAO batonDAO, DetectionDAO detectionDAO) { + this.batonDAO = batonDAO; + this.detectionDAO = detectionDAO; } private BatonStatus getStatusForBaton(String batonMac) { diff --git a/src/main/java/telraam/monitoring/StationDetectionManager.java b/src/main/java/telraam/monitoring/StationDetectionManager.java index 3929f42..931883f 100644 --- a/src/main/java/telraam/monitoring/StationDetectionManager.java +++ b/src/main/java/telraam/monitoring/StationDetectionManager.java @@ -11,9 +11,9 @@ import java.util.Optional; public class StationDetectionManager { - private DetectionDAO detectionDAO; + private final DetectionDAO detectionDAO; - private StationDAO stationDAO; + private final StationDAO stationDAO; public StationDetectionManager(DetectionDAO detectionDAO, StationDAO stationDAO) { this.detectionDAO = detectionDAO; @@ -27,7 +27,7 @@ public Map timeSinceLastDetectionPerStation() { Optional maybeDetection = this.detectionDAO.latestDetectionByStationId(stationId); Optional maybeStation = this.stationDAO.getById(stationId); if (maybeDetection.isPresent() && maybeStation.isPresent()) { - Long time = maybeDetection.get().getTimestamp().getTime(); + long time = maybeDetection.get().getTimestamp().getTime(); stationIdToTimeSinceLatestDetection.put(maybeStation.get().getName(), (System.currentTimeMillis() - time) / 1000); } } diff --git a/src/main/java/telraam/monitoring/models/BatonDetection.java b/src/main/java/telraam/monitoring/models/BatonDetection.java index 646bf34..29eee97 100644 --- a/src/main/java/telraam/monitoring/models/BatonDetection.java +++ b/src/main/java/telraam/monitoring/models/BatonDetection.java @@ -1,7 +1,13 @@ package telraam.monitoring.models; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; +@Setter +@Getter +@AllArgsConstructor public class BatonDetection { @JsonProperty("detected_time") private Integer detectionTime; @@ -13,52 +19,4 @@ public class BatonDetection { private Integer stationId; @JsonProperty("team_name") private String teamName; - - public BatonDetection(Integer detectionTime, Integer rssi, Integer stationId, Integer teamId, String teamName) { - this.detectionTime = detectionTime; - this.rssi = rssi; - this.stationId = stationId; - this.teamId = teamId; - this.teamName = teamName; - } - - public Integer getDetectionTime() { - return detectionTime; - } - - public void setDetectionTime(Integer detectionTime) { - this.detectionTime = detectionTime; - } - - public Integer getRssi() { - return rssi; - } - - public void setRssi(Integer rssi) { - this.rssi = rssi; - } - - public Integer getTeamId() { - return teamId; - } - - public void setTeamId(Integer teamId) { - this.teamId = teamId; - } - - public Integer getStationId() { - return stationId; - } - - public void setStationId(Integer stationId) { - this.stationId = stationId; - } - - public String getTeamName() { - return teamName; - } - - public void setTeamName(String teamName) { - this.teamName = teamName; - } } diff --git a/src/main/java/telraam/monitoring/models/BatonStatus.java b/src/main/java/telraam/monitoring/models/BatonStatus.java index 947bd60..c719098 100644 --- a/src/main/java/telraam/monitoring/models/BatonStatus.java +++ b/src/main/java/telraam/monitoring/models/BatonStatus.java @@ -2,16 +2,20 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; import java.sql.Timestamp; +@Getter +@Setter public class BatonStatus { + private String mac; private Integer id; private String name; private Float battery; - // Uptime in seconds - private Long uptime; + private Long uptime; // Uptime in seconds private Boolean rebooted; @JsonProperty("time_since_seen") private Long lastSeenSecondsAgo; @@ -20,7 +24,7 @@ public class BatonStatus { @JsonProperty("last_detected_at_station") private Integer lastDetectedAtStation; - public BatonStatus(String mac, Integer id, String name, float battery, long uptime, boolean rebooted, Timestamp lastSeen, Integer LDAS) { + public BatonStatus(String mac, Integer id, String name, float battery, long uptime, boolean rebooted, Timestamp lastSeen, Integer lastDetectedAtStation) { this.mac = mac; this.id = id; this.name = name; @@ -29,79 +33,6 @@ public BatonStatus(String mac, Integer id, String name, float battery, long upti this.rebooted = rebooted; this.lastSeen = lastSeen; this.lastSeenSecondsAgo = lastSeen != null ? (System.currentTimeMillis() - lastSeen.getTime()) / 1000 : null; - this.lastDetectedAtStation = LDAS; - } - - // Getters and setters - public String getMac() { - return mac; - } - - public void setMac(String mac) { - this.mac = mac; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Float getBattery() { - return battery; - } - - public void setBattery(Float battery) { - this.battery = battery; - } - - public Long getUptime() { - return uptime; - } - - public void setUptime(Long uptime) { - this.uptime = uptime; - } - - public Boolean getRebooted() { - return rebooted; - } - - public void setRebooted(Boolean rebooted) { - this.rebooted = rebooted; - } - - public Long getLastSeenSecondsAgo() { - return lastSeenSecondsAgo; - } - - public void setLastSeenSecondsAgo(Long lastSeenSecondsAgo) { - this.lastSeenSecondsAgo = lastSeenSecondsAgo; - } - - public Timestamp getLastSeen() { - return lastSeen; - } - - public void setLastSeen(Timestamp lastSeen) { - this.lastSeen = lastSeen; - } - - public Integer getLastDetectedAtStation() { - return lastDetectedAtStation; - } - - public void setLastDetectedAtStation(Integer lastDetectedAtStation) { this.lastDetectedAtStation = lastDetectedAtStation; } diff --git a/src/main/java/telraam/monitoring/models/LapCountForTeam.java b/src/main/java/telraam/monitoring/models/LapCountForTeam.java index f75d8d0..3e8335e 100644 --- a/src/main/java/telraam/monitoring/models/LapCountForTeam.java +++ b/src/main/java/telraam/monitoring/models/LapCountForTeam.java @@ -1,17 +1,16 @@ package telraam.monitoring.models; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; import java.util.Map; +@AllArgsConstructor public class LapCountForTeam { + @JsonProperty("team_name") private String teamName; + @JsonProperty("lap_counts") private Map lapCounts; - - public LapCountForTeam(String teamName, Map lapCounts) { - this.teamName = teamName; - this.lapCounts = lapCounts; - } } diff --git a/src/main/java/telraam/monitoring/models/TeamLapInfo.java b/src/main/java/telraam/monitoring/models/TeamLapInfo.java index 3473bd1..b244c27 100644 --- a/src/main/java/telraam/monitoring/models/TeamLapInfo.java +++ b/src/main/java/telraam/monitoring/models/TeamLapInfo.java @@ -1,21 +1,20 @@ package telraam.monitoring.models; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +@AllArgsConstructor public class TeamLapInfo { + @JsonProperty("lap_time") private long lapTime; + @JsonProperty("timestamp") private long timestamp; + @JsonProperty("team_id") private int teamId; + @JsonProperty("team_name") private String teamName; - - public TeamLapInfo(long lapTime, long timestamp, int teamId, String teamName) { - this.lapTime = lapTime; - this.timestamp = timestamp; - this.teamId = teamId; - this.teamName = teamName; - } } diff --git a/src/main/java/telraam/station/Fetcher.java b/src/main/java/telraam/station/Fetcher.java index bb0ed5e..fbd51b4 100644 --- a/src/main/java/telraam/station/Fetcher.java +++ b/src/main/java/telraam/station/Fetcher.java @@ -54,9 +54,9 @@ public Fetcher(Jdbi database, Station station, Set lappers, Set registeredConnections = new HashSet<>(); + private final Set registeredConnections = new HashSet<>(); private final ObjectMapper mapper = new ObjectMapper(); public void registerConnection(WebSocketConnection conn) {