Class ClassListParameter<C>
- java.lang.Object
-
- elki.utilities.optionhandling.parameters.AbstractParameter<P,T>
-
- elki.utilities.optionhandling.parameters.ListParameter<ClassListParameter<C>,java.util.List<java.lang.Class<? extends C>>>
-
- elki.utilities.optionhandling.parameters.ClassListParameter<C>
-
- Type Parameters:
C
- Class type
- All Implemented Interfaces:
Parameter<java.util.List<java.lang.Class<? extends C>>>
- Direct Known Subclasses:
ObjectListParameter
public class ClassListParameter<C> extends ListParameter<ClassListParameter<C>,java.util.List<java.lang.Class<? extends C>>>
Parameter class for a parameter specifying a list of class names.- Since:
- 0.1
- Author:
- Steffi Wanka, Erich Schubert
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Class<C>
restrictionClass
The restriction class for the list of class names.-
Fields inherited from class elki.utilities.optionhandling.parameters.ListParameter
LIST_SEP, SPLIT, VECTOR_SEP, VECTOR_SPLIT
-
Fields inherited from class elki.utilities.optionhandling.parameters.AbstractParameter
constraints, defaultValue, givenValue, optionalParameter, optionid
-
-
Constructor Summary
Constructors Constructor Description ClassListParameter(OptionID optionID, java.lang.Class<?> restrictionClass)
Constructs a class list parameter with the given optionID and restriction class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringBuilder
describeValues(java.lang.StringBuilder buf)
Describe the valid values.protected java.lang.String
formatValue(java.util.List<java.lang.Class<? extends C>> val)
Format as string.java.lang.String
getDefaultValueAsString()
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.String
getSyntax()
Returns a string representation of the parameter's type.java.lang.String
getValueAsString()
Get the value as string.boolean
grab(Parameterization config, java.util.function.Consumer<java.util.List<? extends C>> consumer)
Get the parameter.java.util.List<C>
instantiateClasses(Parameterization config)
Returns a list of new instances for the value (i.e., the class name) of this class list parameter.protected java.util.List<java.lang.Class<? extends C>>
parseValue(java.lang.Object obj)
Parse a given value into the destination type.int
size()
Size of the list.protected boolean
validate(java.util.List<java.lang.Class<? extends C>> obj)
Validate a value after parsing (e.g., do constraint checks!)-
Methods inherited from class elki.utilities.optionhandling.parameters.AbstractParameter
addConstraint, getConstraints, getDefaultValue, getOptionID, getValue, hasDefaultValue, isDefined, isOptional, isValid, setDefaultValue, setOptional, setValue, setValueInternal, tookDefaultValue, tryDefaultValue
-
-
-
-
Field Detail
-
restrictionClass
protected java.lang.Class<C> restrictionClass
The restriction class for the list of class names.
-
-
Constructor Detail
-
ClassListParameter
public ClassListParameter(OptionID optionID, java.lang.Class<?> restrictionClass)
Constructs a class list parameter with the given optionID and restriction class.- Parameters:
optionID
- the unique id of this parameterrestrictionClass
- the restriction class of the list of class names
-
-
Method Detail
-
getValueAsString
public java.lang.String getValueAsString()
Description copied from interface:Parameter
Get the value as string. May returnnull
- Returns:
- Value as string
-
getDefaultValueAsString
public java.lang.String getDefaultValueAsString()
Description copied from interface:Parameter
Get the default value as string.- Specified by:
getDefaultValueAsString
in interfaceParameter<C>
- Overrides:
getDefaultValueAsString
in classAbstractParameter<ClassListParameter<C>,java.util.List<java.lang.Class<? extends C>>>
- Returns:
- default value
-
formatValue
protected java.lang.String formatValue(java.util.List<java.lang.Class<? extends C>> val)
Format as string.- Parameters:
val
- Value to format- Returns:
- String
-
parseValue
protected java.util.List<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.- Specified by:
parseValue
in classAbstractParameter<ClassListParameter<C>,java.util.List<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
protected boolean validate(java.util.List<java.lang.Class<? extends C>> obj) throws ParameterException
Description copied from class:AbstractParameter
Validate a value after parsing (e.g., do constraint checks!)- Overrides:
validate
in classAbstractParameter<ClassListParameter<C>,java.util.List<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.
-
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
-
getSyntax
public java.lang.String getSyntax()
Returns a string representation of the parameter's type.- Returns:
- "<class_1,...,class_n>"
-
instantiateClasses
public java.util.List<C> instantiateClasses(Parameterization config)
Returns a list of new instances for the value (i.e., the class name) of this class list parameter. The instances have the type of the restriction class of this class list parameter.If the Class for the class names 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 list of new instances for the value of this class list parameter
-
describeValues
public java.lang.StringBuilder describeValues(java.lang.StringBuilder buf)
Description copied from interface:Parameter
Describe the valid values.- Specified by:
describeValues
in interfaceParameter<C>
- Overrides:
describeValues
in classAbstractParameter<ClassListParameter<C>,java.util.List<java.lang.Class<? extends C>>>
- Parameters:
buf
- Buffer to append to- Returns:
- Buffer
-
size
public int size()
Description copied from class:ListParameter
Size of the list.- Specified by:
size
in classListParameter<ClassListParameter<C>,java.util.List<java.lang.Class<? extends C>>>
- Returns:
- Size
-
grab
public boolean grab(Parameterization config, java.util.function.Consumer<java.util.List<? extends C>> consumer)
Get the parameter.- Parameters:
config
- Parameterizationconsumer
- Output consumer- Returns:
true
if valid
-
-