de.jstacs.parameters
Class MultiSelectionParameter

java.lang.Object
  extended by de.jstacs.AnnotatedEntity
      extended by de.jstacs.parameters.Parameter
          extended by de.jstacs.parameters.AbstractSelectionParameter
              extended by de.jstacs.parameters.MultiSelectionParameter
All Implemented Interfaces:
GalaxyConvertible, Rangeable, RangeIterator, Storable, Cloneable

public class MultiSelectionParameter
extends AbstractSelectionParameter
implements RangeIterator

Class for a Parameter that provides a collection of possible values. The user can select one or more values out of the collection as values of this Parameter.

Author:
Jan Grau, Jens Keilwagen
See Also:
AbstractSelectionParameter

Nested Class Summary
 
Nested classes/interfaces inherited from class de.jstacs.parameters.AbstractSelectionParameter
AbstractSelectionParameter.InconsistentCollectionException
 
Field Summary
 
Fields inherited from class de.jstacs.parameters.AbstractSelectionParameter
errorMessage, parameters, userSelected
 
Fields inherited from class de.jstacs.parameters.Parameter
parent
 
Fields inherited from class de.jstacs.AnnotatedEntity
comment, datatype, name
 
Constructor Summary
MultiSelectionParameter(DataType datatype, String[] keys, Object[] values, String[] comments, String name, String comment, boolean required)
          Constructor for a MultiSelectionParameter.
MultiSelectionParameter(DataType datatype, String[] keys, Object[] values, String name, String comment, boolean required)
          Constructor for a MultiSelectionParameter.
MultiSelectionParameter(StringBuffer representation)
          The standard constructor for the interface Storable.
MultiSelectionParameter(String name, String comment, boolean required, Class<? extends ParameterSet>... values)
          Creates a new MultiSelectionParameter from an array of Classes of ParameterSets.
MultiSelectionParameter(String name, String comment, boolean required, ParameterSet... values)
          Creates a new MultiSelectionParameter from an array of ParameterSets.
 
Method Summary
protected  void appendFurtherInfos(StringBuffer sup)
          This method can be used in the method Storable.toXML() to extract further information (name, comment, datatype).
 boolean checkValue(Object value)
          Returns true if the key specified by value is in the set of keys of this AbstractSelectionParameter.
 MultiSelectionParameter clone()
           
protected  void extractFurtherInfos(StringBuffer representation)
          This method can be used in the constructor with parameter StringBuffer to extract the further information.
 void fromGalaxy(String namePrefix, StringBuffer command)
          Parses the contents of command in the format defined by configBuffer of GalaxyConvertible.toGalaxy(String, String, int, StringBuffer, StringBuffer) and sets the values of the Parameter or ParameterSet accordingly.
 int getNumberOfNexts(int afterIdx)
          Returns the number of calls of next() that can be called before false is returned.
 int getNumberOfValues()
          Returns the number of values in the collection.
 int[] getSelected()
          Returns the indexes of the selected options.
 Object getValue()
          Returns the value of the AnnotatedEntity.
 Object getValueFor(int idx)
          Returns the value of the option with no.
 Object getValueFor(String key)
          Returns the value for the option with key key.
 Object[] getValues()
          Returns the values of all selected options as an array.
 String getXMLTag()
          This method returns a tag used as outer tag of the XML description.
 boolean hasDefault()
          Returns true, if this AbstractSelectionParameter has a default value.
 boolean hasDefaultOrIsSet()
          Returns true if the parameter either has a default value or the value was set by the user, false otherwise.
 boolean isRanged()
          Returns true if this RangeIterator is ranging over a set of values.
 boolean isSelected(int idx)
          Returns true if the option at position idx is selected.
 boolean isSelected(String key)
          Returns the selection value of the option with key key.
 boolean next()
          Switches to the next value in the collection of values in the specified range.
 void reset()
          Resets the parameter and its contents to the default values or null if no defaults are given.
 void resetToFirst()
          Resets the current value in the collection to the first value.
 void setDefault(Object defaultValue)
          Sets the default value of this AbstractSelectionParameter to defaultValue.
 void setDefaultSelected(int[] defaultSelection)
          Sets the default selection of this MultiSelectionParameter to defaultSelection.
 boolean setSelected(int idx, boolean selected)
          Sets the selection of option with no.
 boolean setSelected(String key, boolean selected)
          Sets the selection of the option with key key to the value of selected.
 void setValue(Object value)
          Sets the value of this Parameter to value.
 String valuesToString()
          Returns a String representation of the set of values.
 
Methods inherited from class de.jstacs.parameters.AbstractSelectionParameter
check, createParameterSet, equals, getErrorMessage, getParametersInCollection, getRangedInstance, isAtomic, isRangeable, isRequired, isSet, isUserSelected, setRangeable, toGalaxy
 
Methods inherited from class de.jstacs.parameters.Parameter
getParent, isComparable, setParent
 
Methods inherited from class de.jstacs.AnnotatedEntity
getComment, getDatatype, getName, toXML
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiSelectionParameter

