/** * Flushes the preferences (system and user). * * @throws BackingStoreException if failed */ public void flush() throws BackingStoreException { if (!systemOnly) { getUserPrefs().flush(); } getSystemPrefs().flush(); }
/** * Syncs the preferences (system and user). * * @throws BackingStoreException if failed */ public void sync() throws BackingStoreException { if (!systemOnly) { getUserPrefs().sync(); } getSystemPrefs().sync(); }
/** * Returns the root preference node for the system. * <p> * Redirected to the {@link PersistedPreferencesFactory}. * * @return the root preference node for the system. */ static PersistedPreferences systemRoot() { return PersistedPreferencesFactory.getInstance().getSystemRoot(); }
/** * Returns the preference node from the system preference tree that is associated (by convention) with the specified * class's package. * <p> * Redirected to the {@link PersistedPreferencesFactory}. * * @param c the class for whose package a system preference node is desired. * @return the system preference node associated with the package of which <tt>c</tt> is a member. * @see java.util.prefs.Preferences#systemNodeForPackage(java.lang.Class) */ static PersistedPreferences systemNodeForPackage(Class<?> c) { return PersistedPreferencesFactory.getInstance().systemNodeForPackage(c); }
/** * Returns the root preference node for the user. * <p> * Redirected to the {@link PersistedPreferencesFactory}. * * @return the root preference node for the user. */ static PersistedPreferences userRoot() { return PersistedPreferencesFactory.getInstance().getUserRoot(); }
/** * Returns the preference node from the user preference tree that is associated (by convention) with the specified * class's package. * <p> * Redirected to the {@link PersistedPreferencesFactory}. * * @param c the class for whose package a system preference node is desired. * @return the user preference node associated with the package of which <tt>c</tt> is a member. * @see java.util.prefs.Preferences#userNodeForPackage(java.lang.Class) */ static PersistedPreferences userNodeForPackage(Class<?> c) { return PersistedPreferencesFactory.getInstance().userNodeForPackage(c); }
/** * Gets the factory singleton. * * @return the factory */ public static DbPreferencesFactory getInstance() { return (DbPreferencesFactory) PersistedPreferencesFactory.getInstance(); }
/** * Gets the value for a key. * Userspace overwrites systemspace. * * @param key the preferences key * @return the value string or null if no such value */ public String getString(String key) { String val = null; if (!systemOnly) { val = getUserPrefs().get(key, null); } if (val == null) { val = getSystemPrefs().get(key, null); } return val; }
/** * Gets a bytearray from the preferences. * * @param key the preferences key * @return the byte array or null if no such value */ public byte[] getByteArray(String key) { byte[] val = null; if (!systemOnly) { val = getUserPrefs().getByteArray(key, null); } if (val == null) { val = getSystemPrefs().getByteArray(key, null); } return val; }
/** * Sets a Double.<br> * If the value is the same as in systemspace, the user value is removed. * Null-values also perform a remove. * * @param key the preferences key * @param val the value */ public void setDouble(String key, Double val) { setString(key, val == null ? null : val.toString()); }
/** * Gets the value for a key. * Userspace overwrites systemspace. * * @param key the preferences key * @param def the default value * @return the value string */ public String getString(String key, String def) { String val = getString(key); return val == null ? def : val; }
/** * Gets a long value. * * @param key the preferences key * @param def the default value * @return the integer */ public long getLong(String key, long def) { Long val = getALong(key); return val == null ? def : val; }
/** * Gets a bytearray from the preferences. * * @param key the preferences key * @param def the default values * @return the byte array */ public byte[] getByteArray(String key, byte[] def) { byte[] val = getByteArray(key); return val == null ? def : val; }
/** * Gets an int value. * * @param key the preferences key * @param def the default value * @return the integer */ public int getInt(String key, int def) { Integer val = getInteger(key); return val == null ? def : val; }
/** * Gets a double value. * * @param key the preferences key * @param def the default value * @return the integer */ public double getDouble(String key, double def) { Double val = getADouble(key); return val == null ? def : val; }
/** * Gets a float value. * * @param key the preferences key * @param def the default value * @return the integer */ public float getFloat(String key, float def) { Float val = getAFloat(key); return val == null ? def : val; }
/** * Gets a boolean value. * * @param key the preferences key * @param def the default value * @return the integer */ public boolean getBoolean(String key, boolean def) { Boolean val = getABoolean(key); return val == null ? def : val; }
/** * Gets the system preferences. * * @return the system-scope preferences */ public PersistedPreferences getSystemPrefs() { if (systemPrefs == null) { systemPrefs = PersistedPreferencesFactory.getInstance().systemNodeForPackage(this.getClass()); } return systemPrefs; }
/** * Gets the DbPreferencesFactory singleton. * * @return the factory singleton, never null */ private DbPreferencesFactory getFactory() { return (DbPreferencesFactory) PersistedPreferencesFactory.getInstance(); }
/** * Sets a Boolean.<br> * If the value is the same as in systemspace, the user value is removed. * Null-values also perform a remove. * * @param key the preferences key * @param val the value */ public void setBoolean(String key, Boolean val) { setString(key, val == null ? null : val.toString()); }