Java Utililty Methods Preference

List of utility methods to do Preference

  1. HOME
  2. Java
  3. P
  4. Preference

Description

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

Method

boolean backingStoreAvailable(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;
...
Locale cambiarIdioma(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);
Class classFor(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;
...
void clearPreference(Object context)
clear Preference
try {
 prefs = Preferences.userRoot().node(context.getClass().getName());
 prefs.clear();
} catch (BackingStoreException e) {
 e.printStackTrace();
void count(Preferences preferences, String preferenceName)
count
int count = preferences.getInt(preferenceName, 0);
preferences.putInt(preferenceName, count + 1);
Preferences createNode(String path)
Get node path, create if not already existing.
assert !path.startsWith("/");
return Preferences.userRoot().node(path);
boolean hasEnv(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_"));
void initEnv(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);
boolean keyExists(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;
void readAllReg(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) {
...


AltStyle によって変換されたページ (->オリジナル) /