Environment for
DeveLoping
KDD-Applications
Supported by Index-Structures

de.lmu.ifi.dbs.elki.utilities.optionhandling
Class ClassParameter<C>

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.logging.AbstractLoggable
      extended by de.lmu.ifi.dbs.elki.utilities.optionhandling.Option<T>
          extended by de.lmu.ifi.dbs.elki.utilities.optionhandling.Parameter<String,String>
              extended by de.lmu.ifi.dbs.elki.utilities.optionhandling.ClassParameter<C>
All Implemented Interfaces:
Loggable

public class ClassParameter<C>
extends Parameter<String,String>

Parameter class for a parameter specifying a class name.

Author:
Steffi Wanka

Field Summary
private  Class<C> restrictionClass
          The restriction class for this class parameter.
 
Fields inherited from class de.lmu.ifi.dbs.elki.utilities.optionhandling.Parameter
constraints, defaultValue, optionalParameter
 
Fields inherited from class de.lmu.ifi.dbs.elki.utilities.optionhandling.Option
name, shortDescription, value
 
Fields inherited from class de.lmu.ifi.dbs.elki.logging.AbstractLoggable
debug
 
Constructor Summary
ClassParameter(OptionID optionID, Class<C> restrictionClass)
          Constructs a class parameter with the given optionID, and restriction class.
ClassParameter(OptionID optionID, Class<C> restrictionClass, boolean optional)
          Constructs a class parameter with the given optionID, restriction class, and optional flag.
ClassParameter(OptionID optionID, Class<C> restrictionClass, String defaultValue)
          Constructs a class parameter with the given optionID, restriction class, and default value.
ClassParameter(String name, String description, Class<C> restrictionClass)
          Deprecated.  
ClassParameter(String name, String description, Class<C> restrictionClass, String defaultValue)
          Deprecated.  
 
Method Summary
protected  String getParameterType()
          Returns a string representation of the parameter's type.
 Class<C> getRestrictionClass()
          Returns the restriction class of this class parameter.
 String[] getRestrictionClasses()
          Returns the class names allowed according to the restriction class of this class parameter.
 C instantiateClass()
          Returns a new instance for the value (i.e., the class name) of this class parameter.
 boolean isValid(String value)
          Checks if the given parameter value is valid for this ClassParameter.
private  void setCorrectValue(String value)
          Tries to set the correct value for this class parameter.
 void setRestrictionClass(Class<C> restrictionClass)
          Sets the restriction class of this class parameter.
 void setValue(String value)
          Sets the value of the option.
 
Methods inherited from class de.lmu.ifi.dbs.elki.utilities.optionhandling.Parameter
addConstraint, addConstraintList, getDefaultValue, getDescription, getValue, hasDefaultValue, isOptional, isSet, reset, setDefaultValue, setDefaultValueToValue, setOptional, tookDefaultValue
 
Methods inherited from class de.lmu.ifi.dbs.elki.utilities.optionhandling.Option
getName, getShortDescription, setShortDescription
 
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

restrictionClass

private Class<C> restrictionClass
The restriction class for this class parameter.

Constructor Detail

ClassParameter

public ClassParameter(OptionID optionID,
                      Class<C> restrictionClass)
Constructs a class parameter with the given optionID, and restriction class.

Parameters:
optionID - the unique id of the option
restrictionClass - the restriction class of this class parameter

ClassParameter

public ClassParameter(OptionID optionID,
                      Class<C> restrictionClass,
                      boolean optional)
Constructs a class parameter with the given optionID, restriction class, and optional flag.

Parameters:
optionID - the unique id of the option
restrictionClass - the restriction class of this class parameter
optional - specifies if this parameter is an optional parameter

ClassParameter

public ClassParameter(OptionID optionID,
                      Class<C> restrictionClass,
                      String defaultValue)
Constructs a class parameter with the given optionID, restriction class, and default value.

Parameters:
optionID - the unique id of the option
restrictionClass - the restriction class of this class parameter
defaultValue - the default value of this class parameter

ClassParameter

@Deprecated
public ClassParameter(String name,
                                 String description,
                                 Class<C> restrictionClass)
Deprecated. 

Constructs a class parameter with the given name, description, and restriction class.

Parameters:
name - the parameter name
description - the parameter description
restrictionClass - the restriction class of this class parameter

ClassParameter

@Deprecated
public ClassParameter(String name,
                                 String description,
                                 Class<C> restrictionClass,
                                 String defaultValue)
Deprecated. 

Constructs a class parameter with the given name, description, restriction class, and default value.

Parameters:
name - the parameter name
description - the parameter description
restrictionClass - the restriction class of this class parameter
defaultValue - the default value of this class parameter
Method Detail

setValue

public void setValue(String value)
              throws ParameterException
Description copied from class: Option
Sets the value of the option.

Specified by:
setValue in class Option<String>
Parameters:
value - the option's value to be set
Throws:
ParameterException - if the given value is not a valid value for this option.
See Also:
Option.setValue(String)

getRestrictionClasses

public String[] getRestrictionClasses()
Returns the class names allowed according to the restriction class of this class parameter.

Returns:
class names allowed according to the restriction class defined.

isValid

public boolean isValid(String value)
                throws ParameterException
Checks if the given parameter value is valid for this ClassParameter. If not a parameter exception is thrown.

Specified by:
isValid in class Option<String>
Parameters:
value - option value to be checked
Returns:
true, if the given value is valid for this option
Throws:
ParameterException - if the given value is not a valid value for this option.
See Also:
Option.isValid(String)

getRestrictionClass

public Class<C> getRestrictionClass()
Returns the restriction class of this class parameter.

Returns:
the restriction class of this class parameter.

setRestrictionClass

public void setRestrictionClass(Class<C> restrictionClass)
Sets the restriction class of this class parameter.

Parameters:
restrictionClass - the restriction class to be set

setCorrectValue

private void setCorrectValue(String value)
                      throws ParameterException
Tries to set the correct value for this class parameter.

Parameters:
value - the value to be set
Throws:
ParameterException - if the specified value is not correct (e.g., it is not conform with the restriction class)

getParameterType

protected String getParameterType()
Returns a string representation of the parameter's type.

Specified by:
getParameterType in class Parameter<String,String>
Returns:
"<class>"
See Also:
Parameter.getParameterType()

instantiateClass

public C instantiateClass()
                   throws ParameterException
Returns a new instance for the value (i.e., the class name) of this class parameter. The instance has the type of the restriction class of this class parameter.

If the Class for the class name is not found, the instantiation is tried using the package of the restriction class as package of the class name.

Returns:
a new instance for the value of this class parameter
Throws:
ParameterException - if the instantiation cannot be performed successfully or the value of this class parameter is not set

Release 0.1 (2008-07-10_1838)