You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.3 KiB
Java

/*
* Apocalypse Laboratories
* Open Source License
*
* Source code can be used for any purpose, as long as:
* - Compiled binaries are rebranded and trademarks are not
* visible by the end user at any time, except to give
* credit to Apocalypse Laboratories, such as by showing
* "Based on <product> by Apocalypse Laboratories" or a
* similar notice;
* - You do not use the code for evil;
* - Rebranded compiled applications have significant
* differences in functionality;
* - and you provide your modified source code for download,
* under the terms of the GNU LGPL v3 or a comparable
* license.
*
* Compiled binaries cannot be redistributed or mirrored,
* unless:
* - You have written permission from Apocalypse Laboratories;
* - Downloads are not available from Apocalypse Laboratories,
* not even behind a paywall or other blocking mechanism;
* - or you have received a multi-computer license, in which
* case you should take measures to prevent unauthorized
* downloads, such as preventing download access from the
* Internet.
*/
package net.apocalypselabs.symat;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
/**
*
* @author Skylar Ittner
*/
public class PrefStorage {
private static final Preferences prefs = Preferences.userNodeForPackage(PrefStorage.class);
public static void saveSetting(String key, String value) {
prefs.put(key, value);
}
public static boolean isset(String key) {
return !getSetting(key, "NULL").equals("NULL");
}
public static void unset(String key) {
prefs.remove(key);
}
public static String getSetting(String key) {
return prefs.get(key, "");
}
public static String getSetting(String key, String emptyResponse) {
return prefs.get(key, emptyResponse);
}
public static boolean save() {
try {
prefs.flush();
} catch (BackingStoreException ex) {
System.err.println("Settings could not be saved!");
return false;
}
return true;
}
// xkcd 221 compliance.
int getRandomNumber() {
return 4; // chosen by fair dice roll.
// guaranteed to be random.
}
}