From c7119aae68994a67f9b70e601e9bd99c984e1e07 Mon Sep 17 00:00:00 2001 From: "Breno A." Date: Sun, 9 Jun 2024 09:13:18 -0300 Subject: [PATCH] refactor: simplify map operations we can use computeIfAbsent here --- .../java/emu/grasscutter/game/managers/SotSManager.java | 6 +----- src/main/java/emu/grasscutter/game/player/Player.java | 4 +--- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/managers/SotSManager.java b/src/main/java/emu/grasscutter/game/managers/SotSManager.java index 6427de185..eeafe1a09 100644 --- a/src/main/java/emu/grasscutter/game/managers/SotSManager.java +++ b/src/main/java/emu/grasscutter/game/managers/SotSManager.java @@ -218,11 +218,7 @@ public class SotSManager extends BasePlayerManager { public CityInfoData getCityInfo(int cityId) { if (player.getCityInfoData() == null) player.setCityInfoData(new HashMap<>()); - var cityInfo = player.getCityInfoData().get(cityId); - if (cityInfo == null) { - cityInfo = new CityInfoData(cityId); - player.getCityInfoData().put(cityId, cityInfo); - } + var cityInfo = player.getCityInfoData().computeIfAbsent(cityId, CityInfoData::new); return cityInfo; } diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 83cd2447d..c8c65aded 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -599,9 +599,7 @@ public class Player implements PlayerHook, FieldFetch { GameData.getSceneTagDataMap().values().stream() .filter(SceneTagData::isDefaultValid) .forEach(sceneTag -> { - if (this.getSceneTags().get(sceneTag.getSceneId()) == null) { - this.getSceneTags().put(sceneTag.getSceneId(), new HashSet<>()); - } + this.getSceneTags().computeIfAbsent(sceneTag.getSceneId(), k -> new HashSet<>()); this.getSceneTags().get(sceneTag.getSceneId()).add(sceneTag.getId()); }); }