Class ClassParameter<C>
- java.lang.Object
-
- elki.utilities.optionhandling.parameters.AbstractParameter<ClassParameter<C>,java.lang.Class<? extends C>>
-
- elki.utilities.optionhandling.parameters.ClassParameter<C>
-
- Type Parameters:
C- Class type
- All Implemented Interfaces:
Parameter<java.lang.Class<? extends C>>
- Direct Known Subclasses:
ObjectParameter
public class ClassParameter<C> extends AbstractParameter<ClassParameter<C>,java.lang.Class<? extends C>>
Parameter class for a parameter specifying a class name.- Since:
- 0.1
- Author:
- Steffi Wanka, Erich Schubert
-
-
Field Summary
Fields Modifier and Type Field Description private static LoggingLOGThe class logger.protected java.lang.Class<C>restrictionClassThe restriction class for this class parameter.-
Fields inherited from class elki.utilities.optionhandling.parameters.AbstractParameter
constraints, defaultValue, givenValue, optionalParameter, optionid
-
-
Constructor Summary
Constructors Constructor Description ClassParameter(OptionID optionID, java.lang.Class<?> restrictionClass)Constructs a class parameter with the given optionID, and restriction class.ClassParameter(OptionID optionID, java.lang.Class<?> restrictionClass, java.lang.Class<?> defaultValue)Constructs a class parameter with the given optionID, restriction class, and default value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.StringcanonicalClassName(java.lang.Class<?> c, java.lang.Class<?> parent)Get the "simple" form of a class name.static java.lang.StringcanonicalClassName(java.lang.Class<?> c, java.lang.Package pkg)Get the "simple" form of a class name.protected static java.lang.StringBuilderdescribeImplementations(java.lang.StringBuilder buf, java.lang.Class<?> restrictionClass, java.util.List<java.lang.Class<?>> imp)Print the available implementations.java.lang.StringBuilderdescribeValues(java.lang.StringBuilder buf)Describe the valid values.java.lang.StringgetDefaultValueAsString()Get the default value as string.java.util.List<java.lang.Class<?>>getKnownImplementations()Get an iterator over all known implementations of the class restriction.java.lang.Class<C>getRestrictionClass()Returns the restriction class of this class parameter.java.lang.StringgetSyntax()Returns a string representation of the parameter's type.java.lang.StringgetValueAsString()Get the value as string.booleangrab(Parameterization config, java.util.function.Consumer<C> consumer)Get the parameter.CinstantiateClass(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.booleanvalidate(java.lang.Class<? extends C> obj)Checks if the given parameter value is valid for this ClassParameter.-
Methods inherited from class elki.utilities.optionhandling.parameters.AbstractParameter
addConstraint, getConstraints, getDefaultValue, getOptionID, getValue, hasDefaultValue, isDefined, isOptional, isValid, setDefaultValue, setOptional, setValue, setValueInternal, tookDefaultValue, tryDefaultValue
-
-
-
-
Constructor Detail
-
ClassParameter
public ClassParameter(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
-
ClassParameter
public ClassParameter(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:AbstractParameterParse a given value into the destination type.- Specified by:
parseValuein classAbstractParameter<ClassParameter<C>,java.lang.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(java.lang.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:
validatein classAbstractParameter<ClassParameter<C>,java.lang.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 java.lang.String getSyntax()
Returns a string representation of the parameter's type.- Returns:
- "<class>"
-
describeValues
public java.lang.StringBuilder describeValues(java.lang.StringBuilder buf)
Description copied from interface:ParameterDescribe the valid values.- Specified by:
describeValuesin interfaceParameter<C>- Overrides:
describeValuesin classAbstractParameter<ClassParameter<C>,java.lang.Class<? extends C>>- Parameters:
buf- Buffer to append to- Returns:
- Buffer
-
describeImplementations
protected static java.lang.StringBuilder describeImplementations(java.lang.StringBuilder buf, java.lang.Class<?> restrictionClass, java.util.List<java.lang.Class<?>> imp)Print the available implementations.- Parameters:
buf- Output bufferrestrictionClass- Restriction classimp- Implementations- Returns:
- the output buffer, for chaining
-
getValueAsString
public java.lang.String getValueAsString()
Description copied from interface:ParameterGet the value as string. May returnnull- Returns:
- Value as string
-
getDefaultValueAsString
public java.lang.String getDefaultValueAsString()
Description copied from interface:ParameterGet the default value as string.- Specified by:
getDefaultValueAsStringin interfaceParameter<C>- Overrides:
getDefaultValueAsStringin classAbstractParameter<ClassParameter<C>,java.lang.Class<? extends C>>- Returns:
- default value
-
canonicalClassName
public static java.lang.String canonicalClassName(java.lang.Class<?> c, java.lang.Package pkg)Get the "simple" form of a class name.- Parameters:
c- Classpkg- Package- Returns:
- Simplified class name
-
canonicalClassName
public static java.lang.String canonicalClassName(java.lang.Class<?> c, java.lang.Class<?> parent)Get the "simple" form of a class name.- Parameters:
c- Class nameparent- Parent/restriction class (to get package name to strip)- Returns:
- Simplified class name.
-
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 java.lang.Class<C> getRestrictionClass()
Returns the restriction class of this class parameter.- Returns:
- the restriction class of this class parameter.
-
getKnownImplementations
public java.util.List<java.lang.Class<?>> getKnownImplementations()
Get an iterator over all known implementations of the class restriction.- Returns:
- List object
-
grab
public boolean grab(Parameterization config, java.util.function.Consumer<C> consumer)
Get the parameter.- Parameters:
config- Parameterizationconsumer- Output consumer- Returns:
trueif valid;
-
-