From e1561eb0cbd82c81bea630d7b2f38c3962ffac5a Mon Sep 17 00:00:00 2001 From: Joffrey BION Date: Mon, 16 Jan 2017 23:22:53 +0100 Subject: Remove unicity constraint on game names --- .../sevenwonders/repositories/LobbyRepository.java | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/luxons/sevenwonders/repositories/LobbyRepository.java b/src/main/java/org/luxons/sevenwonders/repositories/LobbyRepository.java index 3561161b..dce824ad 100644 --- a/src/main/java/org/luxons/sevenwonders/repositories/LobbyRepository.java +++ b/src/main/java/org/luxons/sevenwonders/repositories/LobbyRepository.java @@ -4,7 +4,6 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; -import org.luxons.sevenwonders.errors.UserInputException; import org.luxons.sevenwonders.game.Lobby; import org.luxons.sevenwonders.game.Player; import org.luxons.sevenwonders.game.data.GameDefinitionLoader; @@ -16,9 +15,7 @@ public class LobbyRepository { private final GameDefinitionLoader gameDefinitionLoader; - private Map lobbies = new HashMap<>(); - - private Map lobbiesById = new HashMap<>(); + private Map lobbies = new HashMap<>(); private long lastGameId = 0; @@ -32,18 +29,14 @@ public class LobbyRepository { } public Lobby create(String gameName, Player owner) { - if (lobbies.containsKey(gameName)) { - throw new GameNameAlreadyUsedException(gameName); - } long id = lastGameId++; Lobby lobby = new Lobby(id, gameName, owner, gameDefinitionLoader.getGameDefinition()); - lobbies.put(gameName, lobby); - lobbiesById.put(id, lobby); + lobbies.put(id, lobby); return lobby; } public Lobby find(long lobbyId) { - Lobby lobby = lobbiesById.get(lobbyId); + Lobby lobby = lobbies.get(lobbyId); if (lobby == null) { throw new LobbyNotFoundException(String.valueOf(lobbyId)); } @@ -55,10 +48,4 @@ public class LobbyRepository { super("Lobby not found for game '" + name + "'"); } } - - private static class GameNameAlreadyUsedException extends UserInputException { - GameNameAlreadyUsedException(String name) { - super("Game name '" + name + "' already exists"); - } - } } -- cgit