feat: characterConfig now has a HashMap for values

This commit is contained in:
Yannik Bretschneider 2021-05-31 23:22:57 +02:00
parent 9a9fe4ae97
commit fa6207e47d

View File

@ -1,8 +1,34 @@
package uulm.teamname.marvelous.gamelibrary.json.config; 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. * POJO describing the CharacterConfig as defined by the standard document.
*/ */
public class CharacterConfig { public class CharacterConfig {
public CharacterProperties[] characters; public CharacterProperties[] characters;
@JsonIgnore private Map<String, CharacterProperties> propertyMap;
@JsonIgnore private Map<String, CharacterProperties> unmodifiablePropertyMap;
/**
* @return a unmodifiable {@link Map}<{@link String}, {@link CharacterProperties}> containing all properties.
* If not yet existent, initialize the Map
*/
public Map<String, CharacterProperties> getMap() {
// lazy initialization
if (propertyMap == null) {
propertyMap = new HashMap<>();
for (CharacterProperties property: characters) {
propertyMap.put(property.name, property);
}
unmodifiablePropertyMap = Collections.unmodifiableMap(propertyMap);
}
return unmodifiablePropertyMap;
}
} }