UPDATE
After response from Pimgd, I've made some changes and I'm left with this. Is this as clean as it can be?
public class Properties
{
/** String type properties. */
private final List<String> m_stringProperties = Arrays.asList("str1", "str2", "str3");
/** Float type properties. */
private final List<String> m_floatProperties = Arrays.asList("float1", "float2", "float3");
/** Integer type properties. */
private final List<String> m_intProperties = Arrays.asList("int1", "int2");
/**
* Returns the value of the given property if it exists.
*
* @param name The name of the property.
*
* @return The property value if it exists, null otherwise.
*/
public Object getProperty(String name)
{
return m_properties.get(name);
}
/**
* Sets the value of the given string-type property. If the property does not exist, it is added first.
* The function asserts if an invalid property name is supplied.
*
* @param name The name of the property. Asserts if null.
* @param value The value of the property. Asserts if null.
*
* @return None.
*/
public void setProperty(String name, String value)
{
assert name != null : "Null property name";
assert value != null : "Null property value";
if (m_stringProperties.contains(name))
{
m_properties.put(name, value);
}
else
{
assert false : "Invalid name for String property";
}
}
/**
* Sets the value of the given float-type property. If the property does not exist, it is added first.
* The function asserts if an invalid property name is supplied.
*
* @param name The name of the property. Asserts if null.
* @param value The value of the property. Asserts if null.
*
* @return None.
*/
public void setProperty(String name, Float value)
{
assert name != null : "Null property name";
assert value != null : "Null property value";
if (m_floatProperties.contains(name))
{
m_properties.put(name, value);
}
else
{
assert false : "Invalid name for Float property";
}
}
/**
* Sets the value of the given integer-type property. If the property does not exist, it is added first.
* The function asserts if an invalid property name is supplied.
*
* @param name The name of the property. Asserts if null.
* @param value The value of the property. Asserts if null.
*
* @return None.
*/
public void setProperty(String name, Integer value)
{
assert name != null : "Null property name";
assert value != null : "Null property value";
if (m_intProperties.contains(name))
{
m_properties.put(name, value);
}
else
{
assert false : "Invalid name for Integer property";
}
}
}