--- /dev/null
+package net.jaekl.squelch.db;
+
+import java.util.Locale;
+
+public class Setting {
+ private String m_name;
+ private Class<?> m_type;
+ private Object m_value;
+
+ public Setting(String name, Class<?> type, Object defaultValue)
+ {
+ m_name = name;
+ m_type = type;
+ m_value = defaultValue;
+ }
+
+ public String getName() { return m_name; }
+
+ public boolean getBoolean()
+ {
+ assert(Boolean.class == m_type);
+
+ if (m_value instanceof Boolean) {
+ return ((Boolean)m_value).booleanValue();
+ }
+ return false;
+ }
+
+ public void set(Object value)
+ {
+ if (Boolean.class == m_type) {
+ if (value instanceof String) {
+ m_value = parseBoolean((String)value);
+ }
+ else if (value instanceof Boolean) {
+ m_value = value;
+ }
+ }
+ else {
+ throw new IllegalArgumentException("This type not yet supported.");
+ }
+ }
+
+ private boolean parseBoolean(String value)
+ {
+ if (null == value) {
+ return false;
+ }
+
+ String setting = value.trim().toLowerCase(Locale.CANADA);
+
+ if (setting.equals("yes") || setting.equals("true") || setting.equals("on") || setting.equals("1")) {
+ return true;
+ }
+ if (setting.equals("no") || setting.equals("false") || setting.equals("off") || setting.equals("0")) {
+ return false;
+ }
+
+ throw new IllegalArgumentException("UnrecognizedBooleanValue: \"" + value + "\"");
+ }
+}