From 07d440bfac836e336ba8ab0e63bb8ff6ad8c9433 Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Sun, 6 Jun 2021 12:46:45 +0200 Subject: [PATCH] refactor: removed callbacks and generated equals and hashcode for Lobby and LobbyConnection --- .../marvelous/server/lobby/Lobby.java | 28 +++++++++++++++++++ .../server/lobbymanager/LobbyConnection.java | 15 ++-------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/Lobby.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/Lobby.java index 0344d2c..9a5c7f6 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/Lobby.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/Lobby.java @@ -216,4 +216,32 @@ public class Lobby { public Participant getActivePlayer() { return activePlayer; } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Lobby lobby = (Lobby) o; + return badRequests == lobby.badRequests && Objects.equals(gameID, lobby.gameID) && Objects.equals(connection, lobby.connection) && Objects.equals(game, lobby.game) && Objects.equals(pipeline, lobby.pipeline) && Objects.equals(activePlayer, lobby.activePlayer) && Objects.equals(pauseSegment, lobby.pauseSegment) && Objects.equals(turnTimer, lobby.turnTimer); + } + + @Override + public int hashCode() { + return Objects.hash(gameID, connection, game, pipeline, activePlayer, badRequests, pauseSegment, turnTimer); + } + + @Override + public String toString() { + return "Lobby{" + + "gameID='" + gameID + '\'' + + ", connection=" + connection + + ", game=" + game + + ", pipeline=" + pipeline + + ", activePlayer=" + activePlayer + + ", badRequests=" + badRequests + + ", pauseSegment=" + pauseSegment + + ", turnTimer=" + turnTimer + + '}'; + } } 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 c5dd4e7..d474a51 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 @@ -34,17 +34,10 @@ public class LobbyConnection implements Runnable { private final HashSet spectators; private final BlockingQueue> incomingMessages; - /** - * A callback executed to send a message, originating from the - * {@link uulm.teamname.marvelous.server.netconnector.UserManager} - */ - private final BiConsumer sendMessageCallback; - // TODO: FIX THIS JAVADOC /** Creates a new LobbyConnection */ - public LobbyConnection(String gameID, BiConsumer sendMessageCallback) { + public LobbyConnection(String gameID) { this.gameID = gameID; - this.sendMessageCallback = sendMessageCallback; this.spectators = new HashSet<>(10); this.incomingMessages = new LinkedBlockingQueue<>(); this.characterSelection = false; @@ -325,18 +318,17 @@ public class LobbyConnection implements Runnable { // TODO: implement this } - @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; LobbyConnection that = (LobbyConnection) o; - return characterSelection == that.characterSelection && inGame == that.inGame && Objects.equals(lobby, that.lobby) && Objects.equals(gameID, that.gameID) && Objects.equals(player1, that.player1) && Objects.equals(player2, that.player2) && Objects.equals(spectators, that.spectators) && Objects.equals(incomingMessages, that.incomingMessages) && Objects.equals(sendMessageCallback, that.sendMessageCallback); + return characterSelection == that.characterSelection && inGame == that.inGame && Objects.equals(lobby, that.lobby) && Objects.equals(gameID, that.gameID) && Objects.equals(player1, that.player1) && Objects.equals(player2, that.player2) && Objects.equals(spectators, that.spectators) && Objects.equals(incomingMessages, that.incomingMessages); } @Override public int hashCode() { - return Objects.hash(lobby, gameID, player1, player2, characterSelection, inGame, spectators, incomingMessages, sendMessageCallback); + return Objects.hash(lobby, gameID, player1, player2, characterSelection, inGame, spectators, incomingMessages); } @Override @@ -350,7 +342,6 @@ public class LobbyConnection implements Runnable { ", inGame=" + inGame + ", spectators=" + spectators + ", incomingMessages=" + incomingMessages + - ", sendMessageCallback=" + sendMessageCallback + '}'; } }