|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.entityfs.util.properties.FileBackedProperties
public class FileBackedProperties
This is an implementation of Properties
that is backed by a file.
Properties written to this object are also written to the file, either
directly when the property is written if autocommit is used, or when
commit()
is called.
The reload()
method can be used to reload properties if the backing
file has been modified.
An instance of this class is not thread safe. If it is to be used concurrently by several threads, the client code must make sure that it is properly protected by locks.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface java.util.Map |
---|
Map.Entry<K,V> |
Field Summary |
---|
Fields inherited from interface org.entityfs.util.properties.Properties |
---|
STRING_ARRAY_DELIMITER, STRING_ARRAY_SPLIT_REGEXP |
Constructor Summary | |
---|---|
FileBackedProperties(ReadWritableFile f)
Create a file-based properties object. |
|
FileBackedProperties(ReadWritableFile f,
boolean autoCommit)
|
Method Summary | |
---|---|
void |
clear()
|
void |
commit()
Commit all modified properties to the backing file. |
boolean |
containsKey(Object key)
|
boolean |
containsValue(Object value)
|
Set<Map.Entry<String,String>> |
entrySet()
|
String |
get(Object key)
|
Properties |
getAsJavaProperties()
Get the contents of this properties object in a Properties object. |
boolean |
getBooleanValue(String key)
Get a boolean property value. |
boolean |
getBooleanValue(String key,
boolean def)
Get a boolean property value. |
double |
getDoubleValue(String key)
Get a double property value. |
double |
getDoubleValue(String key,
double def)
Get a double property value. |
float |
getFloatValue(String key)
Get a float property value. |
float |
getFloatValue(String key,
float def)
Get a float property value. |
int |
getIntValue(String key)
Get an int property value. |
int |
getIntValue(String key,
int def)
Get an int property value. |
long |
getLongValue(String key)
Get a long property value. |
long |
getLongValue(String key,
long def)
Get a long property value. |
Serializable |
getObjectValue(String key)
Get an Object (Serializable ) property value. |
Serializable |
getObjectValue(String key,
Serializable def)
Get an Object (Serializable ) property value. |
PropertiesImpl |
getPropertiesMatching(Glob g)
Get all properties whose names match the supplied glob pattern. |
PropertiesImpl |
getPropertiesMatching(Pattern p)
Get all properties whose names match the supplied regular expression pattern. |
PropertyValue |
getPropertyValue(String key)
Return a property value as a PropertyValue object. |
PropertyValue |
getPropertyValue(String key,
PropertyValue defaultVal)
Get a property value. |
String[] |
getSplitStringArrayValue(String key,
String regexp)
Return a String property value converted to a String array by splitting it with the provided regular expression. |
String[] |
getSplitStringArrayValue(String key,
String regexp,
String[] def)
Return a comma-separated String property value converted to a String array by splitting it with the provided regular expression. |
String[] |
getStringArrayValue(String key)
Return a comma-separated String property value converted to a String array. |
String[] |
getStringArrayValue(String key,
String[] def)
Return a comma-separated String property value converted to a String array. |
String |
getStringValue(String key)
Get a String property value. |
String |
getStringValue(String key,
String def)
Get a String property value. |
boolean |
isEmpty()
|
Set<String> |
keySet()
|
Set<Map.Entry<String,PropertyValue>> |
propertyEntrySet()
Get an entry set. |
Collection<PropertyValue> |
propertyValues()
Get a collection of property values. |
String |
put(String key,
String value)
|
void |
putAll(Map<? extends String,? extends String> m)
|
void |
putAll(Properties p)
Add all properties from the supplied Properties object. |
String |
putBooleanValue(String key,
boolean value)
Set a property with a boolean value. |
String |
putDoubleValue(String key,
double value)
Set a property with a double value. |
String |
putFloatValue(String key,
float value)
Set a property with a float value. |
String |
putIntValue(String key,
int value)
Set a property with an int value. |
String |
putLongValue(String key,
long value)
Set a property with a long value. |
String |
putObjectValue(String key,
Serializable value)
Set a property with an Object (Serializable ) value. |
String |
putPropertyValue(String key,
PropertyValue defaultVal)
Set a property value. |
String |
putStringArrayValue(String key,
String[] value)
Set a property with a String array value. |
String |
putStringArrayValue(String key,
String[] value,
String delimiter)
Set a property with a String array value. |
String |
putStringValue(String key,
String value)
Set a property with a String value. |
void |
reload()
Reload properties from the backing file. |
String |
remove(Object key)
|
int |
size()
|
Collection<String> |
values()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
equals, hashCode |
Constructor Detail |
---|
public FileBackedProperties(ReadWritableFile f)
f
- The property file.public FileBackedProperties(ReadWritableFile f, boolean autoCommit)
Method Detail |
---|
public long getLongValue(String key) throws NoSuchPropertyException, NumberFormatException
Properties
long
property value.
getLongValue
in interface Properties
key
- The property key.
long
value of the property.
NoSuchPropertyException
- If the property is missing.
NumberFormatException
- If the property value cannot be converted
to a long
.public long getLongValue(String key, long def) throws NumberFormatException
Properties
long
property value. If the property is missing, return a
default value.
getLongValue
in interface Properties
key
- The property key.def
- The default value to return if the property is missing.
long
value of the property or the default value if
the property is missing.
NumberFormatException
- If the property value cannot be converted
to a long
.public String putLongValue(String key, long value)
Properties
long
value.
putLongValue
in interface Properties
key
- The property key.value
- The property value.
null
if it was not set
before.public int getIntValue(String key) throws NoSuchPropertyException, NumberFormatException
Properties
int
property value.
getIntValue
in interface Properties
key
- The property key.
int
value of the property.
NoSuchPropertyException
- If the property is missing.
NumberFormatException
- If the property value cannot be converted
to an int
.public int getIntValue(String key, int def) throws NumberFormatException
Properties
int
property value. If the property is missing, return a
default value.
getIntValue
in interface Properties
key
- The property key.def
- The default value to return if the property is missing.
int
value of the property or the default value if the
property is missing.
NumberFormatException
- If the property value cannot be converted
to an int
.public String putIntValue(String key, int value)
Properties
int
value.
putIntValue
in interface Properties
key
- The property key.value
- The property value.
null
if it was not set
before.public float getFloatValue(String key) throws NoSuchPropertyException, NumberFormatException
Properties
float
property value.
getFloatValue
in interface Properties
key
- The property key.
float
value of the property.
NoSuchPropertyException
- If the property is missing.
NumberFormatException
- If the property value cannot be converted
to a float
.public float getFloatValue(String key, float def) throws NumberFormatException
Properties
float
property value. If the property is missing, return a
default value.
getFloatValue
in interface Properties
key
- The property key.def
- The default value to return if the property is missing.
float
value of the property or the default value if
the property is missing.
NumberFormatException
- If the property value cannot be converted
to float
.public String putFloatValue(String key, float value)
Properties
float
value.
putFloatValue
in interface Properties
key
- The property key.value
- The property value.
null
if it was not set
before.public double getDoubleValue(String key) throws NoSuchPropertyException, NumberFormatException
Properties
double
property value.
getDoubleValue
in interface Properties
key
- The property key.
double
value of the property.
NoSuchPropertyException
- If the property is missing.
NumberFormatException
- If the property value cannot be converted
to a double
.public double getDoubleValue(String key, double def) throws NumberFormatException
Properties
double
property value. If the property is missing, return a
default value.
getDoubleValue
in interface Properties
key
- The property key.def
- The default value to return if the property is missing.
double
value of the property or the default value if
the property is missing.
NumberFormatException
- If the property value cannot be converted
to double
.public String putDoubleValue(String key, double value)
Properties
double
value.
putDoubleValue
in interface Properties
key
- The property key.value
- The property value.
null
if it was not set
before.public boolean getBooleanValue(String key) throws NoSuchPropertyException
Properties
boolean
property value.
getBooleanValue
in interface Properties
key
- The property key.
boolean
value of the property.
NoSuchPropertyException
- If the property is missing.public boolean getBooleanValue(String key, boolean def)
Properties
boolean
property value. If the property is missing, return
a default value.
getBooleanValue
in interface Properties
key
- The property key.def
- The default value to return if the property is missing.
boolean
value of the property or the default value if
the property is missing.public String putBooleanValue(String key, boolean value)
Properties
boolean
value.
putBooleanValue
in interface Properties
key
- The property key.value
- The property value.
null
if it was not set
before.public PropertyValue getPropertyValue(String key) throws NoSuchPropertyException
Properties
PropertyValue
object.
getPropertyValue
in interface Properties
key
- The property key.
NoSuchPropertyException
- If the property is missing.Properties.getPropertyValue(String, PropertyValue)
public PropertyValue getPropertyValue(String key, PropertyValue defaultVal)
Properties
getPropertyValue
in interface Properties
key
- The property key.defaultVal
- The default value to return if the property is not set.
This may be null
.
Properties.getPropertyValue(String)
public String putPropertyValue(String key, PropertyValue defaultVal)
Properties
putPropertyValue
in interface Properties
key
- The property name.defaultVal
- The property value.
null
if it was
not set.public Serializable getObjectValue(String key) throws NoSuchPropertyException, WrappedIOException
Properties
Object
(Serializable
) property value.
getObjectValue
in interface Properties
key
- The property key.
Object
value of the property.
NoSuchPropertyException
- If the property is missing.
WrappedIOException
- On errors when deserializing the property
value.public Serializable getObjectValue(String key, Serializable def) throws WrappedIOException
Properties
Object
(Serializable
) property value. If the
property is missing, return a default value.
getObjectValue
in interface Properties
key
- The property key.def
- The default value to return if the property is missing. The
value may be null
.
boolean
value of the property or the default value if
the property is missing.
WrappedIOException
- On errors when deserializing the property
value.public String putObjectValue(String key, Serializable value)
Properties
Object
(Serializable
) value.
putObjectValue
in interface Properties
key
- The property key.value
- The property value.
null
if it was not set
before.public String getStringValue(String key) throws NoSuchPropertyException
Properties
String
property value.
getStringValue
in interface Properties
key
- The property key.
String
value of the property.
NoSuchPropertyException
- If the property is missing.public String getStringValue(String key, String def)
Properties
String
property value. If the property is missing, return a
default value.
getStringValue
in interface Properties
key
- The property key.def
- The default value to return if the property is missing. The
value may be null
.
String
value of the property or the default value if
the property is missing.public String putStringValue(String key, String value)
Properties
String
value.
putStringValue
in interface Properties
key
- The property key.value
- The property value.
null
if it was not set
before.public String[] getStringArrayValue(String key) throws NoSuchPropertyException
Properties
If the property value is empty, an array of length 0
is returned.
getStringArrayValue
in interface Properties
key
- The property key.
NoSuchPropertyException
- If the property is missingpublic String[] getStringArrayValue(String key, String[] def)
Properties
If the property value is empty, an array of length 0
is returned.
getStringArrayValue
in interface Properties
key
- The property key.def
- The default value to return if the property is missing. The
value may be null
.
public String[] getSplitStringArrayValue(String key, String regexp) throws NoSuchPropertyException
Properties
If the property value is empty, an array of length 0
is returned.
getSplitStringArrayValue
in interface Properties
key
- The property key.regexp
- The regular expression.
NoSuchPropertyException
- If the property is missing.public String[] getSplitStringArrayValue(String key, String regexp, String[] def)
Properties
If the property value is empty, an array of length 0
is returned.
getSplitStringArrayValue
in interface Properties
key
- The property key.def
- The default value to return if the property is missing. The
value may be null
.
public String putStringArrayValue(String key, String[] value)
Properties
String
array value. Use the default
delimiter (",") to separate the values.
putStringArrayValue
in interface Properties
key
- The property key.value
- The property value.
null
if it was not set
before.public String putStringArrayValue(String key, String[] value, String delimiter)
Properties
String
array value. Use the provided
delimiter to separate the values.
putStringArrayValue
in interface Properties
key
- The property key.value
- The property value.
null
if it was not set
before.public Properties getAsJavaProperties()
Properties
Properties
object.
getAsJavaProperties
in interface Properties
Properties
object with the same contents as
this object.public void putAll(Properties p)
Properties
Properties
object.
Existing properties that have the same name as properties in the supplied
object will be overwritten.
Note that, since this interface extends Map
, calling putAll
with a Properties
object of this type will also work.
putAll
in interface Properties
p
- A Properties
object.public void clear()
clear
in interface Map<String,String>
public boolean containsKey(Object key)
containsKey
in interface Map<String,String>
public boolean containsValue(Object value)
containsValue
in interface Map<String,String>
public Set<Map.Entry<String,String>> entrySet()
entrySet
in interface Map<String,String>
public String get(Object key)
get
in interface Map<String,String>
public boolean isEmpty()
isEmpty
in interface Map<String,String>
public Set<String> keySet()
keySet
in interface Map<String,String>
public String put(String key, String value)
put
in interface Map<String,String>
public void putAll(Map<? extends String,? extends String> m)
putAll
in interface Map<String,String>
public String remove(Object key)
remove
in interface Map<String,String>
public int size()
size
in interface Map<String,String>
public Collection<String> values()
values
in interface Map<String,String>
public PropertiesImpl getPropertiesMatching(Pattern p)
Properties
object is not file-backed.
getPropertiesMatching
in interface Properties
p
- The regular expression pattern to match property names against.
Properties
object containing the properties from this
object whose names match the regular expression pattern. If no property
names matched the pattern, this object is empty.Properties.getPropertiesMatching(Glob)
public PropertiesImpl getPropertiesMatching(Glob g)
Properties
object is not file-backed.
getPropertiesMatching
in interface Properties
g
- The glob pattern to match property names against.
Properties
object containing the properties from this
object whose names match the glob pattern. If no property names matched
the pattern, this object is empty.Properties.getPropertiesMatching(Pattern)
public Set<Map.Entry<String,PropertyValue>> propertyEntrySet()
Properties
Map.entrySet()
to
get PropertyValue
values in the entry set.
The returned set is read only.
propertyEntrySet
in interface Properties
public Collection<PropertyValue> propertyValues()
Properties
Map.values()
to get PropertyValue
objects instead of
strings.
The returned collection is read only.
propertyValues
in interface Properties
public void commit()
public void reload()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |