Java Utililty Methods Preference

List of utility methods to do Preference

Description

The list of methods to do Preference are organized into topic(s).

Method

booleanbackingStoreAvailable(Preferences prefs)
Test whether preference can be written to disk from: http://java.sun.com/j2se/1.4.2/docs/guide/lang/preferences.html#prefs-usage-backingstore
try {
    boolean oldValue = prefs.getBoolean(BACKING_STORE_AVAIL, false);
    prefs.putBoolean(BACKING_STORE_AVAIL, !oldValue);
    prefs.flush();
} catch (BackingStoreException e) {
    return false;
return true;
...
LocalecambiarIdioma(String lang, String country)
Metodo que cambia el lenguaje.
Preferences userPreferences = Preferences.userRoot();
userPreferences.put("COUNTRY", country);
userPreferences.put("LANG", lang);
return new Locale(lang, country);
ClassclassFor(Object obj)
Returns the class for the given Object.
Class<?> c = null;
try {
    c = Class.forName(obj.getClass().getCanonicalName());
} catch (ClassNotFoundException e) {
    e.printStackTrace();
    c = Preferences.class;
return c;
...
voidclearPreference(Object context)
clear Preference
try {
    prefs = Preferences.userRoot().node(context.getClass().getName());
    prefs.clear();
} catch (BackingStoreException e) {
    e.printStackTrace();
voidcount(Preferences preferences, String preferenceName)
count
int count = preferences.getInt(preferenceName, 0);
preferences.putInt(preferenceName, count + 1);
PreferencescreateNode(String path)
Get node path, create if not already existing.
assert !path.startsWith("/");
return Preferences.userRoot().node(path);
booleanhasEnv(String key, String value)
has Env
if (value == null || "".equals(value.trim())) {
    return false;
Preferences preferences = Preferences.systemRoot().node("/ice_water");
return value.equalsIgnoreCase(preferences.get(key, "_null_mode_"));
voidinitEnv(String key, String value)
init Env
Preferences preferences = Preferences.systemRoot().node("/ice_water");
if (key == null || "".equals(key.trim())) {
    key = "dev_java_mode";
preferences.put(key, value);
booleankeyExists(String className, String prefName)
note that this method is not guaranteed to return an accurate answer if the key in question is nullable.
final Preferences prefs = userNodeForClass(className);
return prefs.get(prefName, null) != null;
voidreadAllReg(String path)
read All Reg
Preferences prefsdemo = Preferences.systemRoot().node(path);
try {
    String[] regkeys = prefsdemo.keys();
    for (String key : regkeys) {
        String value = prefsdemo.get(key, null);
        System.out.println(value);
} catch (Exception e) {
...