sonarqube: removed some smells.

biggest change is that the HashSet and HashMap in LobbyConnection is now a Set and Map instead.
This commit is contained in:
Richard Reiber 2021-08-09 23:19:30 +02:00
parent d54d2004dd
commit 97a2cbb74e
5 changed files with 11 additions and 16 deletions

View File

@ -92,7 +92,6 @@ public class Server {
* It has to be executed <b>BEFORE ANY LOGGING OPERATIONS</b> . * It has to be executed <b>BEFORE ANY LOGGING OPERATIONS</b> .
*/ */
private static void setLogLevel(int logLevel) { private static void setLogLevel(int logLevel) {
// System.out.println("setting log level to " + logLevel);
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
Configuration.replace(map); Configuration.replace(map);

View File

@ -1,13 +1,9 @@
package uulm.teamname.marvelous.server.lobby; 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.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit; 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, * A timer meant to time the entire Lifetime of the lobby, and if it is higher than the maximum permitted value,

View File

@ -28,19 +28,19 @@ public class TurnTimeoutTimer {
/** /**
* This method checks if the participant is not a spectator. Otherwise it won't start a timer. * 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) { public void startTurnTimer(Participant participant) {
if (Participant.type == ParticipantType.Spectator) { if (participant.type == ParticipantType.Spectator) {
throw new IllegalStateException("Spectators don't have TurnTime"); throw new IllegalStateException("Spectators don't have TurnTime");
} }
clear(); clear();
Logger.debug("Starting turn timer for participant '{}' with role {}", Logger.debug("Starting turn timer for participant '{}' with role {}",
Participant.id.getName(), Participant.type); participant.id.getName(), participant.type);
current = timer.schedule(() -> { current = timer.schedule(() -> {
callback.accept(Participant); callback.accept(participant);
return Participant; return participant;
}, },
maxRoundTime, maxRoundTime,
TimeUnit.SECONDS); TimeUnit.SECONDS);

View File

@ -29,9 +29,9 @@ public class LobbyConnection implements Runnable {
private Participant player1; private Participant player1;
private Participant player2; private Participant player2;
private final HashSet<Participant> spectators = new HashSet<>(10); private final Set<Participant> spectators = new HashSet<>(10);
private final HashMap<SUID, List<Integer>> selection = new HashMap<>(2); private final Map<SUID, List<Integer>> selection = new HashMap<>(2);
public final HashMap<ParticipantType, CharacterProperties[]> options = new HashMap<>(2); public final Map<ParticipantType, CharacterProperties[]> options = new HashMap<>(2);
private final BlockingQueue<Tuple<Participant, Request[]>> requestQueue = new LinkedBlockingQueue<>(); private final BlockingQueue<Tuple<Participant, Request[]>> requestQueue = new LinkedBlockingQueue<>();
@ -117,7 +117,7 @@ public class LobbyConnection implements Runnable {
return player2; return player2;
} }
public HashSet<Participant> getSpectators() { public Set<Participant> getSpectators() {
return spectators; return spectators;
} }

View File

@ -43,7 +43,7 @@ class UserManagerTest {
@Test @Test
void userIsConnectedTest() { void userIsConnectedTest() {
assertThat(manager.getUserCount()).isEqualTo(0); assertThat(manager.getUserCount()).isZero();
assertThat(manager.containsConnection(socket1)).isFalse(); assertThat(manager.containsConnection(socket1)).isFalse();
manager.connectUser(socket1); manager.connectUser(socket1);
assertThat(manager.getUserCount()).isEqualTo(1); assertThat(manager.getUserCount()).isEqualTo(1);