Class Parameters
- All Implemented Interfaces:
Serializable
Parameters class represents a set of key-value
pairs.
The Parameters object provides a mechanism to obtain
values based on a String name. There are convenience
methods that allow you to use defaults if the value does not exist,
as well as obtain the value in any of the same formats that are in
the Configuration interface.
While there are similarities between the Parameters
object and the java.util.Properties object, there are some
important semantic differences. First, Parameters are
read-only. Second, Parameters are easily
derived from Configuration objects. Lastly, the
Parameters object is derived from XML fragments that
look like this:
<parameter name="param-name" value="param-value" />
Note: this class is not thread safe by default. If you require thread safety please synchronize write access to this class to prevent potential data corruption.
- Version:
- CVS $Revision: 1.41 $ $Date: 2004/02/11 14:34:25 $
- Author:
- Avalon Development Team
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidChecks is thisParametersobject is writeable.static ParametersfromConfiguration(Configuration configuration) Create aParametersobject from aConfigurationobject.static ParametersfromConfiguration(Configuration configuration, String elementName) Create aParametersobject from aConfigurationobject using the supplied element name.static ParametersfromProperties(Properties properties) Create aParametersobject from aPropertiesobject.String[]getNames()Retrieve an array of all parameter names.getParameter(String name) Retrieve theStringvalue of the specified parameter.getParameter(String name, String defaultValue) Retrieve theStringvalue of the specified parameter.booleangetParameterAsBoolean(String name) Retrieve thebooleanvalue of the specified parameter.booleangetParameterAsBoolean(String name, boolean defaultValue) Retrieve thebooleanvalue of the specified parameter.floatgetParameterAsFloat(String name) Retrieve thefloatvalue of the specified parameter.floatgetParameterAsFloat(String name, float defaultValue) Retrieve thefloatvalue of the specified parameter.intgetParameterAsInteger(String name) Retrieve theintvalue of the specified parameter.intgetParameterAsInteger(String name, int defaultValue) Retrieve theintvalue of the specified parameter.longgetParameterAsLong(String name) Retrieve thelongvalue of the specified parameter.longgetParameterAsLong(String name, long defaultValue) Retrieve thelongvalue of the specified parameter.Deprecated.Use getNames() insteadbooleanisParameter(String name) Test if the specified parameter can be retrieved.voidMake this Parameters read-only so that it will throw aIllegalStateExceptionif someone tries to modify it.merge(Parameters other) Merge parameters from anotherParametersinstance into this.voidremoveParameter(String name) Remove a parameter from the parameters objectsetParameter(String name, String value) Set theStringvalue of a specified parameter.static PropertiestoProperties(Parameters params) Creates ajava.util.Propertiesobject from an Avalon Parameters object.
-
Field Details
-
EMPTY_PARAMETERS
Empty Parameters object- Since:
- 4.1.2
-
-
Constructor Details
-
Parameters
public Parameters()
-
-
Method Details
-
setParameter
Set theStringvalue of a specified parameter. If the specified value is null the parameter is removed.- Parameters:
name- aStringvaluevalue- aStringvalue- Returns:
- The previous value of the parameter or null.
- Throws:
IllegalStateException- if the Parameters object is read-only
-
removeParameter
Remove a parameter from the parameters object- Parameters:
name- aStringvalue- Since:
- 4.1
-
getParameterNames
Deprecated.Use getNames() insteadReturn anIteratorview of all parameter names.- Returns:
- a iterator of parameter names
-
getNames
Retrieve an array of all parameter names.- Returns:
- the parameters names
-
isParameter
Test if the specified parameter can be retrieved.- Parameters:
name- the parameter name- Returns:
- true if parameter is a name
-
getParameter
Retrieve theStringvalue of the specified parameter. If the specified parameter cannot be found, an exception is thrown.- Parameters:
name- the name of parameter- Returns:
- the value of parameter
- Throws:
ParameterException- if the specified parameter cannot be found
-
getParameter
Retrieve theStringvalue of the specified parameter. If the specified parameter cannot be found,defaultValueis returned.- Parameters:
name- the name of parameterdefaultValue- the default value, returned if parameter does not exist or parameter's name is null- Returns:
- the value of parameter
-
getParameterAsInteger
Retrieve theintvalue of the specified parameter. If the specified parameter cannot be found, an exception is thrown. Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary numbers begin with 0b, all other values are assumed to be decimal.- Parameters:
name- the name of parameter- Returns:
- the integer parameter type
- Throws:
ParameterException- if the specified parameter cannot be found or is not an Integer value
-
getParameterAsInteger
Retrieve theintvalue of the specified parameter. If the specified parameter cannot be found,defaultValueis returned. Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary numbers begin with 0b, all other values are assumed to be decimal.- Parameters:
name- the name of parameterdefaultValue- value returned if parameter does not exist or is of wrong type- Returns:
- the integer parameter type
-
getParameterAsLong
Retrieve thelongvalue of the specified parameter. If the specified parameter cannot be found, an exception is thrown. Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary numbers begin with 0b, all other values are assumed to be decimal.- Parameters:
name- the name of parameter- Returns:
- the long parameter type
- Throws:
ParameterException- if the specified parameter cannot be found or is not a Long value.
-
getParameterAsLong
Retrieve thelongvalue of the specified parameter. If the specified parameter cannot be found,defaultValueis returned. Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary numbers begin with 0b, all other values are assumed to be decimal.- Parameters:
name- the name of parameterdefaultValue- value returned if parameter does not exist or is of wrong type- Returns:
- the long parameter type
-
getParameterAsFloat
Retrieve thefloatvalue of the specified parameter. If the specified parameter cannot be found, an exception is thrown.- Parameters:
name- the parameter name- Returns:
- the value
- Throws:
ParameterException- if the specified parameter cannot be found or is not a Float value
-
getParameterAsFloat
Retrieve thefloatvalue of the specified parameter. If the specified parameter cannot be found,defaultValueis returned.- Parameters:
name- the parameter namedefaultValue- the default value if parameter does not exist or is of wrong type- Returns:
- the value
-
getParameterAsBoolean
Retrieve thebooleanvalue of the specified parameter. If the specified parameter cannot be found, an exception is thrown.- Parameters:
name- the parameter name- Returns:
- the value
- Throws:
ParameterException- if an error occursParameterException
-
getParameterAsBoolean
Retrieve thebooleanvalue of the specified parameter. If the specified parameter cannot be found,defaultValueis returned.- Parameters:
name- the parameter namedefaultValue- the default value if parameter does not exist or is of wrong type- Returns:
- the value
-
merge
Merge parameters from anotherParametersinstance into this.- Parameters:
other- the other Parameters- Returns:
- This
Parametersinstance.
-
makeReadOnly
public void makeReadOnly()Make this Parameters read-only so that it will throw aIllegalStateExceptionif someone tries to modify it. -
checkWriteable
Checks is thisParametersobject is writeable.- Throws:
IllegalStateException- if thisParametersobject is read-only
-
fromConfiguration
public static Parameters fromConfiguration(Configuration configuration) throws ConfigurationException Create aParametersobject from aConfigurationobject. This acts exactly like the following method call:Parameters.fromConfiguration(configuration, "parameter");- Parameters:
configuration- the Configuration- Returns:
- This
Parametersinstance. - Throws:
ConfigurationException- if an error occurs
-
fromConfiguration
public static Parameters fromConfiguration(Configuration configuration, String elementName) throws ConfigurationException Create aParametersobject from aConfigurationobject using the supplied element name.- Parameters:
configuration- the ConfigurationelementName- the element name for the parameters- Returns:
- This
Parametersinstance. - Throws:
ConfigurationException- if an error occurs- Since:
- 4.1
-
fromProperties
Create aParametersobject from aPropertiesobject.- Parameters:
properties- the Properties- Returns:
- This
Parametersinstance.
-
toProperties
Creates ajava.util.Propertiesobject from an Avalon Parameters object.- Parameters:
params- aParametersinstance- Returns:
- a
Propertiesinstance
-