Package biz.onixs.util.settings
Class Settings
- java.lang.Object
-
- biz.onixs.util.settings.Settings
-
- Direct Known Subclasses:
FileBasedSettings,PropertyBasedSettings
public abstract class Settings extends Object
Base easy-to-use settings implementation. The collection of (key, value) pairs. The keys values are case-sensitive.
-
-
Constructor Summary
Constructors Constructor Description Settings()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleangetBoolean(String key)Returns a boolean value that corresponds to the given key.booleangetBoolean(String key, boolean defaultValue)Returns a boolean value that corresponds to the given key.intgetInteger(String key)Returns an integer value that corresponds to the given key.intgetInteger(String key, int defaultValue)Returns an integer value that corresponds to the given key.longgetLong(String key)Returns a long value that corresponds to the given key.longgetLong(String key, long defaultValue)Returns a long value that corresponds to the given key.StringgetString(String key)Returns a string value that corresponds to the given key.StringgetString(String key, String defaultValue)Returns a string value that corresponds to the given key.booleanisDefined(String key)Returns true if a corresponding value for the specified key is found, false otherwise.voidsetBoolean(String key, boolean value)Sets the value corresponding to the given key.voidsetBoolean(String key, boolean value, boolean flush)Sets the value corresponding to the given key.voidsetInteger(String key, int value)Sets the value corresponding to the given key.voidsetInteger(String key, int value, boolean flush)Sets the value corresponding to the given key.voidsetLong(String key, long value)Sets the value corresponding to the given key.voidsetLong(String key, long value, boolean flush)Sets the value corresponding to the given key.voidsetString(String key, String value)Sets the value corresponding to the given key.voidsetString(String key, String value, boolean flush)Sets the value corresponding to the given key.
-
-
-
Method Detail
-
getBoolean
public boolean getBoolean(String key)
Returns a boolean value that corresponds to the given key.- Parameters:
key- key- Returns:
- a boolean value that corresponds to the given key
- Throws:
IllegalArgumentException- if key isnullor empty; also if value cannot be found for the specified key
-
getBoolean
public boolean getBoolean(String key, boolean defaultValue)
Returns a boolean value that corresponds to the given key. If a value cannot be found then the specified default value is returned.- Parameters:
key- keydefaultValue- default value- Returns:
- a boolean value that corresponds to the given key
- Throws:
IllegalArgumentException- if key isnullor empty
-
setBoolean
public void setBoolean(String key, boolean value) throws IOException
Sets the value corresponding to the given key.- Parameters:
key- keyvalue- value- Throws:
IOException- if value storing failedIllegalArgumentException- if key isnullor empty
-
setBoolean
public void setBoolean(String key, boolean value, boolean flush) throws IOException
Sets the value corresponding to the given key.- Parameters:
key- keyvalue- valueflush- whether to save to persistent storage immediately- Throws:
IOException- if value storing failedIllegalArgumentException- if key isnullor empty
-
getString
public String getString(String key)
Returns a string value that corresponds to the given key.- Parameters:
key- key- Returns:
- corresponding value
- Throws:
IllegalArgumentException- if key isnullor empty; also if value cannot be found for the specified key
-
getString
public String getString(String key, String defaultValue)
Returns a string value that corresponds to the given key. If a value cannot be found then the specified default value is returned.- Parameters:
key- keydefaultValue- default value- Returns:
- string value that corresponds to the given key
- Throws:
IllegalArgumentException- if key isnullor emptyNullPointerException- if defaultValue isnull
-
setString
public void setString(String key, String value) throws IOException
Sets the value corresponding to the given key.- Parameters:
key- keyvalue- value- Throws:
IOException- if value storing failedIllegalArgumentException- if key isnullor empty
-
setString
public void setString(String key, String value, boolean flush) throws IOException
Sets the value corresponding to the given key.- Parameters:
key- keyvalue- valueflush- whether to save to persistent storage immediately- Throws:
IOException- if value storing failedIllegalArgumentException- if key isnullor empty
-
getInteger
public int getInteger(String key, int defaultValue)
Returns an integer value that corresponds to the given key. If a value cannot be found then the specified default value is returned.- Parameters:
key- keydefaultValue- default value- Returns:
- corresponding value
- Throws:
IllegalArgumentException- if key isnullor emptyNumberFormatException- if value cannot be parsed to integer
-
getInteger
public int getInteger(String key)
Returns an integer value that corresponds to the given key.- Parameters:
key- key- Returns:
- corresponding value
- Throws:
IllegalArgumentException- if key isnullor empty; also if value cannot be found for the specified keyNumberFormatException- if value cannot be parsed to integer
-
setInteger
public void setInteger(String key, int value) throws IOException
Sets the value corresponding to the given key.- Parameters:
key- keyvalue- value- Throws:
IOException- if value storing failedIllegalArgumentException- if key isnullor empty
-
setInteger
public void setInteger(String key, int value, boolean flush) throws IOException
Sets the value corresponding to the given key.- Parameters:
key- keyvalue- valueflush- whether to save to persistent storage immediately- Throws:
IOException- if value storing failedIllegalArgumentException- if key isnullor empty
-
getLong
public long getLong(String key, long defaultValue)
Returns a long value that corresponds to the given key. If a value cannot be found then the specified default value is returned.- Parameters:
key- keydefaultValue- default value- Returns:
- corresponding value
- Throws:
IllegalArgumentException- if key isnullor emptyNumberFormatException- if value cannot be parsed to integer
-
getLong
public long getLong(String key)
Returns a long value that corresponds to the given key.- Parameters:
key- key- Returns:
- corresponding value
- Throws:
IllegalArgumentException- if key isnullor empty; also if value cannot be found for the specified keyNumberFormatException- if value cannot be parsed to long
-
setLong
public void setLong(String key, long value) throws IOException
Sets the value corresponding to the given key.- Parameters:
key- keyvalue- value- Throws:
IOException- if value storing failedIllegalArgumentException- if key isnullor empty
-
setLong
public void setLong(String key, long value, boolean flush) throws IOException
Sets the value corresponding to the given key.- Parameters:
key- keyvalue- valueflush- whether to save to persistent storage immediately- Throws:
IOException- if value storing failedIllegalArgumentException- if key isnullor empty
-
isDefined
public boolean isDefined(String key)
Returns true if a corresponding value for the specified key is found, false otherwise.- Parameters:
key- key- Returns:
- whether a corresponding value for the specified key can be found
- Throws:
IllegalArgumentException- if key isnullor empty
-
-