|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter<S,T>
T
- the type of a possible value (i.e., the type of the option)S
- the supertype for constraintspublic abstract class Parameter<S,T extends S>
Abstract class for specifying a parameter.
A parameter is defined as an option having a specific value.
See the de.lmu.ifi.dbs.elki.utilities.optionhandling
package for
documentation!
Field Summary | |
---|---|
protected List<ParameterConstraint<S>> |
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 Summary | |
---|---|
Parameter(OptionID optionID)
Constructs a parameter with the given optionID. |
|
Parameter(OptionID optionID,
boolean optional)
Constructs a parameter with the given optionID and optional flag. |
|
Parameter(OptionID optionID,
List<ParameterConstraint<S>> constraints)
Constructs a parameter with the given optionID, and constraints. |
|
Parameter(OptionID optionID,
List<ParameterConstraint<S>> constraints,
boolean optional)
Constructs a parameter with the given optionID, constraints, and optional flag. |
|
Parameter(OptionID optionID,
List<ParameterConstraint<S>> constraints,
T defaultValue)
Constructs a parameter with the given optionID, constraints, and default value. |
|
Parameter(OptionID optionID,
ParameterConstraint<S> constraint)
Constructs a parameter with the given optionID, and constraint. |
|
Parameter(OptionID optionID,
ParameterConstraint<S> constraint,
boolean optional)
Constructs a parameter with the given optionID, constraint, and optional flag. |
|
Parameter(OptionID optionID,
ParameterConstraint<S> constraint,
T defaultValue)
Constructs a parameter with the given optionID, constraint, and default value. |
|
Parameter(OptionID optionID,
T defaultValue)
Constructs a parameter with the given optionID and default value. |
Method Summary | ||
---|---|---|
void |
addConstraint(ParameterConstraint<S> 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. |
|
private static
|
makeConstraintsVector(ParameterConstraint<S> constraint)
Wrap a single constraint into a vector of constraints. |
|
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. |
|
void |
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!) |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected T extends S defaultValue
private boolean defaultValueTaken
protected boolean optionalParameter
protected final List<ParameterConstraint<S>> constraints
protected final OptionID optionid
protected String shortDescription
getFullDescription()
protected T extends S givenValue
private T extends S value
Constructor Detail |
---|
public Parameter(OptionID optionID, List<ParameterConstraint<S>> constraints, T defaultValue)
optionID
- the unique id of this parameterconstraints
- the constraints of this parameter, may be empty if there
are no constraintsdefaultValue
- the default value of this parameter (may be null)public Parameter(OptionID optionID, List<ParameterConstraint<S>> constraints, boolean optional)
optionID
- the unique id of this parameterconstraints
- the constraints of this parameter, may be empty if there
are no constraintsoptional
- specifies if this parameter is an optional parameterpublic Parameter(OptionID optionID, List<ParameterConstraint<S>> constraints)
optionID
- the unique id of this parameterconstraints
- the constraints of this parameter, may be empty if there
are no constraintspublic Parameter(OptionID optionID, ParameterConstraint<S> constraint, T defaultValue)
optionID
- the unique id of this parameterconstraint
- the constraint of this parameterdefaultValue
- the default value of this parameter (may be null)public Parameter(OptionID optionID, ParameterConstraint<S> constraint, boolean optional)
optionID
- the unique id of this parameterconstraint
- the constraint of this parameteroptional
- specifies if this parameter is an optional parameterpublic Parameter(OptionID optionID, ParameterConstraint<S> constraint)
optionID
- the unique id of this parameterconstraint
- the constraint of this parameterpublic Parameter(OptionID optionID, T defaultValue)
optionID
- the unique id of the optiondefaultValue
- default value.public Parameter(OptionID optionID, boolean optional)
optionID
- the unique id of the optionoptional
- optional flagpublic Parameter(OptionID optionID)
optionID
- the unique id of the optionMethod Detail |
---|
private static <S> List<ParameterConstraint<S>> makeConstraintsVector(ParameterConstraint<S> constraint)
S
- Typeconstraint
- Constraint, may be null
public void setDefaultValue(T defaultValue)
defaultValue
- default value of this parameterpublic boolean hasDefaultValue()
public void useDefaultValue()
public boolean tryDefaultValue() throws UnspecifiedParameterException
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 void setOptional(boolean opt)
opt
- true if this parameter is optional, false otherwisepublic boolean isOptional()
public boolean tookDefaultValue()
public boolean isDefined()
public T getDefaultValue()
public boolean hasValuesDescription()
public String getValuesDescription()
public String getFullDescription()
protected boolean validate(T obj) throws ParameterException
obj
- Object to validate
ParameterException
- when the object is not valid.public OptionID getOptionID()
public String getName()
public String getShortDescription()
public void setShortDescription(String description)
description
- the short description to be setpublic void setValue(Object obj) throws ParameterException
obj
- the option's value to be set
ParameterException
- if the given value is not a valid value for this
option.protected final void setValueInternal(T val)
val
- Valuepublic final T getValue()
isDefined()
to test
if getValue() will return a well-defined value.
public Object getGivenValue()
null
public final boolean isValid(Object obj) throws ParameterException
obj
- option value to be checked
ParameterException
- if the given value is not a valid value for this
option.public abstract String getSyntax()
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()
null
public String getDefaultValueAsString()
public void addConstraint(ParameterConstraint<S> constraint)
constraint
- Constraint to add.
|
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |