refactor: simplify map operations

we can use computeIfAbsent here
This commit is contained in:
Breno A. 2024-06-09 09:13:18 -03:00
parent 3119e0fffc
commit c7119aae68
2 changed files with 2 additions and 8 deletions

View File

@ -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;
}

View File

@ -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());
});
}