Class ObjectParameter<C>
- java.lang.Object
-
- elki.utilities.optionhandling.parameters.AbstractParameter<ClassParameter<C>,java.lang.Class<? extends C>>
-
- elki.utilities.optionhandling.parameters.ClassParameter<C>
-
- elki.utilities.optionhandling.parameters.ObjectParameter<C>
-
- Type Parameters:
C
- Class type
- All Implemented Interfaces:
Parameter<java.lang.Class<? extends C>>
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.
- Since:
- 0.3
- Author:
- Steffi Wanka, Erich Schubert
-
-
Field Summary
Fields Modifier and Type Field Description private C
instance
The instance to use.-
Fields inherited from class elki.utilities.optionhandling.parameters.ClassParameter
restrictionClass
-
Fields inherited from class elki.utilities.optionhandling.parameters.AbstractParameter
constraints, defaultValue, givenValue, optionalParameter, optionid
-
-
Constructor Summary
Constructors Constructor Description ObjectParameter(OptionID optionID, java.lang.Class<?> restrictionClass)
Constructs a class parameter with the given optionID, and restriction class.ObjectParameter(OptionID optionID, java.lang.Class<?> restrictionClass, java.lang.Class<?> defaultValue)
Constructs a class parameter with the given optionID, restriction class, and default value.ObjectParameter(OptionID optionID, java.lang.Class<?> restrictionClass, T defaultValue)
Constructs a class parameter with the given optionID, restriction class, and default value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.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 java.lang.Class<? extends C>
parseValue(java.lang.Object obj)
Parse a given value into the destination type.ObjectParameter<C>
setOptional(boolean opt)
Specifies if this parameter is an optional parameter.void
setValue(java.lang.Object obj)
Sets the value of the option.-
Methods inherited from class elki.utilities.optionhandling.parameters.ClassParameter
canonicalClassName, canonicalClassName, describeImplementations, describeValues, getDefaultValueAsString, getKnownImplementations, getRestrictionClass, getValueAsString, grab, validate
-
Methods inherited from class elki.utilities.optionhandling.parameters.AbstractParameter
addConstraint, getConstraints, getDefaultValue, getOptionID, getValue, hasDefaultValue, isDefined, isOptional, isValid, setDefaultValue, setValueInternal, tookDefaultValue, tryDefaultValue
-
-
-
-
Field Detail
-
instance
private C instance
The instance to use.
-
-
Constructor Detail
-
ObjectParameter
public ObjectParameter(OptionID optionID, java.lang.Class<?> restrictionClass, java.lang.Class<?> defaultValue)
Constructs a class parameter with the given optionID, restriction class, and default value.- Parameters:
optionID
- the unique id of the optionrestrictionClass
- the restriction class of this class parameterdefaultValue
- the default value of this class parameter
-
ObjectParameter
public ObjectParameter(OptionID optionID, java.lang.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 optionrestrictionClass
- the restriction class of this class parameterdefaultValue
- the default instance of this class parameter
-
ObjectParameter
public ObjectParameter(OptionID optionID, java.lang.Class<?> restrictionClass)
Constructs a class parameter with the given optionID, and restriction class.- Parameters:
optionID
- the unique id of the optionrestrictionClass
- the restriction class of this class parameter
-
-
Method Detail
-
parseValue
protected java.lang.Class<? extends C> parseValue(java.lang.Object obj) throws ParameterException
Description copied from class:AbstractParameter
Parse a given value into the destination type.- Overrides:
parseValue
in classClassParameter<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(java.lang.Object obj) throws ParameterException
Description copied from interface:Parameter
Sets the value of the option.- Specified by:
setValue
in interfaceParameter<C>
- Overrides:
setValue
in classAbstractParameter<ClassParameter<C>,java.lang.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.
-
setOptional
public ObjectParameter<C> setOptional(boolean opt)
Description copied from interface:Parameter
Specifies if this parameter is an optional parameter.- Specified by:
setOptional
in interfaceParameter<C>
- Overrides:
setOptional
in classAbstractParameter<ClassParameter<C>,java.lang.Class<? extends C>>
- Parameters:
opt
- true if this parameter is optional, false otherwise- Returns:
- the parameter itself, for chaining
-
getSyntax
public java.lang.String getSyntax()
Returns a string representation of the parameter's type.
-
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.F
- Overrides:
instantiateClass
in classClassParameter<C>
- Parameters:
config
- Parameterization- Returns:
- a new instance for the value of this class parameter
-
-