mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-07 00:42:57 +08:00
refactor: simplify map operations
we can use computeIfAbsent here
This commit is contained in:
parent
3119e0fffc
commit
c7119aae68
@ -218,11 +218,7 @@ public class SotSManager extends BasePlayerManager {
|
|||||||
|
|
||||||
public CityInfoData getCityInfo(int cityId) {
|
public CityInfoData getCityInfo(int cityId) {
|
||||||
if (player.getCityInfoData() == null) player.setCityInfoData(new HashMap<>());
|
if (player.getCityInfoData() == null) player.setCityInfoData(new HashMap<>());
|
||||||
var cityInfo = player.getCityInfoData().get(cityId);
|
var cityInfo = player.getCityInfoData().computeIfAbsent(cityId, CityInfoData::new);
|
||||||
if (cityInfo == null) {
|
|
||||||
cityInfo = new CityInfoData(cityId);
|
|
||||||
player.getCityInfoData().put(cityId, cityInfo);
|
|
||||||
}
|
|
||||||
return cityInfo;
|
return cityInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -599,9 +599,7 @@ public class Player implements PlayerHook, FieldFetch {
|
|||||||
GameData.getSceneTagDataMap().values().stream()
|
GameData.getSceneTagDataMap().values().stream()
|
||||||
.filter(SceneTagData::isDefaultValid)
|
.filter(SceneTagData::isDefaultValid)
|
||||||
.forEach(sceneTag -> {
|
.forEach(sceneTag -> {
|
||||||
if (this.getSceneTags().get(sceneTag.getSceneId()) == null) {
|
this.getSceneTags().computeIfAbsent(sceneTag.getSceneId(), k -> new HashSet<>());
|
||||||
this.getSceneTags().put(sceneTag.getSceneId(), new HashSet<>());
|
|
||||||
}
|
|
||||||
this.getSceneTags().get(sceneTag.getSceneId()).add(sceneTag.getId());
|
this.getSceneTags().get(sceneTag.getSceneId()).add(sceneTag.getId());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user