com.github.czyzby.autumn.mvc.component.preferences.dto.AbstractPreference Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gdx-autumn-mvc Show documentation
Show all versions of gdx-autumn-mvc Show documentation
MVC framework based on LibGDX using Autumn for components management and LML as view templates.
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