
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.
|
void |
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 void setDefaultValue(T defaultValue)
ParametersetDefaultValue in interface Parameter<T>defaultValue - default value of this parameterpublic boolean hasDefaultValue()
ParameterhasDefaultValue in interface Parameter<T>public void useDefaultValue()
ParameteruseDefaultValue in interface Parameter<T>public boolean tryDefaultValue()
throws UnspecifiedParameterException
ParametertryDefaultValue 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)
ParametersetOptional in interface Parameter<T>opt - true if this parameter is optional, false otherwisepublic boolean isOptional()
ParameterisOptional in interface Parameter<T>public boolean tookDefaultValue()
ParametertookDefaultValue in interface Parameter<T>public boolean isDefined()
Parameterpublic T getDefaultValue()
ParametergetDefaultValue in interface Parameter<T>public boolean hasValuesDescription()
ParameterhasValuesDescription in interface Parameter<T>public String getValuesDescription()
ParametergetValuesDescription in interface Parameter<T>public String getFullDescription()
ParametergetFullDescription in interface Parameter<T>protected boolean validate(T obj) throws ParameterException
obj - Object to validateParameterException - when the object is not valid.public OptionID getOptionID()
ParametergetOptionID in interface Parameter<T>public String getName()
Parameterpublic String getShortDescription()
ParametergetShortDescription in interface Parameter<T>public void setShortDescription(String description)
ParametersetShortDescription in interface Parameter<T>description - the short description to be setpublic void setValue(Object obj) throws ParameterException
ParametersetValue 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()
ParameterParameterization.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()
ParameternullgetGivenValue in interface Parameter<T>public final boolean isValid(Object obj) throws ParameterException
ParameterisValid 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()
ParameterIntParameter
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()
ParameternullgetValueAsString in interface Parameter<T>public String getDefaultValueAsString()
ParametergetDefaultValueAsString in interface Parameter<T>public THIS addConstraint(ParameterConstraint<? super T> constraint)
ParameteraddConstraint in interface Parameter<T>constraint - Constraint to add.