org.entityfs.util.properties
Interface Properties

All Superinterfaces:
Map<String,String>
All Known Subinterfaces:
StorableProperties
All Known Implementing Classes:
FileBackedProperties, PropertiesImpl

public interface Properties
extends Map<String,String>

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.

Since:
1.0
Author:
Karl Gustafsson
See Also:
PropertyValue
In_jar:
entityfs-util

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

STRING_ARRAY_SPLIT_REGEXP

static final String STRING_ARRAY_SPLIT_REGEXP
See Also:
Constant Field Values

STRING_ARRAY_DELIMITER

static final String STRING_ARRAY_DELIMITER
See Also:
Constant Field Values
Method Detail

getLongValue

long getLongValue(String key)
                  throws NoSuchPropertyException,
                         NumberFormatException
Get a long property value.

Parameters:
key - The property key.
Returns:
The long value of the property.
Throws:
NoSuchPropertyException - If the property is missing.
NumberFormatException - If the property value cannot be converted to a long.

getLongValue

long getLongValue(String key,
                  long def)
                  throws NumberFormatException
Get a long property value. If the property is missing, return a default value.

Parameters:
key - The property key.
def - The default value to return if the property is missing.
Returns:
The long value of the property or the default value if the property is missing.
Throws:
NumberFormatException - If the property value cannot be converted to a long.

putLongValue

String putLongValue(String key,
                    long value)
Set a property with a long value.

Parameters:
key - The property key.
value - The property value.
Returns:
The property's old value, or null if it was not set before.

getIntValue

int getIntValue(String key)
                throws NoSuchPropertyException,
                       NumberFormatException
Get an int property value.

Parameters:
key - The property key.
Returns:
The int value of the property.
Throws:
NoSuchPropertyException - If the property is missing.
NumberFormatException - If the property value cannot be converted to an int.

getIntValue

int getIntValue(String key,
                int def)
                throws NumberFormatException
Get an int property value. If the property is missing, return a default value.

Parameters:
key - The property key.
def - The default value to return if the property is missing.
Returns:
The int value of the property or the default value if the property is missing.
Throws:
NumberFormatException - If the property value cannot be converted to an int.

putIntValue

String putIntValue(String key,
                   int value)
Set a property with an int value.

Parameters:
key - The property key.
value - The property value.
Returns:
The property's old value, or null if it was not set before.

getFloatValue

float getFloatValue(String key)
                    throws NoSuchPropertyException,
                           NumberFormatException
Get a float property value.

Parameters:
key - The property key.
Returns:
The float value of the property.
Throws:
NoSuchPropertyException - If the property is missing.
NumberFormatException - If the property value cannot be converted to a float.

getFloatValue

float getFloatValue(String key,
                    float def)
                    throws NumberFormatException
Get a float property value. If the property is missing, return a default value.

Parameters:
key - The property key.
def - The default value to return if the property is missing.
Returns:
The float value of the property or the default value if the property is missing.
Throws:
NumberFormatException - If the property value cannot be converted to float.

putFloatValue

String putFloatValue(String key,
                     float value)
Set a property with a float value.

Parameters:
key - The property key.
value - The property value.
Returns:
The property's old value, or null if it was not set before.

getDoubleValue

double getDoubleValue(String key)
                      throws NoSuchPropertyException,
                             NumberFormatException
Get a double property value.

Parameters:
key - The property key.
Returns:
The double value of the property.
Throws:
NoSuchPropertyException - If the property is missing.
NumberFormatException - If the property value cannot be converted to a double.

getDoubleValue

double getDoubleValue(String key,
                      double def)
                      throws NumberFormatException
Get a double property value. If the property is missing, return a default value.

Parameters:
key - The property key.
def - The default value to return if the property is missing.
Returns:
The double value of the property or the default value if the property is missing.
Throws:
NumberFormatException - If the property value cannot be converted to double.

putDoubleValue

String putDoubleValue(String key,
                      double value)
Set a property with a double value.

Parameters:
key - The property key.
value - The property value.
Returns:
The property's old value, or null if it was not set before.

getBooleanValue

boolean getBooleanValue(String key)
                        throws NoSuchPropertyException
Get a boolean property value.

Parameters:
key - The property key.
Returns:
The boolean value of the property.
Throws:
NoSuchPropertyException - If the property is missing.

getBooleanValue

boolean getBooleanValue(String key,
                        boolean def)
Get a boolean property value. If the property is missing, return a default value.

Parameters:
key - The property key.
def - The default value to return if the property is missing.
Returns:
The boolean value of the property or the default value if the property is missing.

putBooleanValue

String putBooleanValue(String key,
                       boolean value)
Set a property with a boolean value.

Parameters:
key - The property key.
value - The property value.
Returns:
The property's old value, or null if it was not set before.

getObjectValue

Serializable getObjectValue(String key)
                            throws NoSuchPropertyException,
                                   WrappedIOException
Get an Object (Serializable) property value.

Parameters:
key - The property key.
Returns:
The Object value of the property.
Throws:
NoSuchPropertyException - If the property is missing.
WrappedIOException - On errors when deserializing the property value.

getObjectValue

Serializable getObjectValue(String key,
                            Serializable def)
                            throws WrappedIOException
Get an Object (Serializable) property value. If the property is missing, return a default value.

Parameters:
key - The property key.
def - The default value to return if the property is missing. The value may be null.
Returns:
The boolean value of the property or the default value if the property is missing.
Throws:
WrappedIOException - On errors when deserializing the property value.

putObjectValue

