THIS
- type self-referenceT
- the type of a possible value (i.e., the type of the option)public abstract class AbstractParameter<THIS extends AbstractParameter<THIS,T>,T> extends Object implements Parameter<T>
de.lmu.ifi.dbs.elki.utilities.optionhandling
package for
documentation!Modifier and Type | Field and Description |
---|---|
protected List<ParameterConstraint<? super T>> |
constraints
Holds parameter constraints for this parameter.
|
protected T |
defaultValue
The default value of the parameter (may be null).
|
private boolean |
defaultValueTaken
Specifies if the default value of this parameter was taken as parameter
value.
|
protected T |
givenValue
The value last passed to this option.
|
protected boolean |
optionalParameter
Specifies if this parameter is an optional parameter.
|
protected OptionID |
optionid
The option name.
|
protected String |
shortDescription
The short description of the option.
|
private T |
value
The value of this option.
|
Constructor and Description |
---|
AbstractParameter(OptionID optionID)
Constructs a parameter with the given optionID, and constraints.
|
AbstractParameter(OptionID optionID,
boolean optional)
Constructs a parameter with the given optionID, constraints, and optional
flag.
|
AbstractParameter(OptionID optionID,
T defaultValue)
Constructs a parameter with the given optionID, constraints, and default
value.
|
Modifier and Type | Method and Description |
---|---|
THIS |
addConstraint(ParameterConstraint<? super T> constraint)
Add an additional constraint.
|
T |
getDefaultValue()
Returns the default value of the parameter.
|
String |
getDefaultValueAsString()
Get the default value as string.
|
String |
getFullDescription()
Returns the extended description of the option which includes the option's
type, the short description and the default value (if specified).
|
Object |
getGivenValue()
Get the last given value.
|
String |
getName()
Returns the name of the option.
|
OptionID |
getOptionID()
Return the OptionID of this option.
|
String |
getShortDescription()
Returns the short description of the option.
|
abstract String |
getSyntax()
Returns a string representation of the parameter's type (e.g. an
IntParameter
should return <int> ). |
T |
getValue()
Returns the value of the option.
|
abstract String |
getValueAsString()
Get the value as string.
|
String |
getValuesDescription()
Return a string explaining valid values.
|
boolean |
hasDefaultValue()
Checks if this parameter has a default value.
|
boolean |
hasValuesDescription()
Whether this class has a list of default values.
|
boolean |
isDefined()
Returns true if the value of the option is defined, false otherwise.
|
boolean |
isOptional()
Checks if this parameter is an optional parameter.
|
boolean |
isValid(Object obj)
Checks if the given argument is valid for this option.
|
protected abstract T |
parseValue(Object obj)
Parse a given value into the destination type.
|
THIS |
setDefaultValue(T defaultValue)
Sets the default value of this parameter.
|
THIS |
setOptional(boolean opt)
Specifies if this parameter is an optional parameter.
|
void |
setShortDescription(String description)
Sets the short description of the option.
|
void |
setValue(Object obj)
Sets the value of the option.
|
protected void |
setValueInternal(T val)
Internal setter for the value.
|
boolean |
tookDefaultValue()
Checks if the default value of this parameter was taken as the actual
parameter value.
|
boolean |
tryDefaultValue()
Handle default values for a parameter.
|
void |
useDefaultValue()
Sets the default value of this parameter as the actual value of this
parameter.
|
protected boolean |
validate(T obj)
Validate a value after parsing (e.g. do constrain checks!)
|
protected T defaultValue
private boolean defaultValueTaken
protected boolean optionalParameter
protected List<ParameterConstraint<? super T>> constraints
protected final OptionID optionid
protected String shortDescription
getFullDescription()
protected T givenValue
private T value
public AbstractParameter(OptionID optionID, T defaultValue)
optionID
- the unique id of this parameterdefaultValue
- the default value of this parameter (may be null)public AbstractParameter(OptionID optionID, boolean optional)
optionID
- the unique id of this parameteroptional
- specifies if this parameter is an optional parameterpublic AbstractParameter(OptionID optionID)
optionID
- the unique id of this parameterpublic THIS setDefaultValue(T defaultValue)
Parameter
setDefaultValue
in interface Parameter<T>
defaultValue
- default value of this parameterpublic boolean hasDefaultValue()
Parameter
hasDefaultValue
in interface Parameter<T>
public void useDefaultValue()
Parameter
useDefaultValue
in interface Parameter<T>
public boolean tryDefaultValue() throws UnspecifiedParameterException
Parameter
tryDefaultValue
in interface Parameter<T>
true
if it has a default value, false
if it is optional without a default value. Exception if it is a
required parameter!UnspecifiedParameterException
- If the parameter requires a valuepublic THIS setOptional(boolean opt)
Parameter
setOptional
in interface Parameter<T>
opt
- true if this parameter is optional, false otherwisepublic boolean isOptional()
Parameter
isOptional
in interface Parameter<T>
public boolean tookDefaultValue()
Parameter
tookDefaultValue
in interface Parameter<T>
public boolean isDefined()
Parameter
public T getDefaultValue()
Parameter
getDefaultValue
in interface Parameter<T>
public boolean hasValuesDescription()
Parameter
hasValuesDescription
in interface Parameter<T>
public String getValuesDescription()
Parameter
getValuesDescription
in interface Parameter<T>
public String getFullDescription()
Parameter
getFullDescription
in interface Parameter<T>
protected boolean validate(T obj) throws ParameterException
obj
- Object to validateParameterException
- when the object is not valid.public OptionID getOptionID()
Parameter
getOptionID
in interface Parameter<T>
public String getName()
Parameter
public String getShortDescription()
Parameter
getShortDescription
in interface Parameter<T>
public void setShortDescription(String description)
Parameter
setShortDescription
in interface Parameter<T>
description
- the short description to be setpublic void setValue(Object obj) throws ParameterException
Parameter
setValue
in interface Parameter<T>
obj
- the option's value to be setParameterException
- if the given value is not a valid value for this
option.protected final void setValueInternal(T val)
val
- Valuepublic final T getValue()
Parameter
Parameterization.grab(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter<?>)
or Parameter.isDefined()
to test if getValue() will return a well-defined
value.public Object getGivenValue()
Parameter
null
getGivenValue
in interface Parameter<T>
public final boolean isValid(Object obj) throws ParameterException
Parameter
isValid
in interface Parameter<T>
obj
- option value to be checkedParameterException
- if the given value is not a valid value for this
option.public abstract String getSyntax()
Parameter
IntParameter
should return <int>
).protected abstract T parseValue(Object obj) throws ParameterException
obj
- Object to parse (may be a string representation!)ParameterException
- when the object cannot be parsed.public abstract String getValueAsString()
Parameter
null
getValueAsString
in interface Parameter<T>
public String getDefaultValueAsString()
Parameter
getDefaultValueAsString
in interface Parameter<T>
public THIS addConstraint(ParameterConstraint<? super T> constraint)
Parameter
addConstraint
in interface Parameter<T>
constraint
- Constraint to add.Copyright © 2015 ELKI Development Team, Lehr- und Forschungseinheit für Datenbanksysteme, Ludwig-Maximilians-Universität München. License information.