package za.co.taulite.tools.smppclient;
|
|
import com.google.gson.Gson;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.PostConstruct;
|
import java.util.prefs.Preferences;
|
|
@Component
|
public class MSPrefs {
|
|
private static final String PREFS_ROOT = "za/co/taulite/tools/smppclient";
|
private static final Gson GSON = new Gson();
|
|
|
private Preferences prefs;
|
|
@PostConstruct
|
private void init() {
|
prefs = Preferences.userRoot().node(PREFS_ROOT);
|
}
|
|
public void set(String key, Object value) {
|
prefs.put(key, GSON.toJson(value));
|
}
|
|
public <T> T get(String key, Class<T> clazz) {
|
var value = prefs.get(key, null);
|
if (value == null) {
|
return null;
|
}
|
return GSON.fromJson(value, clazz);
|
}
|
}
|