Environment for
DeveLoping
KDD-Applications
Supported by Index-Structures

de.lmu.ifi.dbs.elki.utilities.optionhandling
Class OptionHandler

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.logging.AbstractLoggable
      extended by de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionHandler
All Implemented Interfaces:
Loggable

public class OptionHandler
extends AbstractLoggable

Provides an OptionHandler for holding the given options.

The options specified are stored in a <String,Option>-Map (Map) with the names of the options being the keys. New options can be added by using the method put(Option).

Author:
Arthur Zimek

Field Summary
private  String[] currentParameters
          Holds the parameter array as given to the last call of grabOptions(String[]).
private  List<GlobalParameterConstraint> globalParameterConstraints
          Contains constraints addressing several parameters
static String NEWLINE
          The newline-String dependent on the system.
static String OPTION_PREFIX
          Prefix of optionmarkers on the commandline.
private  Map<String,Option<?>> parameters
          Contains the optionHandler's options, the option names are used as the map's keys
private  String programCall
          The programCall as it should be denoted in an eventual usage-message.
 
Fields inherited from class de.lmu.ifi.dbs.elki.logging.AbstractLoggable
debug
 
Constructor Summary
OptionHandler(Map<String,Option<?>> parameters, String programCall)
          Provides an OptionHandler.
 
Method Summary
 void addOptionSettings(AttributeSettings settings)
          Adds the settings of the options assigned to this option handler to the specified attribute settings.
protected  void checkGlobalParameterConstraints()
           
private  void checkNonOptionalParameters()
           
 Option<?> getOption(String name)
           
 Option<?>[] getOptions()
           
<T> T
getOptionValue(String option)
          Deprecated. use getParameterValue(parameter) instead.
 String[] getParameterArray()
          Returns a copy of the parameter array as given to the last call of grabOptions(String[]).
 String[] grabOptions(String[] currentOptions)
          Reads the options out of a given String-array (usually the args of any main-method).
 boolean isSet(Option<?> option)
          Returns true if the value of the given option is set, false otherwise.
 boolean isSet(String option)
          Returns true if the value of the given option is set, false otherwise.
 void put(Map<String,Option<?>> params)
          Deprecated.  
 void put(Option<?> option)
          Adds the given option to the OptionHandler's current parameter map.
 void remove(String optionName)
          Removes the given option from the OptionHandler's parameter map.
private  void setDefaultValues()
          Checks all parameters not specified in currentParameters for default values and sets them, if existing
 void setGlobalParameterConstraint(GlobalParameterConstraint gpc)
           
 void setProgrammCall(String call)
          Sets the OptionHandler's programmCall (@link #programCall} to the given call.
 String usage(String message)
          Returns an usage-String according to the descriptions given in the constructor.
 String usage(String message, boolean standalone)
          Returns an usage-String according to the descriptions given in the constructor.
 
Methods inherited from class de.lmu.ifi.dbs.elki.logging.AbstractLoggable
debugFine, debugFiner, debugFinest, exception, message, progress, progress, progress, verbose, verbose, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NEWLINE

public static final String NEWLINE
The newline-String dependent on the system.


OPTION_PREFIX

public static final String OPTION_PREFIX
Prefix of optionmarkers on the commandline.

The optionmarkers are supposed to be given on the commandline with leading -.

See Also:
Constant Field Values

programCall

private String programCall
The programCall as it should be denoted in an eventual usage-message.


currentParameters

private String[] currentParameters
Holds the parameter array as given to the last call of grabOptions(String[]).


parameters

private Map<String,Option<?>> parameters
Contains the optionHandler's options, the option names are used as the map's keys


globalParameterConstraints

private List<GlobalParameterConstraint> globalParameterConstraints
Contains constraints addressing several parameters

Constructor Detail

OptionHandler

public OptionHandler(Map<String,Option<?>> parameters,
                     String programCall)
Provides an OptionHandler.

The options are specified in the given TreeMap with the option names being as keys. Leading "-" do not have to be specified since OptionHandler will provide them.

