net.sf.doolin.util
Class ParameterSet

java.lang.Object
  extended by net.sf.doolin.util.ParameterSet

public class ParameterSet
extends Object

Set of parameters that provides the developer a list of utility methods to retrieve values from.

Author:
Damien Coraboeuf

Constructor Summary
ParameterSet()
          Empty constructor
ParameterSet(Map<String,String> map)
          Constructor from an existing map
ParameterSet(Properties properties)
          Constructor from a set of properties
 
Method Summary
 void addParam(String name, boolean value)
          Adds a boolean parameter
 void addParam(String name, int value)
          Adds an integer parameter
 void addParam(String name, String value)
          Add a parameter
 void addParams(Map<String,String> params)
          Adds a set of parameters
 boolean getBooleanParam(String name, boolean mandatory, boolean defaultValue)
          Get a boolean parameter
 Object getConstant(String name, Class<?> type, boolean mandatory, Object defaultValue)
          Gets a parameter as a constant name for a given class and then uses this constant name to get its actual value.
 double getDoubleParam(String name, boolean mandatory, double defaultValue)
          Get a double parameter
 int getIntParam(String name, boolean mandatory, int defaultValue)
          Get an int parameter
 String getParam(String name)
          Get a parameter as a string
 String getParam(String name, boolean mandatory, String defaultValue)
          Get a string parameter
 Map<String,String> getParams()
          Read-only access to parameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParameterSet

public ParameterSet()
Empty constructor


ParameterSet

public ParameterSet(Map<String,String> map)
Constructor from an existing map

Parameters:
map - Existing map. This map is not directly used by the parameter set since it is duplicated.

ParameterSet

public ParameterSet(Properties properties)
Constructor from a set of properties

Parameters:
properties - Set of properties to get parameters from
Method Detail

addParam

public void addParam(String name,
                     boolean value)
Adds a boolean parameter

Parameters:
name - Parameter's name
value - Parameter's value

addParam

public void addParam(String name,
                     int value)
Adds an integer parameter

Parameters:
name - Parameter's name
value - Parameter's value

addParam

public void addParam(String name,
                     String value)
Add a parameter

Parameters:
name - Parameter's name
value - Parameter's value

addParams

public void addParams(Map<String,String> params)
Adds a set of parameters

Parameters:
params - Parameters to be added

getBooleanParam

public boolean getBooleanParam(String name,
                               boolean mandatory,
                               boolean defaultValue)
                        throws MissingParameterException
Get a boolean parameter

Parameters:
name - Parameter's name
mandatory - Indicates if the parameter must be present.
defaultValue - Value to be used if the parameter is not found and if it is not mandatory.
Returns:
Parameter's value or null if not found.
Throws:
MissingParameterException - If the parameter is not found when it is mandatory.

getConstant

public Object getConstant(String name,
                          Class<?> type,
                          boolean mandatory,
                          Object defaultValue)
Gets a parameter as a constant name for a given class and then uses this constant name to get its actual value. For example, the call to getConstant("key", SwingConstants.class, true, null) will return the value for SwingConstant.LEFT if the value associated with "key" is "LEFT".

Parameters:
name - Key name
type - Type that contains the constant definition
mandatory - true if the value is required
defaultValue - Default value if the value is not required and if the key is not found
Returns:
Value or null

getDoubleParam

public double getDoubleParam(String name,
                             boolean mandatory,
                             double defaultValue)
                      throws MissingParameterException
Get a double parameter

Parameters:
name - Parameter's name
mandatory - Indicates if the parameter must be present.
defaultValue - Value to be used if the parameter is not found and if it is not mandatory.
Returns:
Parameter's value or null if not found.
Throws:
MissingParameterException - If the parameter is not found when it is mandatory.

getIntParam

public int getIntParam(String name,
                       boolean mandatory,
                       int defaultValue)
                throws MissingParameterException
Get an int parameter

Parameters:
name - Parameter's name
mandatory - Indicates if the parameter must be present.
defaultValue - Value to be used if the parameter is not found and if it is not mandatory.
Returns:
Parameter's value or null if not found.
Throws:
MissingParameterException - If the parameter is not found when it is mandatory.

getParam

public String getParam(String name)
Get a parameter as a string

Parameters:
name - Parameter's name
Returns:
Parameter's value or null if not found.

getParam

public String getParam(String name,
                       boolean mandatory,
                       String defaultValue)
                throws MissingParameterException
Get a string parameter

Parameters:
name - Parameter's name
mandatory - Indicates if the parameter must be present.
defaultValue - Value to be used if the parameter is not found and if it is not mandatory.
Returns:
Parameter's value or null if not found.
Throws:
MissingParameterException - If the parameter is not found when it is mandatory.

getParams

public Map<String,String> getParams()
Read-only access to parameters

Returns:
A read-only version of the underlying parameter's map.


Copyright © 2011. All Rights Reserved.