All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.czyzby.autumn.mvc.component.preferences.dto.AbstractPreference Maven / Gradle / Ivy

Go to download

MVC framework based on LibGDX using Autumn for components management and LML as view templates.

There is a newer version: 1.9.1.9.6
Show newest version
package com.github.czyzby.autumn.mvc.component.preferences.dto;

import com.badlogic.gdx.Preferences;

/** Abstract base for a class implementing {@link Preference}.
 *
 * @author MJ
 *
 * @param  type of the preference. */
public abstract class AbstractPreference implements Preference {
    private Type preference;

    @Override
    public void read(final String name, final Preferences preferences) throws Exception {
        preference = convert(preferences.getString(name));
    }

    /** @param rawPreference raw preference value stored in the preferences file.
     * @return preference converted to the chosen preference type.
     * @see #convert(String) */
    protected abstract Type convert(String rawPreference);

    /** @param preference current preference value.
     * @return value that should be stored in the preferences file as the raw preference value.
     * @see #convert(String) */
    protected abstract String serialize(Type preference);

    @Override
    public Type get() {
        return preference;
    }

    @Override
    public void set(final Type preference) {
        this.preference = preference;
    }

    @Override
    public void save(final String name, final Preferences preferences) {
        preferences.putString(name, serialize(preference));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy