Class AbstractParameter<P extends AbstractParameter<P,T>,T>
- java.lang.Object
-
- elki.utilities.optionhandling.parameters.AbstractParameter<P,T>
-
- Type Parameters:
P- type self-referenceT- the type of a possible value (i.e., the type of the option)
- All Implemented Interfaces:
Parameter<T>
- Direct Known Subclasses:
ClassParameter,EnumParameter,FileParameter,Flag,IntGeneratorParameter,ListParameter,NumberParameter,PatternParameter,RandomParameter,StringParameter
public abstract class AbstractParameter<P extends AbstractParameter<P,T>,T> extends java.lang.Object implements Parameter<T>
Abstract class for specifying a parameter.A parameter is defined as an option having a specific value.
See the
elki.utilities.optionhandlingpackage for documentation!- Since:
- 0.1
- Author:
- Steffi Wanka, Erich Schubert
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<ParameterConstraint<? super T>>constraintsHolds parameter constraints for this parameter.protected TdefaultValueThe default value of the parameter (may be null).private booleandefaultValueTakenWhether the default value of this parameter was used.protected TgivenValueThe value last passed to this option.protected booleanoptionalParameterSpecifies if this parameter is an optional parameter.protected OptionIDoptionidThe option name.private TvalueThe value of this option.
-
Constructor Summary
Constructors Constructor Description AbstractParameter(OptionID optionID)Constructs a parameter with the given optionID, and constraints.AbstractParameter(OptionID optionID, T defaultValue)Constructs a parameter with the given optionID, constraints, and default value.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description PaddConstraint(ParameterConstraint<? super T> constraint)Add an additional constraint.java.lang.StringBuilderdescribeValues(java.lang.StringBuilder description)Describe the valid values.java.util.List<ParameterConstraint<? super T>>getConstraints()Get the parameter constraints.TgetDefaultValue()Returns the default value of the parameter.java.lang.StringgetDefaultValueAsString()Get the default value as string.OptionIDgetOptionID()Return the OptionID of this option.TgetValue()Returns the value of the option.booleanhasDefaultValue()Checks if this parameter has a default value.booleanisDefined()Returns true if the value of the option is defined, false otherwise.booleanisOptional()Checks if this parameter is an optional parameter.booleanisValid(java.lang.Object obj)Checks if the given argument is valid for this option.protected abstract TparseValue(java.lang.Object obj)Parse a given value into the destination type.PsetDefaultValue(T defaultValue)Sets the default value of this parameter.PsetOptional(boolean opt)Specifies if this parameter is an optional parameter.voidsetValue(java.lang.Object obj)Sets the value of the option.protected voidsetValueInternal(T val)Internal setter for the value.booleantookDefaultValue()Checks if the default value of this parameter was taken as the actual parameter value.booleantryDefaultValue()Handle default values for a parameter.protected booleanvalidate(T obj)Validate a value after parsing (e.g., do constraint checks!)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface elki.utilities.optionhandling.parameters.Parameter
getSyntax, getValueAsString
-
-
-
-
Field Detail
-
optionid
protected final OptionID optionid
The option name.
-
defaultValue
protected T defaultValue
The default value of the parameter (may be null).
-
defaultValueTaken
private boolean defaultValueTaken
Whether the default value of this parameter was used.
-
optionalParameter
protected boolean optionalParameter
Specifies if this parameter is an optional parameter.
-
constraints
protected java.util.List<ParameterConstraint<? super T>> constraints
Holds parameter constraints for this parameter.
-
givenValue
protected T givenValue
The value last passed to this option.
-
value
private T value
The value of this option.
-
-
Constructor Detail
-
AbstractParameter
public AbstractParameter(OptionID optionID, T defaultValue)
Constructs a parameter with the given optionID, constraints, and default value.- Parameters:
optionID- the unique id of this parameterdefaultValue- the default value of this parameter (may be null)
-
AbstractParameter
public AbstractParameter(OptionID optionID)
Constructs a parameter with the given optionID, and constraints.- Parameters:
optionID- the unique id of this parameter
-
-
Method Detail
-
setDefaultValue
public P setDefaultValue(T defaultValue)
Description copied from interface:ParameterSets the default value of this parameter.- Specified by:
setDefaultValuein interfaceParameter<P extends AbstractParameter<P,T>>- Parameters:
defaultValue- default value of this parameter- Returns:
- the parameter itself, for chaining
-
hasDefaultValue
public boolean hasDefaultValue()
Description copied from interface:ParameterChecks if this parameter has a default value.- Specified by:
hasDefaultValuein interfaceParameter<P extends AbstractParameter<P,T>>- Returns:
- true, if this parameter has a default value, false otherwise
-
tryDefaultValue
public boolean tryDefaultValue() throws UnspecifiedParameterExceptionDescription copied from interface:ParameterHandle default values for a parameter.- Specified by:
tryDefaultValuein interfaceParameter<P extends AbstractParameter<P,T>>- Returns:
- Return code:
trueif it has a default value,falseif it is optional without a default value. Exception if it is a required parameter! - Throws:
UnspecifiedParameterException- If the parameter requires a value
-
setOptional
public P setOptional(boolean opt)
Description copied from interface:ParameterSpecifies if this parameter is an optional parameter.- Specified by:
setOptionalin interfaceParameter<P extends AbstractParameter<P,T>>- Parameters:
opt- true if this parameter is optional, false otherwise- Returns:
- the parameter itself, for chaining
-
isOptional
public boolean isOptional()
Description copied from interface:ParameterChecks if this parameter is an optional parameter.- Specified by:
isOptionalin interfaceParameter<P extends AbstractParameter<P,T>>- Returns:
- true if this parameter is optional, false otherwise
-
tookDefaultValue
public boolean tookDefaultValue()
Description copied from interface:ParameterChecks if the default value of this parameter was taken as the actual parameter value.- Specified by:
tookDefaultValuein interfaceParameter<P extends AbstractParameter<P,T>>- Returns:
- true, if the default value was taken as actual parameter value, false otherwise
-
isDefined
public boolean isDefined()
Description copied from interface:ParameterReturns true if the value of the option is defined, false otherwise.
-
getDefaultValue
public T getDefaultValue()
Description copied from interface:ParameterReturns the default value of the parameter.If the parameter has no default value, the method returns null.
- Specified by:
getDefaultValuein interfaceParameter<P extends AbstractParameter<P,T>>- Returns:
- the default value of the parameter, null if the parameter has no default value.
-
describeValues
public java.lang.StringBuilder describeValues(java.lang.StringBuilder description)
Description copied from interface:ParameterDescribe the valid values.- Specified by:
describeValuesin interfaceParameter<P extends AbstractParameter<P,T>>- Parameters:
description- Buffer to append to- Returns:
- Buffer
-
validate
protected boolean validate(T obj) throws ParameterException
Validate a value after parsing (e.g., do constraint checks!)- Parameters:
obj- Object to validate- Returns:
- true iff the object is valid for this parameter.
- Throws:
ParameterException- when the object is not valid.
-
getOptionID
public OptionID getOptionID()
Description copied from interface:ParameterReturn the OptionID of this option.- Specified by:
getOptionIDin interfaceParameter<P extends AbstractParameter<P,T>>- Returns:
- Option ID
-
setValue
public void setValue(java.lang.Object obj) throws ParameterExceptionDescription copied from interface:ParameterSets the value of the option.- Specified by:
setValuein interfaceParameter<P extends AbstractParameter<P,T>>- Parameters:
obj- the option's value to be set- Throws:
ParameterException- if the given value is not a valid value for this option.
-
setValueInternal
protected void setValueInternal(T val)
Internal setter for the value.- Parameters:
val- Value
-
getValue
public final T getValue()
Description copied from interface:ParameterReturns the value of the option.You should use either
Parameterization.grab(elki.utilities.optionhandling.parameters.Parameter<?>)orParameter.isDefined()to test if getValue() will return a well-defined value.
-
isValid
public final boolean isValid(java.lang.Object obj) throws ParameterExceptionDescription copied from interface:ParameterChecks if the given argument is valid for this option.- Specified by:
isValidin interfaceParameter<P extends AbstractParameter<P,T>>- Parameters:
obj- option value to be checked- Returns:
- true, if the given value is valid for this option
- Throws:
ParameterException- if the given value is not a valid value for this option.
-
parseValue
protected abstract T parseValue(java.lang.Object obj) throws ParameterException
Parse a given value into the destination type.- Parameters:
obj- Object to parse (may be a string representation!)- Returns:
- Parsed object
- Throws:
ParameterException- when the object cannot be parsed.
-
getDefaultValueAsString
public java.lang.String getDefaultValueAsString()
Description copied from interface:ParameterGet the default value as string.- Specified by:
getDefaultValueAsStringin interfaceParameter<P extends AbstractParameter<P,T>>- Returns:
- default value
-
addConstraint
public P addConstraint(ParameterConstraint<? super T> constraint)
Description copied from interface:ParameterAdd an additional constraint.- Specified by:
addConstraintin interfaceParameter<P extends AbstractParameter<P,T>>- Parameters:
constraint- Constraint to add.- Returns:
- the parameter itself, for chaining
-
getConstraints
public java.util.List<ParameterConstraint<? super T>> getConstraints()
Description copied from interface:ParameterGet the parameter constraints.- Specified by:
getConstraintsin interfaceParameter<P extends AbstractParameter<P,T>>- Returns:
- Parameter constraints
-
-