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

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  List<GlobalParameterConstraint> globalParameterConstraints
          Contains constraints addressing several parameters
static String NEWLINE
          The newline-String dependent on the system.
static String OPTION_PREFIX
          Prefix of option markers on the command line.
private  Map<String,Option<?>> parameters
          Contains the optionHandler's options, the option names are used as the map's keys
 
Fields inherited from class de.lmu.ifi.dbs.elki.logging.AbstractLoggable
debug, logger
 
Constructor Summary
OptionHandler()
          Provides an OptionHandler.
 
Method Summary
protected  void checkGlobalParameterConstraints()
           
private  void checkNonOptionalParameters()
           
 List<GlobalParameterConstraint> getGlobalParameterConstraints()
           
 Option<?>[] getOptions()
          Get the available options of this handler.
 List<String> grabOptions(List<String> currentOptions)
          Reads the options out of a given String-array (usually the args of any main-method).
 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)
          Add a global parameter constraint.
 
Methods inherited from class de.lmu.ifi.dbs.elki.logging.AbstractLoggable
debugFine, debugFiner, debugFinest, exception, progress, 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 option markers on the command line.

The option markers are supposed to be given on the command line with leading -.

See Also:
Constant Field Values

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()
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.

Method Detail

grabOptions

public List<String> grabOptions(List<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:
ParameterException - if a parameter, for which a value is required, has none (e.g. because the next value is itself some option)

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)
Add a global parameter constraint.

Parameters:
gpc - constraint

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()
Get the available options of this handler.

Returns:
new array of options.

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

getGlobalParameterConstraints

public List<GlobalParameterConstraint> getGlobalParameterConstraints()

Release 0.2 (2009-07-06_1820)