public final class Properties extends Properties
Properties extends
java.util.Properties to include:
net.sf.eBus.util.Properties object.
Properties object
into a named file.
PropertiesListeners when the
underlying properties file has changed and been
automatically reloaded.
Note: automatic properties file reloading is done only if there is a registered properties listener. If there are no registered listeners, then Properties does not watch the underlying file for changes and so does not automatically reload the properties file if it should change.
defaults| Constructor and Description |
|---|
Properties()
Creates an empty property list with no default values.
|
Properties(Properties defaults)
Creates an empty property list with default values.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(PropertiesListener listener)
Adds a properties listener.
|
boolean |
equals(Object o) |
String[] |
getArrayProperty(String key,
char ifs)
Returns the named property value as a
String[]. |
boolean |
getBooleanProperty(String key)
Returns the named property value as a
boolean. |
boolean |
getBooleanProperty(String key,
boolean defaultValue)
Returns the named property value as a
boolean. |
double |
getDoubleProperty(String key)
Returns the named property value as a
double. |
double |
getDoubleProperty(String key,
double defaultValue)
Returns the named property value as a
double. |
int |
getIntProperty(String key)
Returns the named property value as an
int. |
int |
getIntProperty(String key,
int defaultValue)
Returns the named property value as an
int. |
int |
hashCode() |
void |
load()
Reloads properties from the properties file.
|
static Properties |
loadProperties(File file)
Returns a properties list loaded with the values found
in the properties file.
|
static Properties |
loadProperties(String fileName)
Returns a properties list loaded with the values found
in the named properties file.
|
void |
removeListener(PropertiesListener listener)
Removes a properties listener.
|
void |
setArrayProperty(String key,
String[] value,
char ifs)
Sets the named property value to the string array.
|
void |
setBooleanProperty(String key,
boolean value)
Sets the named property value to the specified boolean.
|
void |
setDoubleProperty(String key,
double value)
Sets the named property value to the specified double.
|
void |
setIntProperty(String key,
int value)
Sets the named property value to the specified integer.
|
void |
store(File file,
String header)
Stores properties in the named properties file using the
provided header comment.
|
void |
store(String header)
Stores properties in properties file using the provided
header comment.
|
void |
store(String fileName,
String header)
Stores properties in the named properties file using the
provided header comment.
|
Set<String> |
stringPropertyNames(Pattern p)
Returns a set of keys in this property list whose key
matches the given regular expression pattern
p
and the corresponding values are strings. |
getProperty, getProperty, list, list, load, load, loadFromXML, propertyNames, save, setProperty, store, store, storeToXML, storeToXML, stringPropertyNamesclear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, forEach, get, getOrDefault, isEmpty, keys, keySet, merge, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, size, toString, valuespublic Properties()
public Properties(Properties defaults)
defaults - the default property values.public boolean equals(Object o)
public int hashCode()
public boolean getBooleanProperty(String key)
boolean. If key is an unknown
property or is neither "true" nor
"false" then returns false.key - The property key.boolean. If the value is "true",
then true is returned, otherwise returns
false.getBooleanProperty(String, boolean),
setBooleanProperty(String, boolean)public int getIntProperty(String key)
int.
If key is an unknown property or is not a
valid integer, then returns 0.key - The property key.int.getIntProperty(String, int),
setIntProperty(String, int)public double getDoubleProperty(String key)
double.
If key is an unknown property or is not a
value double, then returns 0.0.key - The property key.double.NumberFormatException - if the property value is not a valid double.getDoubleProperty(String, double),
setDoubleProperty(String, double)public String[] getArrayProperty(String key, char ifs)
String[]. ifs is used as
the interfield separator character.
If the property value does not exist, then returns
an empty array.key - The property key.ifs - The interfield separator.String[]. If the property value does not
exist, then returns an empty array.setArrayProperty(String, String[], char)public boolean getBooleanProperty(String key, boolean defaultValue)
boolean. If key is an unknown
property or an invalid boolean string, then returns the
default value.key - The property key.defaultValue - The default value.boolean. If key is an unknown
property or an invalid boolean string, then returns
defaultValue.getBooleanProperty(String),
setBooleanProperty(String, boolean)public int getIntProperty(String key, int defaultValue)
int.
If either the property does not exist or does exist but
is not an integer, then returns the default value.key - The property key.defaultValue - The default value.int
or defaultValue.getIntProperty(String),
setIntProperty(String, int)public double getDoubleProperty(String key, double defaultValue)
double.
If the property value does not exist or is not a valid
double, then returns the default value.key - The property key.defaultValue - The default value.double.
If the property value does not exist or is not a valid
double, then returns
defaultValue.getDoubleProperty(String),
setDoubleProperty(String, double)public Set<String> stringPropertyNames(Pattern p)
p
and the corresponding values are strings.
Includes distinct keys in the default property list if a
key of the same name is not in the main properties list.
Properties whose key or value is not of type
String are omitted.
The returned set is not backed by the Properties
object. Changes to this Properties are not
reflected in the set or vice versa.
p - match property keys against this pattern.Properties.stringPropertyNames(),
Properties.defaultspublic void setBooleanProperty(String key, boolean value)
key - The property key.value - The boolean value.getBooleanProperty(String),
getBooleanProperty(String, boolean)public void setIntProperty(String key, int value)
key - The property key.value - The integer value.getIntProperty(String),
getIntProperty(String, int)public void setDoubleProperty(String key, double value)
key - The property key.value - The double value.getDoubleProperty(String),
getDoubleProperty(String, double)public void setArrayProperty(String key, String[] value, char ifs)
ifs.key - The property key.value - The string array.ifs - The interfield separator.getArrayProperty(java.lang.String, char)public void load()
throws IOException
IOException - if there are errors reading in the properties file.store(String),
loadProperties(String),
loadProperties(File)public void store(String header) throws FileNotFoundException, IOException
header - File header comment. May be
null.FileNotFoundException - if the properties file could not be created.IOException - if there is an error storing the properties into the
file.load(),
loadProperties(String),
loadProperties(File)public void store(String fileName, String header) throws IllegalArgumentException, FileNotFoundException, IOException
fileName - Property file's name.header - File header comment. May be
null.IllegalArgumentException - if fileName is either null or an empty
string.FileNotFoundException - if the properties file could not be created.IOException - if there is an error storing the properties into the
file.store(String),
store(File, String),
load(),
loadProperties(String),
loadProperties(File)public void store(File file, String header) throws IllegalArgumentException, FileNotFoundException, IOException
file - Property file.header - File header comment. May be
null.IllegalArgumentException - if file is null.FileNotFoundException - if the properties file could not be created.IOException - if there is an error storing the properties into the
file.store(String),
store(String, String),
load(),
loadProperties(String),
loadProperties(File)public void addListener(PropertiesListener listener) throws IllegalArgumentException, IllegalStateException
Note: when the underlying properties file changes, it will
be automatically reloaded prior to calling back to the
registered PropertiesListeners.
listener - Add this properties listener.IllegalArgumentException - if listener is null.IllegalStateException - if this is no underlying property file.public void removeListener(PropertiesListener listener)
Note: when the watch timer is canceled, Properties will no longer determine if the underlying properties file has changed and so will not automatically reload said file if it should change.
listener - Remove this listener.IllegalStateException - if this is no underlying property file.public static Properties loadProperties(String fileName) throws IllegalArgumentException, IOException
fileName - the properties file name.IllegalArgumentException - if fileName is either null or an empty
string.IOException - if fileName is not a valid properties
file.loadProperties(File),
load(),
store(String)public static Properties loadProperties(File file) throws IllegalArgumentException, IOException
file - the properties file object.IllegalArgumentException - if file is null.IOException - if file is not a valid properties file.loadProperties(String),
load(),
store(String)Copyright © 2019. All rights reserved.