From 36b934242deb1c17a2cfac84c2e38136fb7dc808 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Mon, 20 Apr 2020 13:12:07 +0200 Subject: [PATCH] Auto reformaterer alle klasser for nettverk --- .../roborally/networking/RoboRallyClient.java | 14 ++-- .../networking/RoboRallyClientListener.java | 11 ++-- .../roborally/networking/RoboRallyServer.java | 9 ++- .../networking/RoboRallyServerListener.java | 29 +++++---- .../networking/containers/ErrorResponse.java | 6 +- .../networking/containers/GameStartInfo.java | 64 +++++++++++-------- ...Container.java => PowerDownContainer.java} | 6 +- .../containers/ProgamsContainer.java | 9 ++- .../ProgramAndPowerdownRequest.java | 6 +- 9 files changed, 97 insertions(+), 57 deletions(-) rename src/main/java/inf112/fiasko/roborally/networking/containers/{PowerdownContainer.java => PowerDownContainer.java} (84%) diff --git a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClient.java b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClient.java index 57be1a1..7ba07f3 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClient.java +++ b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClient.java @@ -11,10 +11,12 @@ import java.io.IOException; */ public class RoboRallyClient { private final Client client; + /** * Instantiates a new Robo Rally client + * * @param ipAddress The ip address of the server to connect to - * @param wrapper The Robo Rally wrapper to be used + * @param wrapper The Robo Rally wrapper to be used * @throws IOException If the server cannot be reached */ public RoboRallyClient(String ipAddress, RoboRallyWrapper wrapper) throws IOException { @@ -28,12 +30,16 @@ public class RoboRallyClient { /** * Sends something to the server + * * @param object The object to send to the server */ - public void sendElement(Object object) {try{ - client.sendTCP(object);} - catch(Exception e){e.printStackTrace();} + public void sendElement(Object object) { + try { + client.sendTCP(object); + } catch (Exception e) { + e.printStackTrace(); } + } } diff --git a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClientListener.java b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClientListener.java index 235920b..cf43a9b 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClientListener.java +++ b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClientListener.java @@ -6,7 +6,7 @@ import inf112.fiasko.roborally.elementproperties.GameState; import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper; import inf112.fiasko.roborally.networking.containers.ErrorResponse; import inf112.fiasko.roborally.networking.containers.GameStartInfo; -import inf112.fiasko.roborally.networking.containers.PowerdownContainer; +import inf112.fiasko.roborally.networking.containers.PowerDownContainer; import inf112.fiasko.roborally.networking.containers.ProgamsContainer; import inf112.fiasko.roborally.objects.ProgrammingCardDeck; import inf112.fiasko.roborally.objects.RoboRallyGame; @@ -19,6 +19,7 @@ class RoboRallyClientListener extends Listener { /** * Instantiates a new Robo Rally client listener + * * @param wrapper The Robo Rally wrapper to interact with */ RoboRallyClientListener(RoboRallyWrapper wrapper) { @@ -27,7 +28,7 @@ class RoboRallyClientListener extends Listener { } @Override - public void received (Connection connection, Object object) { + public void received(Connection connection, Object object) { if (object instanceof ErrorResponse) { ErrorResponse errorResponse = (ErrorResponse) object; if (errorResponse.isCritical()) { @@ -37,7 +38,7 @@ class RoboRallyClientListener extends Listener { } else if (object instanceof GameStartInfo) { GameStartInfo info = (GameStartInfo) object; wrapper.roboRallyGame = new RoboRallyGame(info.getPlayerList(), info.getBoardName(), - wrapper.server != null, info.getPlayerName(), wrapper.client, wrapper.server); + wrapper.server != null, info.getPlayerName(), wrapper.server); } else if (object instanceof ProgrammingCardDeck) { wrapper.roboRallyGame.setGameState(GameState.CHOOSING_CARDS); wrapper.roboRallyGame.setPlayerHand((ProgrammingCardDeck) object); @@ -47,8 +48,8 @@ class RoboRallyClientListener extends Listener { } catch (InterruptedException e) { e.printStackTrace(); } - } else if (object instanceof PowerdownContainer) { - wrapper.roboRallyGame.receiveStayInPowerDown((PowerdownContainer) object); + } else if (object instanceof PowerDownContainer) { + wrapper.roboRallyGame.receiveStayInPowerDown((PowerDownContainer) object); } } diff --git a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServer.java b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServer.java index b710f54..ce539cc 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServer.java +++ b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServer.java @@ -4,6 +4,7 @@ import com.esotericsoftware.kryonet.Connection; import com.esotericsoftware.kryonet.Server; import inf112.fiasko.roborally.elementproperties.RobotID; import inf112.fiasko.roborally.utility.NetworkUtil; + import java.io.IOException; import java.util.List; import java.util.Map; @@ -17,6 +18,7 @@ public class RoboRallyServer { /** * Instantiates a new Robo Rally server + * * @throws IOException If the server cannot be started */ public RoboRallyServer() throws IOException { @@ -30,6 +32,7 @@ public class RoboRallyServer { /** * Makes notice of players which are dead and as such should not be expected to send anything + * * @param deadRobotList A list of robot ids of robots which are permanently dead */ public void setDeadPlayers(List deadRobotList) { @@ -38,6 +41,7 @@ public class RoboRallyServer { /** * Gets a map between connections and their robot id + * * @return A mapping between connections and robot ids */ public Map getRobotID() { @@ -46,6 +50,7 @@ public class RoboRallyServer { /** * Gets a map between connections and their player name + * * @return A mapping between connections and robot ids */ public Map getPlayerNames() { @@ -54,6 +59,7 @@ public class RoboRallyServer { /** * Sends an object to all clients + * * @param object The object to send */ public void sendToAllClients(Object object) { @@ -62,8 +68,9 @@ public class RoboRallyServer { /** * Sends an object to a specific client + * * @param connection The connection to send the object to - * @param object The object to send + * @param object The object to send */ public void sendToClient(Connection connection, Object object) { server.sendToTCP(connection.getID(), object); diff --git a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServerListener.java b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServerListener.java index be1f295..b34ff8d 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServerListener.java +++ b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServerListener.java @@ -5,12 +5,11 @@ import com.esotericsoftware.kryonet.Connection; import com.esotericsoftware.kryonet.Listener; import inf112.fiasko.roborally.elementproperties.RobotID; import inf112.fiasko.roborally.networking.containers.ErrorResponse; -import inf112.fiasko.roborally.networking.containers.PowerdownContainer; +import inf112.fiasko.roborally.networking.containers.PowerDownContainer; import inf112.fiasko.roborally.networking.containers.ProgamsContainer; import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest; import inf112.fiasko.roborally.objects.ProgrammingCard; -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -21,16 +20,17 @@ import java.util.Set; * This listener handles all sending and responses for the server */ class RoboRallyServerListener extends Listener { - private Connection host; private final Map clients; private final Map playerNames; private final List deadPlayers; + private final RoboRallyServer server; + private Connection host; private Map stayInPowerDown; private Map programs; - private final RoboRallyServer server; /** * Instantiates a new Robo Rally server listener + * * @param server The Robo Rally server using the listener */ RoboRallyServerListener(RoboRallyServer server) { @@ -45,6 +45,7 @@ class RoboRallyServerListener extends Listener { /** * Lets the server know which players have lost this game. + * * @param deadRobots List of RobotID */ public void setDeadPlayers(List deadRobots) { @@ -59,6 +60,7 @@ class RoboRallyServerListener extends Listener { /** * Gets a map between connections and their player name + * * @return A mapping between connections and robot ids */ public Map getPlayerNames() { @@ -67,6 +69,7 @@ class RoboRallyServerListener extends Listener { /** * Gets a map between connections and their robot id + * * @return A mapping between connections and robot ids */ public Map getRobotID() { @@ -74,7 +77,7 @@ class RoboRallyServerListener extends Listener { } @Override - public void received (Connection connection, Object object) { + public void received(Connection connection, Object object) { if (object instanceof String) { receivedString(connection, (String) object); } else if (object instanceof Boolean) { @@ -86,6 +89,7 @@ class RoboRallyServerListener extends Listener { /** * Handles the receiving of a string, handled as a player name in this context + * * @param connection The connection sending the string * @param playerName The player name received */ @@ -100,8 +104,9 @@ class RoboRallyServerListener extends Listener { /** * Handles the receiving of continuing power down + * * @param connection The connection sending the stay in power down value - * @param bool The stay in power down value received + * @param bool The stay in power down value received */ private void receiveContinuePowerDown(Connection connection, Boolean bool) { stayInPowerDown.put(connection, bool); @@ -110,18 +115,19 @@ class RoboRallyServerListener extends Listener { for (Connection connected : stayInPowerDown.keySet()) { powerDowns.put(playerNames.get(connected), stayInPowerDown.get(connected)); } - server.sendToAllClients(new PowerdownContainer(powerDowns)); + server.sendToAllClients(new PowerDownContainer(powerDowns)); stayInPowerDown = new HashMap<>(); } } /** * Handles the receiving of a player's program and whether they want to power down + * * @param connection The connection sending the program and power down request - * @param request The program and power down request received + * @param request The program and power down request received */ private void receiveProgramAndPowerDownRequest(Connection connection, ProgramAndPowerdownRequest request) { - programs.put(connection,request); + programs.put(connection, request); if (receivedDataFromAllConnections(programs)) { Map powerDown = new HashMap<>(); Map> program = new HashMap<>(); @@ -136,11 +142,12 @@ class RoboRallyServerListener extends Listener { /** * Checks whether the input map contains data received by all expected connections + * * @param data A map between connections and some type of data - * @param The type of the data contained in the map + * @param The type of the data contained in the map * @return True if information has been received by all alive players */ - private boolean receivedDataFromAllConnections(Map data) { + private boolean receivedDataFromAllConnections(Map data) { Set connections = clients.keySet(); connections.removeAll(deadPlayers); return connections.containsAll(data.keySet()) && data.keySet().containsAll(connections); diff --git a/src/main/java/inf112/fiasko/roborally/networking/containers/ErrorResponse.java b/src/main/java/inf112/fiasko/roborally/networking/containers/ErrorResponse.java index 03960f9..9b010a1 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/containers/ErrorResponse.java +++ b/src/main/java/inf112/fiasko/roborally/networking/containers/ErrorResponse.java @@ -9,6 +9,7 @@ public class ErrorResponse { /** * Constructs a new error response + * * @param errorMessage The error message describing the error */ public ErrorResponse(String errorMessage) { @@ -18,8 +19,9 @@ public class ErrorResponse { /** * Constructs a new error response + * * @param errorMessage The error message describing the error - * @param critical Whether the error is critical + * @param critical Whether the error is critical */ public ErrorResponse(String errorMessage, boolean critical) { this.errorMessage = errorMessage; @@ -28,6 +30,7 @@ public class ErrorResponse { /** * Gets the error message attached to the error response + * * @return An error message */ public String getErrorMessage() { @@ -36,6 +39,7 @@ public class ErrorResponse { /** * Gets whether the error is critical or not + * * @return True if the error is critical. False otherwise */ public boolean isCritical() { diff --git a/src/main/java/inf112/fiasko/roborally/networking/containers/GameStartInfo.java b/src/main/java/inf112/fiasko/roborally/networking/containers/GameStartInfo.java index de98d3b..21d9eac 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/containers/GameStartInfo.java +++ b/src/main/java/inf112/fiasko/roborally/networking/containers/GameStartInfo.java @@ -15,18 +15,24 @@ public class GameStartInfo { /** * Empty initialization method required by kryo */ - public GameStartInfo() {} + public GameStartInfo() { + } /** - * Sets the player name of the current player - * @param playerName The player name of the current player + * Instantiates a new GameStartInfo object + * + * @param boardName The name of the board to be used, with extension + * @param playerList List of players for the game */ - public void setPlayerName(String playerName) { - this.playerName = playerName; + public GameStartInfo(String boardName, List playerList, String name) { + this.playerName = name; + this.boardName = boardName; + this.playerList = playerList; } /** * Gets the player name of the current player + * * @return The player name of the current player */ public String getPlayerName() { @@ -34,46 +40,48 @@ public class GameStartInfo { } /** - * Sets the name of the board to be used - * @param boardName The name of the board to be used, with extension + * Sets the player name of the current player + * + * @param playerName The player name of the current player */ - public void setBoardName(String boardName) { - this.boardName = boardName; - } - - /** - * Sets the list of players for the game - * @param playerList List of players for the game - */ - public void setPlayerList(List playerList) { - this.playerList = playerList; - } - - /** - * Instantiates a new GameStartInfo object - * @param boardName The name of the board to be used, with extension - * @param playerList List of players for the game - */ - public GameStartInfo(String boardName, List playerList,String name) { - this.playerName=name; - this.boardName = boardName; - this.playerList = playerList; + public void setPlayerName(String playerName) { + this.playerName = playerName; } /** * Gets the list of players + * * @return A list of players */ public List getPlayerList() { return playerList; } + /** + * Sets the list of players for the game + * + * @param playerList List of players for the game + */ + public void setPlayerList(List playerList) { + this.playerList = playerList; + } + /** * Gets the board name + * * @return The board name */ public String getBoardName() { return boardName; } + /** + * Sets the name of the board to be used + * + * @param boardName The name of the board to be used, with extension + */ + public void setBoardName(String boardName) { + this.boardName = boardName; + } + } diff --git a/src/main/java/inf112/fiasko/roborally/networking/containers/PowerdownContainer.java b/src/main/java/inf112/fiasko/roborally/networking/containers/PowerDownContainer.java similarity index 84% rename from src/main/java/inf112/fiasko/roborally/networking/containers/PowerdownContainer.java rename to src/main/java/inf112/fiasko/roborally/networking/containers/PowerDownContainer.java index 0bd6880..8849b12 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/containers/PowerdownContainer.java +++ b/src/main/java/inf112/fiasko/roborally/networking/containers/PowerDownContainer.java @@ -5,19 +5,21 @@ import java.util.Map; /** * This class is used to contain power down status for all players */ -public class PowerdownContainer { +public class PowerDownContainer { private final Map powerDown; /** * Instantiates a new power down container + * * @param powerDown A map between player names and whether they should remain in power down */ - public PowerdownContainer(Map powerDown) { + public PowerDownContainer(Map powerDown) { this.powerDown = powerDown; } /** * Gets the power down map stored in the container + * * @return A map between player name and stay in power down */ public Map getPowerDown() { diff --git a/src/main/java/inf112/fiasko/roborally/networking/containers/ProgamsContainer.java b/src/main/java/inf112/fiasko/roborally/networking/containers/ProgamsContainer.java index 610a205..d2b17ea 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/containers/ProgamsContainer.java +++ b/src/main/java/inf112/fiasko/roborally/networking/containers/ProgamsContainer.java @@ -7,10 +7,12 @@ import java.util.Map; public class ProgamsContainer { private Map> program; - private Map powerdown; + private Map powerdown; - public ProgamsContainer(){} - public ProgamsContainer(Map> program, Map powerdown) { + public ProgamsContainer() { + } + + public ProgamsContainer(Map> program, Map powerdown) { this.program = program; this.powerdown = powerdown; } @@ -18,6 +20,7 @@ public class ProgamsContainer { public Map> getProgram() { return program; } + public Map getPowerdown() { return powerdown; } diff --git a/src/main/java/inf112/fiasko/roborally/networking/containers/ProgramAndPowerdownRequest.java b/src/main/java/inf112/fiasko/roborally/networking/containers/ProgramAndPowerdownRequest.java index 28b66b0..8e31b92 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/containers/ProgramAndPowerdownRequest.java +++ b/src/main/java/inf112/fiasko/roborally/networking/containers/ProgramAndPowerdownRequest.java @@ -8,9 +8,11 @@ public class ProgramAndPowerdownRequest { private Boolean powerdown; private List program; - public ProgramAndPowerdownRequest(){} + public ProgramAndPowerdownRequest() { + } + public ProgramAndPowerdownRequest(Boolean powerdown, List program) { - this.program=program; + this.program = program; this.powerdown = powerdown; }