String putObjectValue(String key,
                      Serializable value)
                      throws NullPointerException,
                             WrappedIOException
Set a property with an Object (Serializable) value.

Parameters:
key - The property key.
value - The property value.
Returns:
The property's old value, or null if it was not set before.
Throws:
NullPointerException - If value is null.
WrappedIOException - If there is an error serializing value .

getStringValue

String getStringValue(String key)
                      throws NoSuchPropertyException
Get a String property value.

Parameters:
key - The property key.
Returns:
The String value of the property.
Throws:
NoSuchPropertyException - If the property is missing.

getStringValue

String getStringValue(String key,
                      String def)
Get a String property value. If the property is missing, return a default value.

Parameters:
key - The property key.
def - The default value to return if the property is missing. The value may be null.
Returns:
The String value of the property or the default value if the property is missing.

putStringValue

String putStringValue(String key,
                      String value)
                      throws NullPointerException
Set a property with a String value.

Parameters:
key - The property key.
value - The property value.
Returns:
The property's old value, or null if it was not set before.
Throws:
NullPointerException - If the key or the value is null.

getStringArrayValue

String[] getStringArrayValue(String key)
                             throws NoSuchPropertyException
Return a comma-separated String property value converted to a String array.

If the property value is empty, an array of length 0 is returned.

Parameters:
key - The property key.
Returns:
The property value, split around the regexp "\\s*,\\s*".
Throws:
NoSuchPropertyException - If the property is missing

getStringArrayValue

String[] getStringArrayValue(String key,
                             String[] def)
Return a comma-separated String property value converted to a String array. If the property is missing, return a default value.

If the property value is empty, an array of length 0 is returned.

Parameters:
key - The property key.
def - The default value to return if the property is missing. The value may be null.
Returns:
The property value, split around the regexp "\\s*,\\s*" or the default value if the property is missing.

getSplitStringArrayValue

String[] getSplitStringArrayValue(String key,
                                  String regexp)
                                  throws NoSuchPropertyException
Return a String property value converted to a String array by splitting it with the provided regular expression.

If the property value is empty, an array of length 0 is returned.

Parameters:
key - The property key.
regexp - The regular expression.
Returns:
The property value.
Throws:
NoSuchPropertyException - If the property is missing.

getSplitStringArrayValue

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. If the property is missing, return a default value.

If the property value is empty, an array of length 0 is returned.

Parameters:
key - The property key.
def - The default value to return if the property is missing. The value may be null.
Returns:
The property value or the default value if the property is missing.

putStringArrayValue

String putStringArrayValue(String key,
                           String[] value)
                           throws NullPointerException
Set a property with a String array value. Use the default delimiter (",") to separate the values.

Parameters:
key - The property key.
value - The property value.
Returns:
The property's old value, or null if it was not set before.
Throws:
NullPointerException - If the key or the value is null.

putStringArrayValue

String putStringArrayValue(String key,
                           String[] value,
                           String delimiter)
                           throws NullPointerException
Set a property with a String array value. Use the provided delimiter to separate the values.

Parameters:
key - The property key.
value - The property value.
Returns:
The property's old value, or null if it was not set before.
Throws:
NullPointerException - If the key or the value is null.

getAsJavaProperties

Properties getAsJavaProperties()
Get the contents of this properties object in a Properties object.

Returns:
A Properties object with the same contents as this object.

putAll

void putAll(Properties p)
            throws NullPointerException
Add all properties from the supplied 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.

Parameters:
p - A Properties object.
Throws:
NullPointerException - If p is null or if it contains any null value.

getPropertyValue

PropertyValue getPropertyValue(String key)
                               throws NoSuchPropertyException
Return a property value as a PropertyValue object.

Parameters:
key - The property key.
Returns:
The property value.
Throws:
NoSuchPropertyException - If the property is missing.
Since:
1.1
See Also:
getPropertyValue(String, PropertyValue)

getPropertyValue

PropertyValue getPropertyValue(String key,
                               PropertyValue defaultVal)
Get a property value. If the property is not set, return a default value.

Parameters:
key - The property key.
defaultVal - The default value to return if the property is not set. This may be null.
Returns:
The property value, or a default value if the property is not set.
Since:
1.1
See Also:
getPropertyValue(String)

putPropertyValue

String putPropertyValue(String key,
                        PropertyValue value)
Set a property value.

Parameters:
key - The property name.
value - The property value.
Returns:
The previous value for the property, or null if it was not set.

getPropertiesMatching

Properties getPropertiesMatching(Pattern p)
Get a new Properties object that contains all properties from this object whose names match the supplied regular expression Pattern.

Parameters:
p - The regular expression pattern to match property names against.
Returns:
A 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.
Since:
1.1
See Also:
getPropertiesMatching(Glob)

getPropertiesMatching

Properties getPropertiesMatching(Glob g)
Get a new Properties object that contains all properties from this object whose names match the supplied glob pattern.

Parameters:
g - The glob pattern to match property names against.
Returns:
A 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.
Since:
1.1
See Also:
getPropertiesMatching(Pattern)

propertyValues

Collection<PropertyValue> propertyValues()
Get a collection of property values. This can be used instead of Map.values() to get PropertyValue objects instead of strings.

The returned collection is read only.

Returns:
A collection of property values.

propertyEntrySet

Set<Map.Entry<String,PropertyValue>> propertyEntrySet()
Get an entry set. This can be used instead of Map.entrySet() to get PropertyValue values in the entry set.

The returned set is read only.

Returns:
The entry set.