de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters
Class ObjectParameter<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>
          extended by de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ObjectParameter<C>
Type Parameters:
C - Class type

public class ObjectParameter<C>
extends ClassParameter<C>

Parameter class for a parameter representing a single object. It can be parameterized by giving a class name or class to instantiate, or an existing instance.


Field Summary
private  C instance
          The instance to use.
 
Fields inherited from class de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ClassParameter
FACTORY_POSTFIX, restrictionClass
 
Fields inherited from class de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter
constraints, defaultValue, givenValue, optionalParameter, optionid, shortDescription
 
Constructor Summary
ObjectParameter(OptionID optionID, Class<?> restrictionClass)
          Constructs a class parameter with the given optionID, and restriction class.
ObjectParameter(OptionID optionID, Class<?> restrictionClass, boolean optional)
          Constructs a class parameter with the given optionID, restriction class, and optional flag.
ObjectParameter(OptionID optionID, Class<?> restrictionClass, Class<?> defaultValue)
          Constructs a class parameter with the given optionID, restriction class, and default value.
ObjectParameter(OptionID optionID, Class<?> restrictionClass, T defaultValue)
          Constructs a class parameter with the given optionID, restriction class, and default value.
 
Method Summary
 Object getGivenValue()
          Get the last given value.
 String getSyntax()
          Returns a string representation of the parameter's type.
 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.
 void setValue(Object obj)
          Sets the value of the option.
 
Methods inherited from class de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ClassParameter
canonicalClassName, canonicalClassName, getDefaultValueAsString, getKnownImplementations, getRestrictionClass, getRestrictionClasses, getValueAsString, getValuesDescription, hasValuesDescription, restrictionString, validate
 
Methods inherited from class de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter
addConstraint, getDefaultValue, getFullDescription, getName, getOptionID, getShortDescription, getValue, hasDefaultValue, isDefined, isOptional, isValid, setDefaultValue, setOptional, setShortDescription, setValueInternal, tookDefaultValue, tryDefaultValue, useDefaultValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

private C instance
The instance to use.

Constructor Detail

ObjectParameter

public ObjectParameter(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

ObjectParameter

public ObjectParameter(OptionID optionID,
                       Class<?> restrictionClass,
                       T defaultValue)
Constructs a class parameter with the given optionID, restriction class, and default value.

Type Parameters:
T - default value type, to solve generics problems.
Parameters:
optionID - the unique id of the option
restrictionClass - the restriction class of this class parameter
defaultValue - the default instance of this class parameter

ObjectParameter

public ObjectParameter(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

ObjectParameter

public ObjectParameter(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.

Overrides:
parseValue in class ClassParameter<C>
Parameters:
obj - Object to parse (may be a string representation!)
Returns:
Parsed object
Throws:
ParameterException - when the object cannot be parsed.

setValue

public void setValue(Object obj)
              throws ParameterException
Sets the value of the option.

Overrides:
setValue in class Parameter<Class<?>,Class<? extends C>>
Parameters:
obj - the option's value to be set
Throws:
ParameterException - if the given value is not a valid value for this option.

getSyntax

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

Overrides:
getSyntax in class ClassParameter<C>
Returns:
"<class>"

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.

Overrides:
instantiateClass in class ClassParameter<C>
Parameters:
config - Parameterization
Returns:
a new instance for the value of this class parameter

getGivenValue

public Object getGivenValue()
Get the last given value. May return null

Overrides:
getGivenValue in class Parameter<Class<?>,Class<? extends C>>
Returns:
Given value

Release 0.4.0 (2011-09-20_1324)