org.entityfs.util.properties
Class PropertiesImpl

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<String,String>
          extended by org.entityfs.util.properties.PropertiesImpl
All Implemented Interfaces:
Serializable, Cloneable, Map<String,String>, Properties

public class PropertiesImpl
extends HashMap<String,String>
implements Properties

This is an HashMap-based implementation of Properties.

Property values are converted to different data types according to the following rules:

int:
to: Integer.parseInt(val), from: Integer.toString(val).
long:
to: Long.parseLong(val), from: Long.toString(val).
double:
to: Double.parseDouble(val), from: Double.toString(val).
float:
to: Float.parseFloat(val), from: Float.toString(val).
boolean:
to: "true".equalsIgnoreCase(val), from: (val ? "true" : "false").
Object:
to: Base64 decode and deserialize, from: Serialize and Base64 encode.

Since:
1.0
Author:
Karl Gustafsson
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
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
PropertiesImpl()
          Create a new HashMap-backed Properties implementation.
PropertiesImpl(int initialCapacity)
          Create a new HashMap-backed Properties implementation with the given initial capacity.
PropertiesImpl(int initialCapacity, float loadFactor)
          Create a new HashMap-backed Properties implementation with the given initial capacity and load factory.
PropertiesImpl(Map<String,String> m)
          Create a new HashMap-backed Properties implementation and copy the contents from the provided map.
PropertiesImpl(Properties props)
          Create a new HashMap-backed Properties implementation and copy the contents from the provided java.util.Properties object.
 
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.
 PropertiesImpl getPropertiesMatching(Glob g)
          Get a new Properties object that contains all properties from this object whose names match the supplied glob pattern.
 PropertiesImpl 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 class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Constructor Detail

PropertiesImpl

public PropertiesImpl()
Create a new HashMap-backed Properties implementation.


PropertiesImpl

public PropertiesImpl(int initialCapacity)
Create a new HashMap-backed Properties implementation with the given initial capacity.

Parameters:
initialCapacity - The initial capacity (see Map).

PropertiesImpl

public PropertiesImpl(int initialCapacity,
                      float loadFactor)
Create a new HashMap-backed Properties implementation with the given initial capacity and load factory.

Parameters:
initialCapacity - The initial capacity (see Map).
loadFactor - The load factory (see Map).

PropertiesImpl

public PropertiesImpl(Map<String,String> m)
Create a new HashMap-backed Properties implementation and copy the contents from the provided map.

Parameters:
m - The initial contents.

PropertiesImpl

public PropertiesImpl(Properties props)
Create a new HashMap-backed Properties implementation and copy the contents from the provided java.util.Properties object.

Parameters:
props - The initial contents.
Method Detail

getStringValue

public String getStringValue(String key)
Description copied from interface: Properties
Get a String property value.

Specified by:
getStringValue in interface Properties
Parameters:
key - The property key.
Returns:
The String value of the property.

getStringValue

public String getStringValue(String key,
                             String def)
Description copied from interface: Properties
Get a String property value. If the property is missing, return a default value.

Specified by:
getStringValue in interface Properties
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

public String putStringValue(String key,
                             String value)
Description copied from interface: Properties
Set a property with a String value.

Specified by:
putStringValue in interface Properties
Parameters:
key - The property key.
value - The property value.
Returns:
The property's old value, or null if it was not set before.

getObjectValue

public Serializable getObjectValue(String key)
Description copied from interface: Properties
Get an Object (Serializable) property value.

Specified by:
getObjectValue in interface Properties
Parameters:
key - The property key.
Returns:
The Object value of the property.

getObjectValue

public Serializable getObjectValue(String key,
                                   Serializable def)
Description copied from interface: Properties
Get an Object (Serializable) property value. If the property is missing, return a default value.

Specified by:
getObjectValue in interface Properties
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.

putObjectValue

public String putObjectValue(String key,
                             Serializable value)
Description copied from interface: Properties
Set a property with an Object (Serializable) value.

Specified by:
putObjectValue in interface Properties
Parameters:
key - The property key.
value - The property value.
Returns:
The property's old value, or null if it was not set before.

getIntValue

public int getIntValue(String key)
Description copied from interface: Properties
Get an int property value.

Specified by:
getIntValue in interface Properties
Parameters:
key - The property key.
Returns:
The int value of the property.

getIntValue

public int getIntValue(String key,
                       int def)
Description copied from interface: Properties
Get an int property value. If the property is missing, return a default value.

Specified by:
getIntValue in interface Properties
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.

putIntValue

public String putIntValue(String key,
                          int value)
Description copied from interface: Properties
Set a property with an int value.

Specified by:
putIntValue in interface Properties
Parameters:
key - The property key.
value - The property value.
Returns:
The property's old value, or null if it was not set before.

getLongValue

public long getLongValue(String key)
Description copied from interface: Properties
Get a long property value.

Specified by:
getLongValue in interface Properties
Parameters:
key - The property key.
Returns:
The long value of the property.

getLongValue

public long getLongValue(String key,
                         long def)
Description copied from interface: Properties
Get a long property value. If the property is missing, return a default value.

Specified by:
getLongValue in interface Properties
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.

putLongValue

public String putLongValue(String key,
                           long value)
Description copied from interface: Properties
Set a property with a long value.

Specified by:
putLongValue in interface Properties
Parameters:
key - The property key.
value - The property value.
Returns:
The property's old value, or null if it was not set before.

getBooleanValue

public boolean getBooleanValue(String key)
Description copied from interface: Properties
Get a boolean property value.

