diff options
author | Joffrey BION <joffrey.bion@gmail.com> | 2017-01-16 23:22:53 +0100 |
---|---|---|
committer | Joffrey BION <joffrey.bion@gmail.com> | 2017-01-16 23:22:53 +0100 |
commit | e1561eb0cbd82c81bea630d7b2f38c3962ffac5a (patch) | |
tree | b1577502af59367848e6e50e62a9d457d2a6cad1 /src/main/java | |
parent | Separate client and server errors in the ExceptionHandler (diff) | |
download | seven-wonders-e1561eb0cbd82c81bea630d7b2f38c3962ffac5a.tar.gz seven-wonders-e1561eb0cbd82c81bea630d7b2f38c3962ffac5a.tar.bz2 seven-wonders-e1561eb0cbd82c81bea630d7b2f38c3962ffac5a.zip |
Remove unicity constraint on game names
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/luxons/sevenwonders/repositories/LobbyRepository.java | 19 |
1 files changed, 3 insertions, 16 deletions
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<String, Lobby> lobbies = new HashMap<>(); - - private Map<Long, Lobby> lobbiesById = new HashMap<>(); + private Map<Long, Lobby> 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"); - } - } } |