diff options
author | joffrey-bion <joffrey.bion@gmail.com> | 2021-02-09 17:10:41 +0100 |
---|---|---|
committer | joffrey-bion <joffrey.bion@gmail.com> | 2021-02-09 17:12:22 +0100 |
commit | e7ee3ea35ad7188d32403933187c345442fbab0a (patch) | |
tree | 894879b14c8d89a9ed85d2e40341bb03dd3c9b50 /sw-server/src/main/kotlin/org/luxons | |
parent | Fix bot logger (diff) | |
download | seven-wonders-e7ee3ea35ad7188d32403933187c345442fbab0a.tar.gz seven-wonders-e7ee3ea35ad7188d32403933187c345442fbab0a.tar.bz2 seven-wonders-e7ee3ea35ad7188d32403933187c345442fbab0a.zip |
Rename find->get to imply non-null check
Diffstat (limited to 'sw-server/src/main/kotlin/org/luxons')
6 files changed, 11 insertions, 9 deletions
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameBrowserController.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameBrowserController.kt index d6573f8f..9530a6b7 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameBrowserController.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameBrowserController.kt @@ -57,7 +57,7 @@ class GameBrowserController( fun createGame(@Validated action: CreateGameAction, principal: Principal): LobbyDTO { checkThatUserIsNotInAGame(principal, "cannot create another game") - val player = playerRepository.find(principal.name) + val player = playerRepository.get(principal.name) val lobby = lobbyRepository.create(action.gameName, owner = player) logger.info("Game '{}' ({}) created by {} ({})", lobby.name, lobby.id, player.displayName, player.username) @@ -81,8 +81,8 @@ class GameBrowserController( fun joinGame(@Validated action: JoinGameAction, principal: Principal): LobbyDTO { checkThatUserIsNotInAGame(principal, "cannot join another game") - val lobby = lobbyRepository.find(action.gameId) - val player = playerRepository.find(principal.name) + val lobby = lobbyRepository.get(action.gameId) + val player = playerRepository.get(principal.name) synchronized(lobby) { lobby.addPlayer(player) @@ -93,7 +93,7 @@ class GameBrowserController( } private fun checkThatUserIsNotInAGame(principal: Principal, impossibleActionDescription: String) { - val player = playerRepository.find(principal.name) + val player = playerRepository.get(principal.name) if (player.isInLobby || player.isInGame) { throw UserAlreadyInGameException(player.lobby.name, impossibleActionDescription) } diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt index 3313d22c..4f948ccf 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt @@ -23,7 +23,7 @@ class GameController( private val lobbyRepository: LobbyRepository, ) { private val Principal.player - get() = playerRepository.find(name) + get() = playerRepository.get(name) /** * Notifies the game that the player is ready to receive his hand. diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt index 557a1714..732b9193 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt @@ -39,7 +39,7 @@ class LobbyController( @Value("\${server.port}") private val serverPort: String, ) { private val Principal.player: Player - get() = playerRepository.find(name) + get() = playerRepository.get(name) /** * Leaves the current lobby. diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/LobbyRepository.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/LobbyRepository.kt index 06afc78c..e45fb5e9 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/LobbyRepository.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/LobbyRepository.kt @@ -23,7 +23,7 @@ class LobbyRepository { return lobby } - fun find(lobbyId: Long): Lobby = lobbies[lobbyId] ?: throw LobbyNotFoundException(lobbyId) + fun get(lobbyId: Long): Lobby = lobbies[lobbyId] ?: throw LobbyNotFoundException(lobbyId) fun remove(lobbyId: Long): Lobby = lobbies.remove(lobbyId) ?: throw LobbyNotFoundException(lobbyId) } diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepository.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepository.kt index c93b219c..d2d8f967 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepository.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepository.kt @@ -20,7 +20,9 @@ class PlayerRepository { return p } - fun find(username: String): Player = players[username] ?: throw PlayerNotFoundException(username) + fun find(username: String): Player? = players[username] + + fun get(username: String): Player = find(username) ?: throw PlayerNotFoundException(username) fun remove(username: String): Player = players.remove(username) ?: throw PlayerNotFoundException(username) } diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/validation/DestinationAccessValidator.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/validation/DestinationAccessValidator.kt index e680f094..8920a1fd 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/validation/DestinationAccessValidator.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/validation/DestinationAccessValidator.kt @@ -35,7 +35,7 @@ class DestinationAccessValidator(private val lobbyRepository: LobbyRepository) { } private fun isUserInLobby(username: String, lobbyId: Long): Boolean = - lobbyRepository.find(lobbyId).containsUser(username) + lobbyRepository.get(lobbyId).containsUser(username) companion object { |