From 97a2cbb74e05cf07f14a794a936416103956ce80 Mon Sep 17 00:00:00 2001 From: Richard Reiber Date: Mon, 9 Aug 2021 23:19:30 +0200 Subject: [PATCH] sonarqube: removed some smells. biggest change is that the HashSet and HashMap in LobbyConnection is now a Set and Map instead. --- .../java/uulm/teamname/marvelous/server/Server.java | 1 - .../marvelous/server/lobby/LifetimeTimer.java | 4 ---- .../marvelous/server/lobby/TurnTimeoutTimer.java | 12 ++++++------ .../server/lobbymanager/LobbyConnection.java | 8 ++++---- .../server/netconnector/UserManagerTest.java | 2 +- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/Server.java b/Server/src/main/java/uulm/teamname/marvelous/server/Server.java index 54490b2..75f8930 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/Server.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/Server.java @@ -92,7 +92,6 @@ public class Server { * It has to be executed BEFORE ANY LOGGING OPERATIONS . */ private static void setLogLevel(int logLevel) { - // System.out.println("setting log level to " + logLevel); Map map = new HashMap<>(); Configuration.replace(map); diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/LifetimeTimer.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/LifetimeTimer.java index ff47751..c6d2317 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/LifetimeTimer.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/LifetimeTimer.java @@ -1,13 +1,9 @@ package uulm.teamname.marvelous.server.lobby; -import uulm.teamname.marvelous.server.Server; -import uulm.teamname.marvelous.server.lobbymanager.Participant; - import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; -import java.util.function.Consumer; /** * A timer meant to time the entire Lifetime of the lobby, and if it is higher than the maximum permitted value, diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/TurnTimeoutTimer.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/TurnTimeoutTimer.java index 9e39aa5..39f6f3e 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/TurnTimeoutTimer.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/TurnTimeoutTimer.java @@ -28,19 +28,19 @@ public class TurnTimeoutTimer { /** * This method checks if the participant is not a spectator. Otherwise it won't start a timer. * - * @param Participant the timer is for + * @param participant the timer is for */ - public void startTurnTimer(Participant Participant) { - if (Participant.type == ParticipantType.Spectator) { + public void startTurnTimer(Participant participant) { + if (participant.type == ParticipantType.Spectator) { throw new IllegalStateException("Spectators don't have TurnTime"); } clear(); Logger.debug("Starting turn timer for participant '{}' with role {}", - Participant.id.getName(), Participant.type); + participant.id.getName(), participant.type); current = timer.schedule(() -> { - callback.accept(Participant); - return Participant; + callback.accept(participant); + return participant; }, maxRoundTime, TimeUnit.SECONDS); diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyConnection.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyConnection.java index 8b19cf3..3ef64a8 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyConnection.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyConnection.java @@ -29,9 +29,9 @@ public class LobbyConnection implements Runnable { private Participant player1; private Participant player2; - private final HashSet spectators = new HashSet<>(10); - private final HashMap> selection = new HashMap<>(2); - public final HashMap options = new HashMap<>(2); + private final Set spectators = new HashSet<>(10); + private final Map> selection = new HashMap<>(2); + public final Map options = new HashMap<>(2); private final BlockingQueue> requestQueue = new LinkedBlockingQueue<>(); @@ -117,7 +117,7 @@ public class LobbyConnection implements Runnable { return player2; } - public HashSet getSpectators() { + public Set getSpectators() { return spectators; } diff --git a/Server/src/test/java/uulm/teamname/marvelous/server/netconnector/UserManagerTest.java b/Server/src/test/java/uulm/teamname/marvelous/server/netconnector/UserManagerTest.java index 24e49f3..98fd48a 100644 --- a/Server/src/test/java/uulm/teamname/marvelous/server/netconnector/UserManagerTest.java +++ b/Server/src/test/java/uulm/teamname/marvelous/server/netconnector/UserManagerTest.java @@ -43,7 +43,7 @@ class UserManagerTest { @Test void userIsConnectedTest() { - assertThat(manager.getUserCount()).isEqualTo(0); + assertThat(manager.getUserCount()).isZero(); assertThat(manager.containsConnection(socket1)).isFalse(); manager.connectUser(socket1); assertThat(manager.getUserCount()).isEqualTo(1);