refactor: removed callbacks and generated equals and hashcode for Lobby and LobbyConnection

This commit is contained in:
Yannik Bretschneider 2021-06-06 12:46:45 +02:00
parent d8a031f379
commit 07d440bfac
2 changed files with 31 additions and 12 deletions

View File

@ -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 +
'}';
}
}

View File

@ -34,17 +34,10 @@ public class LobbyConnection implements Runnable {
private final HashSet<Participant> spectators;
private final BlockingQueue<Tuple<Participant, BasicMessage>> incomingMessages;
/**
* A callback executed to send a message, originating from the
* {@link uulm.teamname.marvelous.server.netconnector.UserManager}
*/
private final BiConsumer<Participant, BasicMessage> sendMessageCallback;
// TODO: FIX THIS JAVADOC
/** Creates a new LobbyConnection */
public LobbyConnection(String gameID, BiConsumer<Participant, BasicMessage> 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 +
'}';
}
}