jj2000.j2k.util
Class ParameterList

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--java.util.Properties
                    |
                    +--jj2000.j2k.util.ParameterList
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class ParameterList
extends java.util.Properties

This class holds modules options and parameters as they are provided to the encoder or the decoder. Each option and its associated parameters are stored as strings.

This class is built on the standard Java Properties class. Consequently, it offers facilities to load and write parameters from/to a file. In the meantime, a ParameterList object can also handle default parameters for each option.

Each parameter can be retrieved as a string or as an specific primitive type (int, float, etc).

For more details see the Properties class.

Note that this class does not support multiple occurrences of parameters (for a parameter name, only one value is possible). Also there is no particular order of the parameters.

See Also:
Properties, Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.Hashtable
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
 
Fields inherited from class java.util.Properties
defaults
 
Fields inherited from class java.util.Hashtable
 
Constructor Summary
ParameterList()
          Constructs an empty ParameterList object.
ParameterList(ParameterList def)
          Constructs an empty ParameterList object with the provided default parameters.
 
Method Summary
 void checkList(char[] prfxs, java.lang.String[] plist)
          Checks if the parameters which names do not start with any of the prefixes in 'prfxs' in this ParameterList are all in the list of valid parameter names 'plist'.
 void checkList(char prfx, java.lang.String[] plist)
          Checks if the parameters which name starts with the prefix 'prfx' in the parameter list are all in the list of valid parameter names 'plist'.
 boolean getBooleanParameter(java.lang.String pname)
          Returns the value of the named parameter as a boolean.
 ParameterList getDefaultParameterList()
          Returns the default ParameterList.
 float getFloatParameter(java.lang.String pname)
          Returns the value of the named parameter as a float.
 int getIntParameter(java.lang.String pname)
          Returns the value of the named parameter as an int.
 java.lang.String getParameter(java.lang.String pname)
          Returns the value of the named parameter, as a string.
 void parseArgs(java.lang.String[] argv)
          Parses the parameters from an argument list, such as as the one in the command line, and integrates them in this parameter list.
static java.lang.String[] toNameArray(java.lang.String[][] pinfo)
          Converts the usage information to a list of parameter names in a single array.
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, propertyNames, save, setProperty, store
 
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

ParameterList

public ParameterList()
Constructs an empty ParameterList object. It can be later completed by adding elements one by one, by loading them from a file, or by initializing them from an argument string.


ParameterList

public ParameterList(ParameterList def)
Constructs an empty ParameterList object with the provided default parameters. The list can be later updated by adding elements one by one, by loading them from a file, or by initializing them from an argument string.

Parameters:
def - The defaults parameters
Method Detail

getDefaultParameterList

public ParameterList getDefaultParameterList()
Returns the default ParameterList.

Returns:
Default ParameterList

parseArgs

public void parseArgs(java.lang.String[] argv)
Parses the parameters from an argument list, such as as the one in the command line, and integrates them in this parameter list.

All options must be preceded by '-' and then followed by one or more words, which constitues the values. The name of the options constitute the name of the parameters. The only exception is for boolean options, in which case if they are preceded by '-' they will be turned on, and if preceded by '+' they will be turned off. The string value of a boolean option is "on" or "off". Note that the '-' and '+' characters can not precede any word which would be a value for an option unless they are numeric values (otherwise it would be considered as a boolean option). Note also that the name of an option can not start with a number.

No option can appear more than once. If so happens an exception is thrown.

For instance the string: "-Ffilters w5x3 -Wlev 5 -Qtype reversible

will create the following parameter list:

 Ffilers  w5x3
 Wlev     5
 Qtype    reversible
 

Parameters:
argv - The argument list.
Throws:
StringFormatException - if there are invalid arguments in 'argv'

getParameter

public java.lang.String getParameter(java.lang.String pname)
Returns the value of the named parameter, as a string. The value can come from teh defaults, if there are.

Parameters:
pname - The parameter name.
Returns:
the value of the parameter as a string, or null if there is no parameter with the name 'pname'.

getBooleanParameter

public boolean getBooleanParameter(java.lang.String pname)
Returns the value of the named parameter as a boolean. The value "on" is interpreted as 'true', while the value "off" is interpreted as 'false'. If the parameter has another value then an StringFormatException is thrown. If the parameter 'pname' is not in the parameter list, an IllegalArgumentException is thrown.

Parameters:
pname - The parameter name.
Returns:
the value of the parameter as a boolean.
Throws:
StringFormatException - If the parameter has a value which is neither "on" nor "off".
java.lang.IllegalArgumentException - If there is no parameter with the name 'pname' in the parameter list.

getIntParameter

public int getIntParameter(java.lang.String pname)
Returns the value of the named parameter as an int. If the parameter has a non-numeric value a NumberFormatException is thrown. If the parameter has a multiple word value than the first word is returned as an int, others are ignored. If the parameter 'pname' is not in the parameter list, an IllegalArgumentException is thrown.

Parameters:
pname - The parameter name.
Returns:
the value of the parameter as an int.
Throws:
java.lang.NumberFormatException - If the parameter has a non-numeric value.
java.lang.IllegalArgumentException - If there is no parameter with the name 'pname' in the parameter list.

getFloatParameter

public float getFloatParameter(java.lang.String pname)
Returns the value of the named parameter as a float. If the parameter has a non-numeric value a NumberFormatException is thrown. If the parameter has a multiple word value than the first word is returned as an int, others are ignored. If the parameter 'pname' is not in the parameter list, an IllegalArgumentException is thrown.

Parameters:
pname - The parameter name.
Returns:
the value of the parameter as a float.
Throws:
java.lang.NumberFormatException - If the parameter has a non-numeric value.
java.lang.IllegalArgumentException - If there is no parameter with the name 'pname' in the parameter list.

checkList

public void checkList(char prfx,
                      java.lang.String[] plist)
Checks if the parameters which name starts with the prefix 'prfx' in the parameter list are all in the list of valid parameter names 'plist'. If there is a parameter that is not in 'plist' an IllegalArgumentException is thrown with an explanation message. The default parameters are also included in the check.

Parameters:
prfx - The prefix of parameters to check.
plist - The list of valid parameter names for the 'prfx' prefix. If null it is considered that no names are valid.
Throws:
java.lang.IllegalArgumentException - If there's a parameter name starting with 'prfx' which is not in the valid list of parameter names.

checkList

public void checkList(char[] prfxs,
                      java.lang.String[] plist)
Checks if the parameters which names do not start with any of the prefixes in 'prfxs' in this ParameterList are all in the list of valid parameter names 'plist'. If there is a parameter that is not in 'plist' an IllegalArgumentException is thrown with an explanation message. The default parameters are also included in the check.

Parameters:
prfxs - The prefixes of parameters to ignore.
plist - The list of valid parameter names. If null it is considered that no names are valid.
Throws:
java.lang.IllegalArgumentException - If there's a parameter name not starting with 'prfx' which is not in the valid list of parameter names.

toNameArray

public static java.lang.String[] toNameArray(java.lang.String[][] pinfo)
Converts the usage information to a list of parameter names in a single array. The usage information appears in a 2D array of String. The first dimensions contains the different options, the second dimension contains the name of the option (first element), the synopsis and the explanation. This method takes the names of the different options in 'pinfo' and returns them in a single array of String.

Parameters:
pinfo - The list of options and their usage info (see above).
Returns:
An array with the names of the options in pinfo. If pinfo is null, null is returned.