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

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter<Class<?>,Class<? extends C>>
      extended by de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ClassParameter<C>
Type Parameters:
C - Class type
Direct Known Subclasses:
ObjectParameter

public class ClassParameter<C>
extends Parameter<Class<?>,Class<? extends C>>

Parameter class for a parameter specifying a class name.


Field Summary
static String FACTORY_POSTFIX
           
protected  Class<C> restrictionClass
          The restriction class for this class parameter.
 
Fields inherited from class de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter
constraints, defaultValue, givenValue, optionalParameter, optionid, shortDescription
 
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, Class<?> defaultValue)
          Constructs a class parameter with the given optionID, restriction class, and default value.
 
Method Summary
static String canonicalClassName(Class<?> c, Class<?> parent)
          Get the "simple" form of a class name.
static String canonicalClassName(Class<?> c, Package pkg, String postfix)
          Get the "simple" form of a class name.
 String getDefaultValueAsString()
          Get the default value as string.
 IterableIterator<Class<?>> 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 getValueAsString()
          Get the value as string.
 String getValuesDescription()
          Return a description of known valid classes.
 boolean hasValuesDescription()
          This class sometimes provides a list of value descriptions.
 C instantiateClass(Parameterization config)
          Returns a new instance for the value (i.e., the class name) of this class parameter.
protected  Class<? extends C> parseValue(Object obj)
          Parse a given value into the destination type.
 String restrictionString()
          Provides a description string listing all classes for the given superclass or interface as specified in the properties.
 boolean validate(Class<? extends C> obj)
          Checks if the given parameter value is valid for this ClassParameter.
 
Methods inherited from class de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter
addConstraint, getDefaultValue, getFullDescription, getGivenValue, getName, getOptionID, getShortDescription, getValue, hasDefaultValue, isDefined, isOptional, isValid, setDefaultValue, setOptional, setShortDescription, setValue, setValueInternal, tookDefaultValue, tryDefaultValue, useDefaultValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FACTORY_POSTFIX

public static final String FACTORY_POSTFIX
See Also:
Constant Field Values

restrictionClass

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

Constructor Detail

ClassParameter

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

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)
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
Method Detail

parseValue

protected Class<? extends C> parseValue(Object obj)
                                 throws ParameterException
Parse a given value into the destination type.

Specified by:
parseValue in class Parameter<Class<?>,Class<? extends C>>
Parameters:
obj - Object to parse (may be a string representation!)
Returns:
Parsed object
Throws:
ParameterException - when the object cannot be parsed.

validate

public boolean validate(Class<? extends C> obj)
                 throws ParameterException
Checks if the given parameter value is valid for this ClassParameter. If not a parameter exception is thrown.

Overrides:
validate in class Parameter<Class<?>,Class<? extends C>>
Parameters:
obj - Object to validate
Returns:
true iff the object is valid for this parameter.
Throws:
ParameterException - when the object is not valid.

getSyntax

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

Specified by:
getSyntax in class Parameter<Class<?>,Class<? extends C>>
Returns:
"<class>"

hasValuesDescription

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

Overrides:
hasValuesDescription in class Parameter<Class<?>,Class<? extends C>>
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<Class<?>,Class<? extends C>>
Returns:
String explaining valid values (e.g. a class list)
See Also:
Parameter.getValuesDescription()

getValueAsString

public String getValueAsString()
Description copied from class: Parameter
Get the value as string. May return null

Specified by:
getValueAsString in class Parameter<Class<?>,Class<? extends C>>
Returns:
Value as string

instantiateClass

public C instantiateClass(Parameterization config)
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.

Parameters:
config - Parameterization to use (if Parameterizable))
Returns:
a new instance for the value of this class parameter

getRestrictionClass

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

Returns:
the restriction class of this class parameter.

getKnownImplementations

public IterableIterator<Class<?>> getKnownImplementations()
Get an iterator over all known implementations of the class restriction.

Returns:
Iterable and Iterator object

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.

restrictionString

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

Returns:
a description string listing all classes for the given superclass or interface as specified in the properties

canonicalClassName

public static String canonicalClassName(Class<?> c,
                                        Package pkg,
                                        String postfix)
Get the "simple" form of a class name.

Parameters:
c - Class
pkg - Package
postfix - Postfix to strip
Returns:
Simplified class name

canonicalClassName

public static String canonicalClassName(Class<?> c,
                                        Class<?> parent)
Get the "simple" form of a class name.

Parameters:
c - Class name
parent - Parent/restriction class (to get package name to strip)
Returns:
Simplified class name.

getDefaultValueAsString

public String getDefaultValueAsString()
Description copied from class: Parameter
Get the default value as string.

Overrides:
getDefaultValueAsString in class Parameter<Class<?>,Class<? extends C>>
Returns:
default value

Release 0.4.0 (2011-09-20_1324)