de.jstacs.parameters
Class ExpandableParameterSet

java.lang.Object
  extended by de.jstacs.parameters.ParameterSet
      extended by de.jstacs.parameters.ExpandableParameterSet
All Implemented Interfaces:
RangeIterator, Storable, Cloneable
Direct Known Subclasses:
AlphabetContainerParameterSet.SectionDefinedAlphabetParameterSet, ArrayParameterSet

public class ExpandableParameterSet
extends ParameterSet

A class for a ParameterSet that can be expanded by additional Parameters at runtime. The Parameter are all of type ParameterSetContainer. The contents of these Parameters are provided by a ParameterSet-template, which is cloned each time the addParameterToSet()-method is called and set as value of a ParameterSetContainer that is added to the Parameters of the ExpandableParameterSet. Already added Parameters can also be removed from the set using the removeParameterFromSet-method.

Author:
Jan Grau

Nested Class Summary
 
Nested classes/interfaces inherited from class de.jstacs.parameters.ParameterSet
ParameterSet.ParameterList
 
Field Summary
protected  String commentTemplate
          A template for the comment of the enclosing ParameterSetContainer
protected  String nameTemplate
          A template for the name of the enclosing ParameterSetContainer
protected  ParameterSet template
          The template for each ParameterSet
 
Fields inherited from class de.jstacs.parameters.ParameterSet
alternativeInstanceClass, errorMessage, parameters, parent, ranged
 
Constructor Summary
ExpandableParameterSet(Class instanceClass, ParameterSet[] templateAndContent, String nameTemplate, String commentTemplate)
          Creates a new ExpandableParameterSet from a ParameterSet-array.
ExpandableParameterSet(Class alternativeInstanceClass, ParameterSet template, String nameTemplate, String commentTemplate)
          Creates a new ExpandableParameterSet from a Class that can be instantiated using this ExpandableParameterSet and templates for the ParameterSet in each element of the array, the name and the comment that are displayed for the ParameterSetContainers enclosing the ParameterSets.
ExpandableParameterSet(Class alternativeInstanceClass, ParameterSet template, String nameTemplate, String commentTemplate, int initCount)
          Creates a new ExpandableParameterSet from a Class that can be instantiated using this ExpandableParameterSet and templates for the ParameterSet in each element of the array, the name and the comment that are displayed for the ParameterSetContainers enclosing the ParameterSets.
ExpandableParameterSet(StringBuffer representation)
          Creates a new ExpandableParameterSet from its XML-representation.
 
Method Summary
 void addParameterToSet()
          Adds a new ParameterSetContainer containing a clone of the ParameterSet-template to the set of Parameters
 ExpandableParameterSet clone()
          Creates a full clone (deep copy) of this ParameterSet.
protected  void fromXML(StringBuffer representation)
          Parses the instance fields of a ParameterSet from the XML-representation as returned by ParameterSet.toXML().
 String getInstanceComment()
          Returns a comment (a textual description) of the class that can be constructed using this ParameterSet.
 String getInstanceName()
          Returns the name of an instance of the class that can be constructed using this ParameterSet.
protected  void loadParameters()
          Loads the parameters for this ParameterSet.
 boolean parameterRemovable()
          Returns true if there is still a Parameter that can be removed from the set.
 void removeParameterFromSet()
          Removes the last Parameter from set.
 boolean replaceContentWith(ParameterSet[] paramSetArray)
          First removes all previous added ParameterSetContainer and afterwards adds all given ParameterSets (in the given order) enclosed in new ParameterSetContainers.
protected  void replaceParametersWithRangedInstance()
          Replaces all Parameters in this ParameterSet by their equivalents implementing the Rangeable interface.
 StringBuffer toXML()
          This method returns an XML-representation of an instance of the implementing class.
 
Methods inherited from class de.jstacs.parameters.ParameterSet
getErrorMessage, getId, getInstance, getInstanceClass, getNumberOfParameters, getNumberOfValues, getParameterAt, getParent, hasDefaultOrIsSet, initParameterList, initParameterList, isAtomic, isRanged, makeRanged, next, parametersLoaded, propagateId, recieveId, reset, resetToFirst, setAlternativeInstanceClass, setParent, simplify, valuesToString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

template

protected ParameterSet template
The template for each ParameterSet


nameTemplate

protected String nameTemplate
A template for the name of the enclosing ParameterSetContainer


commentTemplate

protected String commentTemplate
A template for the comment of the enclosing ParameterSetContainer

Constructor Detail

ExpandableParameterSet

public ExpandableParameterSet(Class alternativeInstanceClass,
                              ParameterSet template,
                              String nameTemplate,
                              String commentTemplate)
Creates a new ExpandableParameterSet from a Class that can be instantiated using this ExpandableParameterSet and templates for the ParameterSet in each element of the array, the name and the comment that are displayed for the ParameterSetContainers enclosing the ParameterSets. Initially, the loadParameters-method creates one copy of the template.

Parameters:
alternativeInstanceClass - the Class
template - the template of the ParameterSet
nameTemplate - the name-template
commentTemplate - the comment-template