public MultiSelectionParameter(DataType datatype,
                               String[] keys,
                               Object[] values,
                               String name,
                               String comment,
                               boolean required)
                        throws AbstractSelectionParameter.InconsistentCollectionException,
                               SimpleParameter.IllegalValueException,
                               SimpleParameter.DatatypeNotValidException
Constructor for a MultiSelectionParameter. The first option in the selection is selected by default.

Parameters:
datatype - the data type of the parameters in the collection
keys - the keys/names of the values in the collection, this is the name the user will see in the user interface
values - the values the names stand for, this array must be of the same length as keys, a key at a certain position belongs to the value at the same position in the array
name - the name of the parameter
comment - a comment on the parameter
required - true if the parameter is required, false otherwise
Throws:
InconsistentCollectionException - if the lengths of keys and values are different or the collection is inconsistent for some other reason
SimpleParameter.IllegalValueException - if one of the values in values is not of type datatype
SimpleParameter.DatatypeNotValidException - if the datatype is not one of the allowed values
AbstractSelectionParameter.InconsistentCollectionException

MultiSelectionParameter

public MultiSelectionParameter(DataType datatype,
                               String[] keys,
                               Object[] values,
                               String[] comments,
                               String name,
                               String comment,
                               boolean required)
                        throws AbstractSelectionParameter.InconsistentCollectionException,
                               SimpleParameter.IllegalValueException,
                               SimpleParameter.DatatypeNotValidException
Constructor for a MultiSelectionParameter. The first option in the selection is selected by default.

Parameters:
datatype - the data type of the parameters in the collection
keys - the keys/names of the values in the collection, this is the name the user will see in the user interface
values - the values the names stand for, this array must be of the same length as keys, a key at a certain position belongs to the value at the same position in the array
comments - the comments on the values in the collection
name - the name of the parameter
comment - a comment on the parameter
required - true if the parameter is required, false otherwise
Throws:
InconsistentCollectionException - if the lengths of keys and values are different or the collection is inconsistent for some other reason
SimpleParameter.IllegalValueException - if one of the values in values is not of type datatype
SimpleParameter.DatatypeNotValidException - if the datatype is not one of the allowed values
AbstractSelectionParameter.InconsistentCollectionException

MultiSelectionParameter

public MultiSelectionParameter(String name,
                               String comment,
                               boolean required,
                               ParameterSet... values)
Creates a new MultiSelectionParameter from an array of ParameterSets. The first option in the selection is selected by default.

Parameters:
values - the options/values in the collection
name - the name of this MultiSelectionParameter
comment - the comment on this MultiSelectionParameter
required - true if this MultiSelectionParameter is required, false otherwise

MultiSelectionParameter

public MultiSelectionParameter(String name,
                               String comment,
                               boolean required,
                               Class<? extends ParameterSet>... values)
Creates a new MultiSelectionParameter from an array of Classes of ParameterSets. The first option in the selection is selected by default. It is the lazy evaluation variant of MultiSelectionParameter(String, String, boolean, ParameterSet...), i.e., the ParameterSets are only created if necessary.

Parameters:
values - the array of Classes of ParameterSets
name - the name of this MultiSelectionParameter
comment - the comment on this MultiSelectionParameter
required - true if this MultiSelectionParameter is required, false otherwise

MultiSelectionParameter

public MultiSelectionParameter(StringBuffer representation)
                        throws NonParsableException
The standard constructor for the interface Storable. Creates a new MultiSelectionParameter from its XML representation

Parameters:
representation - the XML representation as StringBuffer
Throws:
NonParsableException - if the StringBuffer representation could not be parsed
Method Detail

clone

public MultiSelectionParameter clone()
                              throws CloneNotSupportedException
Overrides:
clone in class AbstractSelectionParameter
Throws:
CloneNotSupportedException

setSelected

public boolean setSelected(String key,
                           boolean selected)
Sets the selection of the option with key key to the value of selected.

Parameters:
key - the key of the option
selected - the selection value
Returns:
true if the key could be found and set, false otherwise

isSelected

public boolean isSelected(String key)
Returns the selection value of the option with key key.

Parameters:
key - the key of the option
Returns:
the selection value or false if no such option exists

getValueFor

public Object getValueFor(String key)
Returns the value for the option with key key.

Parameters:
key - the key of the option
Returns:
the value or null if the corresponding option either does not exist or is not selected

checkValue

public boolean checkValue(Object value)
Description copied from class: AbstractSelectionParameter
Returns true if the key specified by value is in the set of keys of this AbstractSelectionParameter.

Overrides:
checkValue in class AbstractSelectionParameter
Parameters:
value - the value to be checked
Returns:
true if the key specified by value is in the set of keys of this AbstractSelectionParameter, false otherwise

setValue

public void setValue(Object value)
              throws SimpleParameter.IllegalValueException
Description copied from class: Parameter
Sets the value of this Parameter to value.

Specified by:
setValue in class Parameter
Parameters:
value - the new value of the Parameter
Throws:
SimpleParameter.IllegalValueException - if the specified value is not valid for this Parameter

getSelected

public int[] getSelected()
Returns the indexes of the selected options.

