de.jstacs.parameters
Class Parameter

java.lang.Object
  extended by de.jstacs.AnnotatedEntity
      extended by de.jstacs.parameters.Parameter
All Implemented Interfaces:
Storable, Cloneable
Direct Known Subclasses:
AbstractSelectionParameter, FileParameter, ParameterSetContainer, RangeParameter, SimpleParameter

public abstract class Parameter
extends AnnotatedEntity
implements Cloneable

Abstract class for a parameter that shall be used as the parameter of some method, constructor, etc. This class provides annotation of the parameter, e.g. a name and a comment, the data type, and additional properties for non-atomic parameters. The intention of the Parameter classes is to link this annotation directly to the parameter values, which could not be achieved by primitive data types.
Parameters should always be embedded into a ParameterSet and then passed to the respective method.

Author:
Jan Grau, Jens Keilwagen
See Also:
ParameterSet

Field Summary
protected  ParameterSet parent
          If this Parameter is enclosed in a ParameterSet, this variable holds a reference to that ParameterSet.
 
Fields inherited from class de.jstacs.AnnotatedEntity
comment, datatype, name
 
Constructor Summary
Parameter(StringBuffer xml)
          The standard constructor for the interface Storable.
Parameter(String name, String comment, DataType type)
          The main constructor which takes the main information of a Parameter.
 
Method Summary
protected  void appendFurtherInfos(StringBuffer buf)
          This method can be used in the method Storable.toXML() to extract further information (name, comment, datatype).
abstract  boolean checkValue(Object value)
          Checks the value for correctness, e.g.
 Parameter clone()
           
protected  void extractFurtherInfos(StringBuffer source)
          This method can be used in the constructor with parameter StringBuffer to extract the further information.
abstract  String getErrorMessage()
          If a value could not be set successfully this method returns the corresponding error message.
 ParameterSet getParent()
          Returns a reference to the ParameterSet enclosing this Parameter.
abstract  boolean hasDefaultOrIsSet()
          Returns true if the parameter either has a default value or the value was set by the user, false otherwise.
abstract  boolean isAtomic()
          Returns true if the parameter is of an atomic data type, false otherwise.
 boolean isComparable(Parameter p)
          This method checks whether the given Parameter is comparable to the current instance, i.e.
abstract  boolean isRequired()
          Returns true if the Parameter is required, false otherwise.
abstract  boolean isSet()
          Returns true if the parameter was set by the user, false otherwise.
abstract  void reset()
          Resets the parameter and its contents to the default values or null if no defaults are given.
abstract  void setDefault(Object defaultValue)
          Sets the default value of the Parameter to defaultValue.
 void setParent(ParameterSet parent)
          Sets the reference of the enclosing ParameterSet of this Parameter to parent.
abstract  void setValue(Object value)
          Sets the value of this Parameter to value.
 
Methods inherited from class de.jstacs.AnnotatedEntity
getComment, getDatatype, getName, getValue, getXMLTag, toXML
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parent

protected ParameterSet parent
If this Parameter is enclosed in a ParameterSet, this variable holds a reference to that ParameterSet.

Constructor Detail

Parameter

public Parameter(String name,
                 String comment,
                 DataType type)
The main constructor which takes the main information of a Parameter.

Parameters:
name - the name of the result
comment - the comment for the result
type - the data type of the result

Parameter

public Parameter(StringBuffer xml)
          throws NonParsableException
The standard constructor for the interface Storable. Creates a new Parameter out of its XML representation.

Parameters:
xml - the XML representation as StringBuffer
Throws:
NonParsableException - if the XML representation is not parsable
See Also:
Storable, extractFurtherInfos(StringBuffer)
Method Detail

isRequired

public abstract boolean isRequired()
Returns true if the Parameter is required, false otherwise.

Returns:
true if the Parameter is required, false otherwise

checkValue

public abstract boolean checkValue(Object value)
Checks the value for correctness, e.g. for numerical parameters this might be checking if the value is within specified bounds.

Parameters:
value - the value to be checked
Returns:
true if the value is valid, false otherwise

setValue

public abstract void setValue(Object value)
                       throws SimpleParameter.IllegalValueException
Sets the value of this Parameter to value.

Parameters:
value - the new value of the Parameter
Throws:
SimpleParameter.IllegalValueException - if the specified value is not valid for this Parameter

hasDefaultOrIsSet

public abstract boolean hasDefaultOrIsSet()
Returns true if the parameter either has a default value or the value was set by the user, false otherwise.

Returns:
true if value has a default value or was set, false otherwise

isSet

public abstract boolean isSet()
Returns true if the parameter was set by the user, false otherwise.

Returns:
true if the parameter was set, false otherwise

isAtomic

public abstract boolean isAtomic()
Returns true if the parameter is of an atomic data type, false otherwise.

Returns:
true if the parameter is atomic, false otherwise

getErrorMessage

public abstract String getErrorMessage()
If a value could not be set successfully this method returns the corresponding error message.

Returns:
an error message if a value could not be set successfully

reset

public abstract void reset()
Resets the parameter and its contents to the default values or null if no defaults are given.


clone

public Parameter clone()
                throws CloneNotSupportedException
Overrides:
clone in class Object
Throws:
CloneNotSupportedException

setDefault

public abstract void setDefault(Object defaultValue)
                         throws Exception
Sets the default value of the Parameter to defaultValue. This method also sets the current value of this Parameter to the default.

Parameters:
defaultValue - the default value
Throws:
Exception - if the default value is not an appropriate value for this Parameter

setParent

public void setParent(ParameterSet parent)
Sets the reference of the enclosing ParameterSet of this Parameter to parent.

Parameters:
parent - the new enclosing ParameterSet

getParent

public ParameterSet getParent()
Returns a reference to the ParameterSet enclosing this Parameter.

Returns:
the reference to the enclosing ParameterSet

extractFurtherInfos

protected void extractFurtherInfos(StringBuffer source)
                            throws NonParsableException
Description copied from class: AnnotatedEntity
This method can be used in the constructor with parameter StringBuffer to extract the further information.

Specified by:
extractFurtherInfos in class AnnotatedEntity
Parameters:
source - a XML represenation of the main information as StringBuffer
Throws:
NonParsableException - if the XML representation is not parsable
See Also:
AnnotatedEntity.AnnotatedEntity(StringBuffer)

appendFurtherInfos

protected void appendFurtherInfos(StringBuffer buf)
Description copied from class: AnnotatedEntity
This method can be used in the method Storable.toXML() to extract further information (name, comment, datatype).

Specified by:
appendFurtherInfos in class AnnotatedEntity
Parameters:
buf - a XML representation of the main information as StringBuffer
See Also:
Storable.toXML()

isComparable

public boolean isComparable(Parameter p)
This method checks whether the given Parameter is comparable to the current instance, i.e. whether the Class, the DataType, the name and the comment are identical. If necessary, all these characteristics are checked recursively. In other words, the method returns true if the parameters only differ in their specific raw values.

Parameters:
p - the Parameter for the comparison
Returns:
true if the parameters only differ in their values, otherwise false
See Also:
Object.getClass(), AnnotatedEntity.getDatatype(), AnnotatedEntity.getName(), AnnotatedEntity.getComment(), DataType.PARAMETERSET, ParameterSet.isComparable(ParameterSet)