ExpandableParameterSet

public ExpandableParameterSet(Class alternativeInstanceClass,
                              ParameterSet template,
                              String nameTemplate,
                              String commentTemplate,
                              int initCount)
Creates a new ExpandableParameterSet from a Class that can be instantiated using this ExpandableParameterSet and templates for the ParameterSet in each element of the array, the name and the comment that are displayed for the ParameterSetContainers enclosing the ParameterSets. Using this constructor, the loadParameters()-method initially creates initCount copies of the template.

Parameters:
alternativeInstanceClass - the Class
template - the template of the ParameterSet
nameTemplate - the name-template
commentTemplate - the comment-template
initCount - the number of initial copies of the template

ExpandableParameterSet

public ExpandableParameterSet(StringBuffer representation)
                       throws NonParsableException
Creates a new ExpandableParameterSet from its XML-representation.

Parameters:
representation - the XML-represenation
Throws:
NonParsableException - is thrown if representation could not be parsed.

ExpandableParameterSet

public ExpandableParameterSet(Class instanceClass,
                              ParameterSet[] templateAndContent,
                              String nameTemplate,
                              String commentTemplate)
Creates a new ExpandableParameterSet from a ParameterSet-array. The first element of this array is taken as a template for further addParameterToSet()-calls.

Parameters:
instanceClass - the class that can be instantiated from this ExpandableParameterSet
templateAndContent - the content (and template)
nameTemplate - the name-template
commentTemplate - the comment-template
Method Detail

clone

public ExpandableParameterSet clone()
                             throws CloneNotSupportedException
Description copied from class: ParameterSet
Creates a full clone (deep copy) of this ParameterSet. As a convenience-method the user can use fillWithStandardFieldsForClone(ParameterSet) on a newly created instance of a subclass of ParameterSet to obtain a clone/copy of all standard member variables (those already defined in ParameterSet) in the passed ParameterSet. Using this method, the cloning-process becomes merely three-step:
This method fulfils the conventions of Object's method clone()

Overrides:
clone in class ParameterSet
Returns:
a deep clone of this ParameterSet
Throws:
CloneNotSupportedException

loadParameters

protected void loadParameters()
                       throws Exception
Description copied from class: ParameterSet
Loads the parameters for this ParameterSet. This is in most cases done by simply creating a new ArrayList<Parameter> for the field parameters/code> and filling it with instances of subclasses of Parameter

Specified by:
loadParameters in class ParameterSet
Throws:
Exception - an Exception is thrown if the parameters could not be loaded
See Also:
ParameterSet.parameters, Parameter

replaceParametersWithRangedInstance

protected void replaceParametersWithRangedInstance()
                                            throws Exception
Description copied from class: ParameterSet
Replaces all Parameters in this ParameterSet by their equivalents implementing the Rangeable interface.

Overrides:
replaceParametersWithRangedInstance in class ParameterSet
Throws:
Exception - is thrown if these instances could not be created

addParameterToSet

public void addParameterToSet()
                       throws CloneNotSupportedException
Adds a new ParameterSetContainer containing a clone of the ParameterSet-template to the set of Parameters

Throws:
CloneNotSupportedException - is thrown if the template could not be cloned

replaceContentWith

public boolean replaceContentWith(ParameterSet[] paramSetArray)
First removes all previous added ParameterSetContainer and afterwards adds all given ParameterSets (in the given order) enclosed in new ParameterSetContainers.

Parameters:
paramSetArray - the ParameterSets to be set
Returns:
true, if all given ParameterSets are of the same class as the defined template-ParameterSet of this ExpandableParameterSet; false otherwise (In this case, neither the previous added ParameterSetContainer are removed nor is any given ParameterSet added. Hence the ExpandableParameterSet stays unchanged)

parameterRemovable

public boolean parameterRemovable()
Returns true if there is still a Parameter that can be removed from the set.

Returns:
is a Parameter can be removed

removeParameterFromSet

public void removeParameterFromSet()
Removes the last Parameter from set.


toXML

public StringBuffer toXML()
Description copied from interface: Storable
This method returns an XML-representation of an instance of the implementing class.

Specified by:
toXML in interface Storable
Overrides:
toXML in class ParameterSet
Returns:
the XML-representation

fromXML

protected void fromXML(StringBuffer representation)
                throws NonParsableException
Description copied from class: ParameterSet
Parses the instance fields of a ParameterSet from the XML-representation as returned by ParameterSet.toXML().

Overrides:
fromXML in class ParameterSet
Parameters:
representation - the XML-representation
Throws:
NonParsableException - is thrown if the XML-code could not be parsed

getInstanceName

public String getInstanceName()
Description copied from class: ParameterSet
Returns the name of an instance of the class that can be constructed using this ParameterSet.

Specified by:
getInstanceName in class ParameterSet
Returns:
the name

getInstanceComment

public String getInstanceComment()
Description copied from class: ParameterSet
Returns a comment (a textual description) of the class that can be constructed using this ParameterSet.

Specified by:
getInstanceComment in class ParameterSet
Returns:
the comment