Returns:
the indexes of the selected options.

setSelected

public boolean setSelected(int idx,
                           boolean selected)
Sets the selection of option with no. idx to selected.

Parameters:
idx - the index of the option
selected - the selection value
Returns:
true if the option exists and could be set, false otherwise

isSelected

public boolean isSelected(int idx)
Description copied from class: AbstractSelectionParameter
Returns true if the option at position idx is selected.

Specified by:
isSelected in class AbstractSelectionParameter
Parameters:
idx - the position
Returns:
true if the option at position idx is selected, false otherwise

getValueFor

public Object getValueFor(int idx)
Returns the value of the option with no. idx.

Parameters:
idx - the index of the option
Returns:
the value or null if the corresponding option either does not exists or is not selected

getValues

public Object[] getValues()
Returns the values of all selected options as an array.

Returns:
the values of all selected options

getValue

public Object getValue()
Description copied from class: AnnotatedEntity
Returns the value of the AnnotatedEntity.

Specified by:
getValue in class AnnotatedEntity
Returns:
the value of the AnnotatedEntity

hasDefaultOrIsSet

public boolean hasDefaultOrIsSet()
Description copied from class: Parameter
Returns true if the parameter either has a default value or the value was set by the user, false otherwise.

Specified by:
hasDefaultOrIsSet in class Parameter
Returns:
true if value has a default value or was set, false otherwise

reset

public void reset()
Description copied from class: Parameter
Resets the parameter and its contents to the default values or null if no defaults are given.

Specified by:
reset in class Parameter

setDefault

public void setDefault(Object defaultValue)
                throws SimpleParameter.IllegalValueException
Description copied from class: AbstractSelectionParameter
Sets the default value of this AbstractSelectionParameter to defaultValue. This method also sets the current value of this AbstractSelectionParameter to the default and resets it such that AbstractSelectionParameter.isUserSelected() returns false.

Specified by:
setDefault in class AbstractSelectionParameter
Parameters:
defaultValue - the default value
Throws:
SimpleParameter.IllegalValueException

setDefaultSelected

public void setDefaultSelected(int[] defaultSelection)
Sets the default selection of this MultiSelectionParameter to defaultSelection. This method also sets the current selection of this MultiSelectionParameter to the default and resets it such that AbstractSelectionParameter.isUserSelected() returns false.

Parameters:
defaultSelection - the new default selection

getXMLTag

public String getXMLTag()
Description copied from class: AnnotatedEntity
This method returns a tag used as outer tag of the XML description.

Specified by:
getXMLTag in class AnnotatedEntity
Returns:
a tag used as outer tag of the XML description

appendFurtherInfos

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

Overrides:
appendFurtherInfos in class AbstractSelectionParameter
Parameters:
sup - a XML representation of the main information as StringBuffer
See Also:
Storable.toXML()

extractFurtherInfos

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

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

next

public boolean next()
             throws ParameterException
Description copied from interface: RangeIterator
Switches to the next value in the collection of values in the specified range.

Specified by:
next in interface RangeIterator
Returns:
true if the next element exists, false otherwise
Throws:
ParameterException - if the next value could not be fetched

resetToFirst

public void resetToFirst()
Description copied from interface: RangeIterator
Resets the current value in the collection to the first value.

Specified by:
resetToFirst in interface RangeIterator

getNumberOfValues

public int getNumberOfValues()
Description copied from interface: RangeIterator
Returns the number of values in the collection.

Specified by:
getNumberOfValues in interface RangeIterator
Returns:
the number of values

getNumberOfNexts

public int getNumberOfNexts(int afterIdx)
Returns the number of calls of next() that can be called before false is returned.

Parameters:
afterIdx - the index after which shall be counted
Returns:
the number of calls of next()

valuesToString

public String valuesToString()
Description copied from interface: RangeIterator
Returns a String representation of the set of values.

Specified by:
valuesToString in interface RangeIterator
Returns:
the String representation

isRanged

public boolean isRanged()
Description copied from interface: RangeIterator
Returns true if this RangeIterator is ranging over a set of values.

Specified by:
isRanged in interface RangeIterator
Returns:
true if this RangeIterator is ranging over a set of values, false otherwise

hasDefault

public boolean hasDefault()
Description copied from class: AbstractSelectionParameter
Returns true, if this AbstractSelectionParameter has a default value.

Specified by:
hasDefault in class AbstractSelectionParameter
Returns:
if this AbstractSelectionParameter has a default value
See Also:
AbstractSelectionParameter.setDefault(Object)

fromGalaxy

public void fromGalaxy(String namePrefix,
                       StringBuffer command)
                throws Exception
Description copied from interface: GalaxyConvertible
Parses the contents of command in the format defined by configBuffer of GalaxyConvertible.toGalaxy(String, String, int, StringBuffer, StringBuffer) and sets the values of the Parameter or ParameterSet accordingly.

Specified by:
fromGalaxy in interface GalaxyConvertible
Parameters:
namePrefix - the prefix of the variable name
command - the command string
Throws:
Exception - if the command string could not be parsed