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.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>
Type Parameters:
C - Class type

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

Parameter class for a parameter specifying a class name.

Author:
Steffi Wanka

Field Summary
protected static Logging logger
          Logger
static String NONBREAKING_SPACE
          Non-breaking unicode space character.
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
optionid, shortDescription, value
 
Constructor Summary
ClassParameter(OptionID optionID, Class<?> restrictionClass)
          Constructs a class parameter with the given optionID, and restriction class.
ClassParameter(OptionID optionID, Class<?> restrictionClass, boolean optional)
          Constructs a class parameter with the given optionID, restriction class, and optional flag.
ClassParameter(OptionID optionID, Class<?> restrictionClass, String defaultValue)
          Constructs a class parameter with the given optionID, restriction class, and default value.
 
Method Summary
 IterateKnownImplementations getKnownImplementations()
          Get an iterator over all known implementations of the class restriction.
 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.
 String getSyntax()
          Returns a string representation of the parameter's type.
 String getValuesDescription()
          Return a description of known valid classes.
 boolean hasValuesDescription()
          This class sometimes provides a list of value descriptions.
 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.
 String restrictionString(Class<?> superclass)
          Provides a description string listing all classes for the given superclass or interface as specified in the properties.
static boolean satisfiesClassRestriction(Class<?> restrictionClass, String value)
          Try to satisfy a single class restriction
private  void setCorrectValue(String value)
          Tries to set the correct value for 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, getFullDescription, getValue, hasDefaultValue, isOptional, isSet, reset, setDefaultValue, setDefaultValueToValue, setOptional, tookDefaultValue
 
Methods inherited from class de.lmu.ifi.dbs.elki.utilities.optionhandling.Option
getName, getOptionID, getShortDescription, setShortDescription
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static Logging logger
Logger


restrictionClass

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


NONBREAKING_SPACE

public static final String NONBREAKING_SPACE
Non-breaking unicode space character.

See Also:
Constant Field Values
Constructor Detail

ClassParameter

public ClassParameter(OptionID optionID,
                      Class<?> 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<?> 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<?> 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
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.

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.

satisfiesClassRestriction

public static boolean satisfiesClassRestriction(Class<?> restrictionClass,
                                                String value)
                                         throws ClassNotFoundException
Try to satisfy a single class restriction

Parameters:
restrictionClass -
value -
Returns:
if the class restriction is satisfied.
Throws:
ClassNotFoundException

getRestrictionClass

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

Returns:
the restriction class of this class parameter.

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)

getSyntax

public String getSyntax()
Returns a string representation of the parameter's type.

Specified by:
getSyntax in class Option<String>
Returns:
"<class>"

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

hasValuesDescription

public boolean hasValuesDescription()
This class sometimes provides a list of value descriptions.

Overrides:
hasValuesDescription in class Parameter<String,String>
Returns:
whether the class has a description of valid values.
See Also:
Parameter.hasValuesDescription()

getValuesDescription

public String getValuesDescription()
Return a description of known valid classes.

Overrides:
getValuesDescription in class Parameter<String,String>
Returns:
String explaining valid values (e.g. a class list)
See Also:
Parameter.getValuesDescription()

getKnownImplementations

public IterateKnownImplementations getKnownImplementations()
Get an iterator over all known implementations of the class restriction.

Returns:
Iterable and Iterator object

restrictionString

public String restrictionString(Class<?> superclass)
Provides a description string listing all classes for the given superclass or interface as specified in the properties.

Parameters:
superclass - the class to be extended or interface to be implemented
Returns:
a description string listing all classes for the given superclass or interface as specified in the properties

Release 0.2 (2009-07-06_1820)