org.jppf.utils
Class TypedProperties

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<Object,Object>
          extended by java.util.Properties
              extended by org.jppf.utils.TypedProperties
All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>
Direct Known Subclasses:
OptionDescriptor

public class TypedProperties
extends Properties

Extension of the java.util.Properties class to handle the conversion of string values to other types.

Author:
Laurent Cohen
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
TypedProperties()
          Default constructor.
TypedProperties(Map<Object,Object> map)
          Initialize this object with a set of existing properties.
 
Method Summary
 String asString()
          Convert this set of properties into a string.
 boolean getBoolean(String key)
          Get the boolean value of a property with a specified name.
 boolean getBoolean(String key, boolean defValue)
          Get the boolean value of a property with a specified name.
 char getChar(String key)
          Get the char value of a property with a specified name.
 char getChar(String key, char defValue)
          Get the char value of a property with a specified name.
 double getDouble(String key)
          Get the double precision value of a property with a specified name.
 double getDouble(String key, double defValue)
          Get the double precision value of a property with a specified name.
 float getFloat(String key)
          Get the single precision value of a property with a specified name.
 float getFloat(String key, float defValue)
          Get the single precision value of a property with a specified name.
 InetAddress getInetAddress(String key)
          Get the value of a property with the specified name as an InetAddress.
 InetAddress getInetAddress(String key, InetAddress def)
          Get the value of a property with the specified name as an InetAddress.
 int getInt(String key)
          Get the integer value of a property with a specified name.
 int getInt(String key, int defValue)
          Get the integer value of a property with a specified name.
 long getLong(String key)
          Get the long integer value of a property with a specified name.
 long getLong(String key, long defValue)
          Get the long integer value of a property with a specified name.
 TypedProperties getProperties(String key)
          Get the value of a property with the specified name as a set of a properties.
 TypedProperties getProperties(String key, TypedProperties def)
          Get the value of a property with the specified name as a set of properties.
 String getString(String key)
          Get the string value of a property with a specified name.
 String getString(String key, String defValue)
          Get the string value of a property with a specified name.
 void loadString(String source)
          Load this set of properties from a string.
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, load, loadFromXML, propertyNames, save, setProperty, store, store, storeToXML, storeToXML, stringPropertyNames
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TypedProperties

public TypedProperties()
Default constructor.


TypedProperties

public TypedProperties(Map<Object,Object> map)
Initialize this object with a set of existing properties. This will copy into the present object all map entries such that both key and value are strings.

Parameters:
map - the properties to be copied. No reference to this parameter is kept in this TypedProperties object.
Method Detail

getString

public String getString(String key)
Get the string value of a property with a specified name.

Parameters:
key - the name of the property to look for.
Returns:
the value of the property as a string, or null if it is not found.

getString

public String getString(String key,
                        String defValue)
Get the string value of a property with a specified name.

Parameters:
key - the name of the property to look for.
defValue - a default value to return if the property is not found.
Returns:
the value of the property as a string, or the default value if it is not found.

getInt

public int getInt(String key)
Get the integer value of a property with a specified name.

Parameters:
key - the name of the property to look for.
Returns:
the value of the property as an int, or zero if it is not found.

getInt

public int getInt(String key,
                  int defValue)
Get the integer value of a property with a specified name.

Parameters:
key - the name of the property to look for.
defValue - a default value to return if the property is not found.
Returns:
the value of the property as an int, or the default value if it is not found.

getLong

public long getLong(String key)
Get the long integer value of a property with a specified name.

Parameters:
key - the name of the property to look for.
Returns:
the value of the property as a long, or zero if it is not found.

getLong

public long getLong(String key,
                    long defValue)
Get the long integer value of a property with a specified name.

Parameters:
key - the name of the property to look for.
defValue - a default value to return if the property is not found.
Returns:
the value of the property as a long, or the default value if it is not found.

getFloat

public float getFloat(String key)
Get the single precision value of a property with a specified name.

Parameters:
key - the name of the property to look for.
Returns:
the value of the property as a float, or zero if it is not found.

getFloat

public float getFloat(String key,
                      float defValue)
Get the single precision value of a property with a specified name.

Parameters:
key - the name of the property to look for.
defValue - a default value to return if the property is not found.
Returns:
the value of the property as a float, or the default value if it is not found.

getDouble

public double getDouble(String key)
Get the double precision value of a property with a specified name.

Parameters:
key - the name of the property to look for.
Returns:
the value of the property as a double, or zero if it is not found.

getDouble

public double getDouble(String key,
                        double defValue)
Get the double precision value of a property with a specified name.

Parameters:
key - the name of the property to look for.
defValue - a default value to return if the property is not found.
Returns:
the value of the property as a double, or the default value if it is not found.

getBoolean

public boolean getBoolean(String key)
Get the boolean value of a property with a specified name.

Parameters:
key - the name of the property to look for.
Returns:
the value of the property as a boolean, or false if it is not found.

getBoolean

public boolean getBoolean(String key,
                          boolean defValue)
Get the boolean value of a property with a specified name.

Parameters:
key - the name of the property to look for.
defValue - a default value to return if the property is not found.
Returns:
the value of the property as a boolean, or the default value if it is not found.

getChar

public char getChar(String key)
Get the char value of a property with a specified name. If the key is not found a default value of ' ' is returned.

Parameters:
key - the name of the property to look for.
Returns:
the value of the property as a char, or the default value ' ' (space character) if it is not found.

getChar

public char getChar(String key,
                    char defValue)
Get the char value of a property with a specified name. If the value has more than one character, the first one will be used.

Parameters:
key - the name of the property to look for.
defValue - a default value to return if the property is not found.
Returns:
the value of the property as a char, or the default value if it is not found.

getProperties

public TypedProperties getProperties(String key)
Get the value of a property with the specified name as a set of a properties.

Parameters:
key - the name of the property to look for. Its value is the path to another properties file. Relative paths are evaluated against the current application directory.
Returns:
the value of the property as another set of properties, or null if it is not found.

getProperties

public TypedProperties getProperties(String key,
                                     TypedProperties def)
Get the value of a property with the specified name as a set of properties.

Parameters:
key - the name of the property to look for. Its value is the path to another properties file. Relative paths are evaluated against the current application directory.
def - a default value to return if the property is not found.
Returns:
the value of the property as another set of properties, or the default value if it is not found.

getInetAddress

public InetAddress getInetAddress(String key)
Get the value of a property with the specified name as an InetAddress.

Parameters:
key - the name of the property to retrieve.
Returns:
the property as an InetAddress instance, or null if the property is not defined or the host doesn't exist.

getInetAddress

public InetAddress getInetAddress(String key,
                                  InetAddress def)
Get the value of a property with the specified name as an InetAddress.

Parameters:
key - the name of the property to retrieve.
def - the default value to use if the property is not defined.
Returns:
the property as an InetAddress instance, or the sdpecified default value if the property is not defined.

asString

public String asString()
Convert this set of properties into a string.

Returns:
a representation of this object as a string.

loadString

public void loadString(String source)
                throws IOException
Load this set of properties from a string.

Parameters:
source - the string to load from.
Throws:
IOException - if any error occurs.


Copyright © 2005-2010 JPPF Team.