summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/luxons/sevenwonders/repositories/GameRepository.java14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/repositories/GameRepository.java b/src/main/java/org/luxons/sevenwonders/repositories/GameRepository.java
index 59e984af..efe39b85 100644
--- a/src/main/java/org/luxons/sevenwonders/repositories/GameRepository.java
+++ b/src/main/java/org/luxons/sevenwonders/repositories/GameRepository.java
@@ -12,14 +12,14 @@ public class GameRepository {
private Map<Long, Game> games = new HashMap<>();
- public void add(Game game) {
+ public void add(Game game) throws GameAlreadyExistsException {
if (games.containsKey(game.getId())) {
throw new GameAlreadyExistsException(game.getId());
}
games.put(game.getId(), game);
}
- public Game find(long gameId) {
+ public Game find(long gameId) throws GameNotFoundException {
Game game = games.get(gameId);
if (game == null) {
throw new GameNotFoundException(gameId);
@@ -27,13 +27,21 @@ public class GameRepository {
return game;
}
+ public Game remove(long gameId) throws GameNotFoundException {
+ Game game = games.remove(gameId);
+ if (game == null) {
+ throw new GameNotFoundException(gameId);
+ }
+ return game;
+ }
+
public static class GameNotFoundException extends ApiMisuseException {
GameNotFoundException(long id) {
super("Game " + id + " doesn't exist");
}
}
- private static class GameAlreadyExistsException extends ApiMisuseException {
+ static class GameAlreadyExistsException extends ApiMisuseException {
GameAlreadyExistsException(long id) {
super("Game " + id + " already exists");
}
bgstack15