Hi, I have a few methods to easily get a value from a HashMap which I load into from an .ini file.
The first method returns a float value from the ini if the key exists, otherwise returns the default value. The second method returns an enum of any type depending on what default value you put in. I’m not sure about the second method. It works, but is it correct?
public float GetFloat(String key, float defaultValue)
{
String value = m_mapValues.get(key);
if (value == null)
return defaultValue;
else
return Float.parseFloat(value);
}
public Enum<?> GetEnum(String key, Enum<?> defaultValue)
{
String value = m_mapValues.get(key);
if (value == null)
return defaultValue;
else
{
value = value.toUpperCase();
return Enum.valueOf(defaultValue.getDeclaringClass(), value);
}
}