
package de.longri.cachebox3.settings.types;

public class SettingString extends SettingBase<String> {
    public static final String STRING_SPLITTER = "�";

    public SettingString(String name, SettingCategory category, SettingMode modus, String defaultValue, SettingStoreType StoreType, SettingUsage usage) {
        this(name, category, modus, defaultValue, StoreType, usage, false);
    }

    public SettingString(String name, SettingCategory category, SettingMode modus, String defaultValue, SettingStoreType StoreType, SettingUsage usage, boolean desired) {
        super(name, category, modus, StoreType, usage, desired);
        this.defaultValue = defaultValue;
        this.value = defaultValue;
    }

    @Override
    public Object toDbValue() {
        return String.valueOf(value);
    }

    @Override
    public boolean fromDbvalue(Object dbString) {
        try {
            value = (String) dbString;
            return true;
        } catch (Exception ex) {
            value = defaultValue;
            return false;
        }
    }

    @Override
    public SettingBase<String> copy() {
        SettingBase<String> ret = new SettingString(this.name, this.category, this.mode, this.defaultValue, this.storeType, usage);
        ret.value = this.value;
        ret.lastValue = this.lastValue;
        return ret;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof SettingString))
            return false;

        SettingString inst = (SettingString) obj;
        if (!(inst.name.equals(this.name)))
            return false;
        if (!inst.value.equals(this.value))
            return false;

        return true;
    }

}
