/** * 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 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; }
/** * Flushes the preferences (system and user). * * @throws BackingStoreException if failed */ public void flush() throws BackingStoreException { if (!systemOnly) { getUserPrefs().flush(); } getSystemPrefs().flush(); }
/** * Sets a bytearray.<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 values */ public void setByteArray(String key, byte[] val) { if (!systemOnly) { if (val == null || areByteArraysEqual(val, getSystemPrefs().getByteArray(key, null))) { getUserPrefs().remove(key); } else { getUserPrefs().putByteArray(key, val); } } else { if (val == null) { getSystemPrefs().remove(key); } else { getSystemPrefs().putByteArray(key, val); } } }
/** * 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; }
/** * Syncs the preferences (system and user). * * @throws BackingStoreException if failed */ public void sync() throws BackingStoreException { if (!systemOnly) { getUserPrefs().sync(); } getSystemPrefs().sync(); }
/** * Gets a Double. * * @param key the preferences key * @return the integer or null if no such value */ public Double getADouble(String key) { String val = getString(key); return val == null ? null : Double.valueOf(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; }
/** * Gets an Integer. * * @param key the preferences key * @return the integer or null if no such value */ public Integer getInteger(String key) { String val = getString(key); return val == null ? null : Integer.valueOf(val); }
/** * 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 Boolean. * * @param key the preferences key * @return the integer or null if no such value */ public Boolean getABoolean(String key) { String val = getString(key); return val == null ? null : Boolean.valueOf(val); }
/** * Sets the value for a key.<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 setString(String key, String val) { if (!systemOnly) { if (val == null || Objects.equals(val, getSystemPrefs().get(key, null))) { getUserPrefs().remove(key); } else { getUserPrefs().put(key, val); } } else { if (val == null) { getSystemPrefs().remove(key); } else { getSystemPrefs().put(key, val); } } }
/** * Gets a Long. * * @param key the preferences key * @return the integer or null if no such value */ public Long getALong(String key) { String val = getString(key); return val == null ? null : Long.valueOf(val); }
/** * Gets a Float. * * @param key the preferences key * @return the integer or null if no such value */ public Float getAFloat(String key) { String val = getString(key); return val == null ? null : Float.valueOf(val); }