From fa6207e47dceeec9be9a75bf293e6eea992f7d31 Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Mon, 31 May 2021 23:22:57 +0200 Subject: [PATCH] feat: characterConfig now has a HashMap for values --- .../json/config/CharacterConfig.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/config/CharacterConfig.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/config/CharacterConfig.java index 0b0f0b6..38f875f 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/config/CharacterConfig.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/config/CharacterConfig.java @@ -1,8 +1,34 @@ package uulm.teamname.marvelous.gamelibrary.json.config; +import com.fasterxml.jackson.annotation.JsonIgnore; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + /** * POJO describing the CharacterConfig as defined by the standard document. */ public class CharacterConfig { public CharacterProperties[] characters; + + @JsonIgnore private Map propertyMap; + @JsonIgnore private Map unmodifiablePropertyMap; + + /** + * @return a unmodifiable {@link Map}<{@link String}, {@link CharacterProperties}> containing all properties. + * If not yet existent, initialize the Map + */ + public Map getMap() { + // lazy initialization + if (propertyMap == null) { + propertyMap = new HashMap<>(); + for (CharacterProperties property: characters) { + propertyMap.put(property.name, property); + } + unmodifiablePropertyMap = Collections.unmodifiableMap(propertyMap); + } + + return unmodifiablePropertyMap; + } }