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 java.lang.Object implements Parameter<T>
de.lmu.ifi.dbs.elki.utilities.optionhandling
package for
documentation!Modifier and Type | Field and Description |
---|---|
protected java.util.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 java.lang.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.
|
java.lang.StringBuilder |
describeValues(java.lang.StringBuilder description)
Describe the valid values.
|
java.util.List<ParameterConstraint<? super T>> |
getConstraints()
Get the parameter constraints.
|
T |
getDefaultValue()
Returns the default value of the parameter.
|
java.lang.String |
getDefaultValueAsString()
Get the default value as string.
|
OptionID |
getOptionID()
Return the OptionID of this option.
|
java.lang.String |
getShortDescription()
Returns the short description of the option.
|
abstract java.lang.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 java.lang.String |
getValueAsString()
Get the value as string.
|
boolean |
hasDefaultValue()
Checks if this parameter has a default value.
|
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(java.lang.Object obj)
Checks if the given argument is valid for this option.
|
protected abstract T |
parseValue(java.lang.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(java.lang.String description)
Sets the short description of the option.
|
void |
setValue(java.lang.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.
|
protected boolean |
validate(T obj)
Validate a value after parsing (e.g. do constraint checks!)
|
protected T defaultValue
private boolean defaultValueTaken
protected boolean optionalParameter
protected java.util.List<ParameterConstraint<? super T>> constraints
protected final OptionID optionid
protected java.lang.String shortDescription
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 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
If the parameter has no default value, the method returns null.
getDefaultValue
in interface Parameter<T>
public java.lang.StringBuilder describeValues(java.lang.StringBuilder description)
Parameter
describeValues
in interface Parameter<T>
description
- Buffer to append toprotected 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 java.lang.String getShortDescription()
Parameter
getShortDescription
in interface Parameter<T>
public void setShortDescription(java.lang.String description)
Parameter
setShortDescription
in interface Parameter<T>
description
- the short description to be setpublic void setValue(java.lang.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 final boolean isValid(java.lang.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 java.lang.String getSyntax()
Parameter
IntParameter
should return <int>
).protected abstract T parseValue(java.lang.Object obj) throws ParameterException
obj
- Object to parse (may be a string representation!)ParameterException
- when the object cannot be parsed.public abstract java.lang.String getValueAsString()
Parameter
null
getValueAsString
in interface Parameter<T>
public java.lang.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.public java.util.List<ParameterConstraint<? super T>> getConstraints()
Parameter
getConstraints
in interface Parameter<T>
Copyright © 2019 ELKI Development Team. License information.