Parameters:
parameters - Map containing the options
programCall - String for the program-call using this OptionHandler (for usage in usage(String))
Method Detail

grabOptions

public String[] grabOptions(String[] currentOptions)
                     throws ParameterException
Reads the options out of a given String-array (usually the args of any main-method).

Parameters:
currentOptions - an array of given options, flags without values. E.g. the args of some main-method. In this array every option should have a leading "-".
Returns:
String[] an array containing the unexpected parameters in the given order. Parameters are treated as unexpected if they are not known to the optionhandler or if they were already read.
Throws:
NoParameterValueException - if a parameter, for which a value is required, has none (e.g. because the next value is itself some option)
ParameterException

getOptionValue

public <T> T getOptionValue(String option)
                 throws UnusedParameterException,
                        NoParameterValueException
Deprecated. use getParameterValue(parameter) instead.

Returns the value of the given option, if there is one.

Parameters:
option - option to get value of. The option should be asked for without leading "-" or closing ":".
Returns:
String value of given option
Throws:
UnusedParameterException - if the given option is not used
NoParameterValueException - if the given option is only a flag and should therefore have no value

getOption

public Option<?> getOption(String name)
                    throws UnusedParameterException
Throws:
UnusedParameterException

isSet

public boolean isSet(String option)
Returns true if the value of the given option is set, false otherwise.

Parameters:
option - The option should be asked for without leading "-" or closing ":".
Returns:
boolean true if the value of the given option is set, false otherwise

isSet

public boolean isSet(Option<?> option)
Returns true if the value of the given option is set, false otherwise.

Parameters:
option - The option should be asked for without leading "-" or closing ":".
Returns:
boolean true if the value of the given option is set, false otherwise

usage

public String usage(String message)
Returns an usage-String according to the descriptions given in the constructor. Same as usage(message,true).

Parameters:
message - some error-message, if needed (may be null or empty String)
Returns:
an usage-String according to the descriptions given in the constructor.

usage

public String usage(String message,
                    boolean standalone)
Returns an usage-String according to the descriptions given in the constructor.

Parameters:
message - some error-message, if needed (may be null or empty String)
standalone - whether the class using this OptionHandler provides a main method
Returns:
an usage-String according to the descriptions given in the constructor.

getParameterArray

public String[] getParameterArray()
Returns a copy of the parameter array as given to the last call of grabOptions(String[]). The resulting array will contain only those values that were recognized and needed by this OptionHandler.

Returns:
a copy of the parameter array as given to the last call of grabOptions(String[])

put

@Deprecated
public void put(Map<String,Option<?>> params)
Deprecated. 

Adds the given parameter map to the OptionHandler's current parameter map.

Parameters:
params - Parameter map to be added.

put

public void put(Option<?> option)
Adds the given option to the OptionHandler's current parameter map.

Parameters:
option - Option to be added.

setGlobalParameterConstraint

public void setGlobalParameterConstraint(GlobalParameterConstraint gpc)

setProgrammCall

public void setProgrammCall(String call)
Sets the OptionHandler's programmCall (@link #programCall} to the given call.

Parameters:
call - The new programm call.

remove

public void remove(String optionName)
            throws UnusedParameterException
Removes the given option from the OptionHandler's parameter map.

Parameters:
optionName - Option to be removed.
Throws:
UnusedParameterException - If there is no such option.

getOptions

public Option<?>[] getOptions()

addOptionSettings

public void addOptionSettings(AttributeSettings settings)
                       throws UnusedParameterException
Adds the settings of the options assigned to this option handler to the specified attribute settings.

Parameters:
settings - the attribute settings to add the settings of the options assigned to this option handler to
Throws:
UnusedParameterException - todo

setDefaultValues

private void setDefaultValues()
Checks all parameters not specified in currentParameters for default values and sets them, if existing


checkNonOptionalParameters

private void checkNonOptionalParameters()
                                 throws ParameterException
Throws:
ParameterException

checkGlobalParameterConstraints

protected void checkGlobalParameterConstraints()
                                        throws ParameterException
Throws:
ParameterException

Release 0.1 (2008-07-10_1838)