Specified by:
getBooleanValue in interface Properties
Parameters:
key - The property key.
Returns:
The boolean value of the property.

getBooleanValue

public boolean getBooleanValue(String key,
                               boolean def)
Description copied from interface: Properties
Get a boolean property value. If the property is missing, return a default value.

Specified by:
getBooleanValue in interface Properties
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

public String putBooleanValue(String key,
                              boolean value)
Description copied from interface: Properties
Set a property with a boolean value.

Specified by:
putBooleanValue in interface Properties
Parameters:
key - The property key.
value - The property value.
Returns:
The property's old value, or null if it was not set before.

getDoubleValue

public double getDoubleValue(String key)
Description copied from interface: Properties
Get a double property value.

Specified by:
getDoubleValue in interface Properties
Parameters:
key - The property key.
Returns:
The double value of the property.

getDoubleValue

public double getDoubleValue(String key,
                             double def)
Description copied from interface: Properties
Get a double property value. If the property is missing, return a default value.

Specified by:
getDoubleValue in interface Properties
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.

putDoubleValue

public String putDoubleValue(String key,
                             double value)
Description copied from interface: Properties
Set a property with a double value.

Specified by:
putDoubleValue in interface Properties
Parameters:
key - The property key.
value - The property value.
Returns:
The property's old value, or null if it was not set before.

getFloatValue

public float getFloatValue(String key)
Description copied from interface: Properties
Get a float property value.

Specified by:
getFloatValue in interface Properties
Parameters:
key - The property key.
Returns:
The float value of the property.

getFloatValue

public float getFloatValue(String key,
                           float def)
Description copied from interface: Properties
Get a float property value. If the property is missing, return a default value.

Specified by:
getFloatValue in interface Properties
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.

putFloatValue

public String putFloatValue(String key,
                            float value)
Description copied from interface: Properties
Set a property with a float value.

Specified by:
putFloatValue in interface Properties
Parameters:
key - The property key.
value - The property value.
Returns:
The property's old value, or null if it was not set before.

getStringArrayValue

public String[] getStringArrayValue(String key)
Description copied from interface: Properties
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.

Specified by:
getStringArrayValue in interface Properties
Parameters:
key - The property key.
Returns:
The property value, split around the regexp "\\s*,\\s*".

getStringArrayValue

public String[] getStringArrayValue(String key,
                                    String[] def)
Description copied from interface: Properties
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.

Specified by:
getStringArrayValue in interface Properties
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

public String[] getSplitStringArrayValue(String key,
                                         String regexp)
Description copied from interface: Properties
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.

Specified by:
getSplitStringArrayValue in interface Properties
Parameters:
key - The property key.
regexp - The regular expression.
Returns:
The property value.

getSplitStringArrayValue

public String[] getSplitStringArrayValue(String key,
                                         String regexp,
                                         String[] def)
Description copied from interface: Properties
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.

Specified by:
getSplitStringArrayValue in interface Properties
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

public String putStringArrayValue(String key,
                                  String[] value)
Description copied from interface: Properties
Set a property with a String array value. Use the default delimiter (",") to separate the values.

Specified by:
putStringArrayValue in interface Properties
Parameters:
key - The property key.
value - The property value.
Returns:
The property's old value, or null if it was not set before.

putStringArrayValue

public String putStringArrayValue(String key,
                                  String[] value,
                                  String delimiter)
Description copied from interface: Properties
Set a property with a String array value. Use the provided delimiter to separate the values.

Specified by:
putStringArrayValue in interface Properties
Parameters:
key - The property key.
value - The property value.
Returns:
The property's old value, or null if it was not set before.

getAsJavaProperties

public Properties getAsJavaProperties()
Description copied from interface: Properties
Get the contents of this properties object in a Properties object.

Specified by:
getAsJavaProperties in interface Properties
Returns:
A Properties object with the same contents as this object.

putAll

public void putAll(Properties p)
Description copied from interface: Properties
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.

Specified by:
putAll in interface Properties
Parameters:
p - A Properties object.

getPropertyValue

public PropertyValue getPropertyValue(String key)
Description copied from interface: Properties
Return a property value as a PropertyValue object.

Specified by:
getPropertyValue in interface Properties
Parameters:
key - The property key.
Returns:
The property value.
See Also:
Properties.getPropertyValue(String, PropertyValue)

getPropertyValue

public PropertyValue getPropertyValue(String key,
                                      PropertyValue defaultVal)
Description copied from interface: Properties
Get a property value. If the property is not set, return a default value.

Specified by:
getPropertyValue in interface Properties
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.
See Also:
Properties.getPropertyValue(String)

putPropertyValue

public String putPropertyValue(String key,
                               PropertyValue value)
Description copied from interface: Properties
Set a property value.

Specified by:
putPropertyValue in interface Properties
Parameters:
key - The property name.
value - The property value.
Returns:
The previous value for the property, or null if it was not set.

getPropertiesMatching

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

Specified by:
getPropertiesMatching in interface Properties
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.
See Also:
Properties.getPropertiesMatching(Glob)

getPropertiesMatching

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

Specified by:
getPropertiesMatching in interface Properties
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.
See Also:
Properties.getPropertiesMatching(Pattern)

propertyValues

public Collection<PropertyValue> propertyValues()
Description copied from interface: Properties
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.

Specified by:
propertyValues in interface Properties
Returns:
A collection of property values.

propertyEntrySet

public Set<Map.Entry<String,PropertyValue>> propertyEntrySet()
Description copied from interface: Properties
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.

Specified by:
propertyEntrySet in interface Properties
Returns:
The entry set.