|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Properties
This interface gives an alternative to the good, old java.util.Properties
class. It defines methods for accessing properties of
different types (such as integers and floats). The interface extends Map<String, String>
, so all map operations are also available.
Get methods throw NoSuchPropertyException
if the property is missing
instead of returning null
.
A PropertyValue
object may be used to encapsulate a property value.
It contains several methods for interpreting the property value as different
data types. The Properties
interface would have been nicer to work
with if it extended Map<String, PropertyValue>
, but that would break
backwards compatibility. The propertyValues()
and
propertyEntrySet()
methods works as the values
and entrySet
methods if this has been a Map<String, PropertyValue>
.
null
property values are not permitted.
How values are converted to their data types is up to the implementations of this interface.
PropertyValue
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface java.util.Map |
---|
Map.Entry<K,V> |
Field Summary | |
---|---|
static String |
STRING_ARRAY_DELIMITER
|
static String |
STRING_ARRAY_SPLIT_REGEXP
|
Method Summary | |
---|---|
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. |
Properties |
getPropertiesMatching(Glob g)
Get a new Properties object that contains all properties from
this object whose names match the supplied glob pattern. |
Properties |
getPropertiesMatching(Pattern p)
Get a new Properties object that contains all properties from
this object 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. |
Set<Map.Entry<String,PropertyValue>> |
propertyEntrySet()
Get an entry set. |
Collection<PropertyValue> |
propertyValues()
Get a collection of property values. |
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 value)
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. |
Methods inherited from interface java.util.Map |
---|
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values |
Field Detail |
---|
static final String STRING_ARRAY_SPLIT_REGEXP
static final String STRING_ARRAY_DELIMITER
Method Detail |
---|
long getLongValue(String key) throws NoSuchPropertyException, NumberFormatException
long
property value.
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
.long getLongValue(String key, long def) throws NumberFormatException
long
property value. If the property is missing, return a
default value.
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
.String putLongValue(String key, long value)
long
value.
key
- The property key.value
- The property value.
null
if it was not set
before.int getIntValue(String key) throws NoSuchPropertyException, NumberFormatException
int
property value.
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
.int getIntValue(String key, int def) throws NumberFormatException
int
property value. If the property is missing, return a
default value.
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
.String putIntValue(String key, int value)
int
value.
key
- The property key.value
- The property value.
null
if it was not set
before.float getFloatValue(String key) throws NoSuchPropertyException, NumberFormatException
float
property value.
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
.float getFloatValue(String key, float def) throws NumberFormatException
float
property value. If the property is missing, return a
default value.
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
.String putFloatValue(String key, float value)
float
value.
key
- The property key.value
- The property value.
null
if it was not set
before.double getDoubleValue(String key) throws NoSuchPropertyException, NumberFormatException
double
property value.
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
.double getDoubleValue(String key, double def) throws NumberFormatException
double
property value. If the property is missing, return a
default value.
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
.String putDoubleValue(String key, double value)
double
value.
key
- The property key.value
- The property value.
null
if it was not set
before.boolean getBooleanValue(String key) throws NoSuchPropertyException
boolean
property value.
key
- The property key.
boolean
value of the property.
NoSuchPropertyException
- If the property is missing.boolean getBooleanValue(String key, boolean def)
boolean
property value. If the property is missing, return
a default value.
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.String putBooleanValue(String key, boolean value)
boolean
value.
key
- The property key.value
- The property value.
null
if it was not set
before.Serializable getObjectValue(String key) throws NoSuchPropertyException, WrappedIOException
Object
(Serializable
) property value.
key
- The property key.
Object
value of the property.
NoSuchPropertyException
- If the property is missing.
WrappedIOException
- On errors when deserializing the property
value.Serializable getObjectValue(String key, Serializable def) throws WrappedIOException
Object
(Serializable
) property value. If the
property is missing, return a default value.
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.String putObjectValue(String key, Serializable value) throws NullPointerException, WrappedIOException
Object
(Serializable
) value.
key
- The property key.value
- The property value.
null
if it was not set
before.
NullPointerException
- If value
is null
.
WrappedIOException
- If there is an error serializing value
.String getStringValue(String key) throws NoSuchPropertyException
String
property value.
key
- The property key.
String
value of the property.
NoSuchPropertyException
- If the property is missing.String getStringValue(String key, String def)
String
property value. If the property is missing, return a
default value.
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.String putStringValue(String key, String value) throws NullPointerException
String
value.
key
- The property key.value
- The property value.
null
if it was not set
before.
NullPointerException
- If the key or the value is null
.String[] getStringArrayValue(String key) throws NoSuchPropertyException
If the property value is empty, an array of length 0
is returned.
key
- The property key.
NoSuchPropertyException
- If the property is missingString[] getStringArrayValue(String key, String[] def)
If the property value is empty, an array of length 0
is returned.
key
- The property key.def
- The default value to return if the property is missing. The
value may be null
.
String[] getSplitStringArrayValue(String key, String regexp) throws NoSuchPropertyException
If the property value is empty, an array of length 0
is returned.
key
- The property key.regexp
- The regular expression.
NoSuchPropertyException
- If the property is missing.String[] getSplitStringArrayValue(String key, String regexp, String[] def)
If the property value is empty, an array of length 0
is returned.
key
- The property key.def
- The default value to return if the property is missing. The
value may be null
.
String putStringArrayValue(String key, String[] value) throws NullPointerException
String
array value. Use the default
delimiter (",") to separate the values.
key
- The property key.value
- The property value.
null
if it was not set
before.
NullPointerException
- If the key or the value is null.String putStringArrayValue(String key, String[] value, String delimiter) throws NullPointerException
String
array value. Use the provided
delimiter to separate the values.
key
- The property key.value
- The property value.
null
if it was not set
before.
NullPointerException
- If the key or the value is null.Properties getAsJavaProperties()
Properties
object.
Properties
object with the same contents as
this object.void putAll(Properties p) throws NullPointerException
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.
p
- A Properties
object.
NullPointerException
- If p
is null or if it contains any
null
value.PropertyValue getPropertyValue(String key) throws NoSuchPropertyException
PropertyValue
object.
key
- The property key.
NoSuchPropertyException
- If the property is missing.getPropertyValue(String, PropertyValue)
PropertyValue getPropertyValue(String key, PropertyValue defaultVal)
key
- The property key.defaultVal
- The default value to return if the property is not set.
This may be null
.
getPropertyValue(String)
String putPropertyValue(String key, PropertyValue value)
key
- The property name.value
- The property value.
null
if it was
not set.Properties getPropertiesMatching(Pattern p)
Properties
object that contains all properties from
this object whose names match the supplied regular expression
Pattern
.
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.getPropertiesMatching(Glob)
Properties getPropertiesMatching(Glob g)
Properties
object that contains all properties from
this object whose names match the supplied glob pattern.
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.getPropertiesMatching(Pattern)
Collection<PropertyValue> propertyValues()
Map.values()
to get PropertyValue
objects instead of
strings.
The returned collection is read only.
Set<Map.Entry<String,PropertyValue>> propertyEntrySet()
Map.entrySet()
to
get PropertyValue
values in the entry set.
The returned set is read only.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |