|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.jstacs.parameters.Parameter
de.jstacs.parameters.CollectionParameter
public class CollectionParameter
Class for a collection parameter, i.e. a parameter that provides some
collection of possible values the user can choose from. Instances of this
class can be used as parameters in a ParameterSet
.
ParameterSet
Nested Class Summary | |
---|---|
class |
CollectionParameter.InconsistentCollectionException
This exception is thrown if the CollectionParameter is
inconsistent for some reason. |
Field Summary | |
---|---|
protected String |
errorMessage
If a value was illegal for the collection parameter, this field holds the error message. |
protected ParameterSet |
parameters
The internal ParameterSet that holds the possible values |
protected boolean |
userSelected
true if the user has selected an item |
Fields inherited from class de.jstacs.parameters.Parameter |
---|
neededReference, neededReferenceId, parent |
Constructor Summary | |
---|---|
|
CollectionParameter(DataType datatype,
String[] keys,
Object[] values,
String[] comments,
String name,
String comment,
boolean required)
Constructor for a CollectionParameter . |
|
CollectionParameter(DataType datatype,
String[] keys,
Object[] values,
String name,
String comment,
boolean required)
Constructor for a CollectionParameter . |
|
CollectionParameter(InstanceParameterSet[] values,
String name,
String comment,
boolean required)
Constructor for a CollectionParameter from an array of
ParameterSet s. |
|
CollectionParameter(ParameterSet[] values,
String[] keys,
String[] comments,
String name,
String comment,
boolean required)
Constructor for a CollectionParameter from an array of
ParameterSet s. |
protected |
CollectionParameter(ParameterSet options,
int selected,
int defaultSelected,
boolean userSelected,
String name,
String comment,
boolean required,
DataType datatype,
String errorMessage,
boolean rangeable)
Creates a new CollectionParameter from the necessary field. |
|
CollectionParameter(StringBuffer representation)
The standard constructor for the interface Storable . |
Method Summary | |
---|---|
protected void |
appendCollection(StringBuffer buf)
Appends the internal ParameterSet in its XML representation (
ParameterSet.toXML() ) to the StringBuffer
buf . |
boolean |
checkValue(Object value)
Returns true if the key specified by value is
in the set of keys of this CollectionParameter . |
CollectionParameter |
clone()
|
protected void |
createParameterSet(Object[] values,
String[] keys,
String[] comments)
Creates a new ParameterSet from an array of values, an array of
names and an array of comments. |
boolean |
equals(Object o2)
|
protected void |
extractCollection(StringBuffer buf)
Extracts the internal ParameterSet from its XML representation (
ParameterSet.toXML() ). |
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. |
protected void |
fromXML(StringBuffer representation)
Parses a Parameter from a XML representation as returned by
Parameter.toXML() . |
String |
getComment()
Returns a comment on this Parameter that tells something about
useful values, domains, usage of this parameter, etc. |
DataType |
getDatatype()
Returns the data type of the Parameter . |
protected int |
getDefault()
Returns the index of the default selected value. |
String |
getErrorMessage()
If a value could not be set successfully this method returns the corresponding error message. |
String |
getName()
Returns the name of the Parameter . |
ParameterSet |
getParametersInCollection()
Returns the possible values in this collection. |
Parameter |
getRangedInstance()
Returns an instance of RangeIterator that has the same properties
as the current instance, but accepts a range or list of values. |
int |
getSelected()
Returns the index of the selected value. |
Object |
getValue()
Returns the current value of this Parameter . |
boolean |
hasDefault()
Returns true , if this CollectionParameter 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 |
isAtomic()
Returns true if the parameter is of an atomic data type,
false otherwise. |
boolean |
isRangeable()
Returns true if the parameters can be varied over a range of
values. |
boolean |
isRequired()
Returns true if the Parameter is required,
false otherwise. |
boolean |
isSelected(int idx)
Returns true if the option at position idx is
selected. |
boolean |
isSet()
Returns true if the parameter was set by the user,
false otherwise. |
boolean |
isUserSelected()
Returns true if the value was selected by the user. |
void |
reset()
Resets the parameter and its contents to the default values or null if no defaults are given. |
void |
setDefault(Object defaultValue)
Sets the default value of the Parameter to
defaultValue . |
void |
setRangeable(boolean rangeable)
Sets the value returned by isRangeable() to
rangeable . |
void |
setValue(Object value)
Sets the selected value to the one that is specified by the key value . |
void |
simplify()
Simplifies the Parameter and its contents to the relevant
information. |
void |
toGalaxy(String namePrefix,
String configPrefix,
int depth,
StringBuffer descBuffer,
StringBuffer configBuffer)
Creates an Galaxy XML-representation of the parameters and appends it to descBuffer
and variable configuration and appends it to configBuffer . |
String |
toString()
|
StringBuffer |
toXML()
This method returns an XML representation as StringBuffer of an
instance of the implementing class. |
Methods inherited from class de.jstacs.parameters.Parameter |
---|
getId, getNeededReference, getNeededReferenceId, getParent, setNeededReference, setParent |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected ParameterSet parameters
ParameterSet
that holds the possible values
protected boolean userSelected
true
if the user has selected an item
protected String errorMessage
Constructor Detail |
---|
protected CollectionParameter(ParameterSet options, int selected, int defaultSelected, boolean userSelected, String name, String comment, boolean required, DataType datatype, String errorMessage, boolean rangeable)
CollectionParameter
from the necessary field. This
constructor should be used to clone a current instance.
options
- the options of the CollectionParameter
selected
- the currently selected valuedefaultSelected
- the value selected by defaultuserSelected
- true
if the current value was selected by the
user, false
otherwisename
- the name of the parametercomment
- a comment on the parameterrequired
- true
if this CollectionParameter
is
required, false
otherwisedatatype
- the data type of the parameters in the collectionerrorMessage
- the error message of the last error or null
rangeable
- true
if the current instance is rangeablepublic CollectionParameter(DataType datatype, String[] keys, Object[] values, String name, String comment, boolean required) throws CollectionParameter.InconsistentCollectionException, SimpleParameter.IllegalValueException, SimpleParameter.DatatypeNotValidException
CollectionParameter
.
datatype
- the data type of the parameters in the collectionkeys
- the keys/names of the values in the collection, this is the
name the user will see in the user interfacevalues
- 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 arrayname
- the name of the parametercomment
- a comment on the parameterrequired
- true
if this CollectionParameter
is
required, false
otherwise
CollectionParameter.InconsistentCollectionException
- if the length of keys
and the
values
is 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 valuesCollectionParameter(DataType, String[],
Object[], String[], String, String, boolean)
public CollectionParameter(DataType datatype, String[] keys, Object[] values, String[] comments, String name, String comment, boolean required) throws CollectionParameter.InconsistentCollectionException, SimpleParameter.IllegalValueException, SimpleParameter.DatatypeNotValidException
CollectionParameter
.
datatype
- the data type of the parameters in the collectionkeys
- the keys/names of the values in the collection, this is the
name the user will see in the user interfacevalues
- 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 arraycomments
- the comments on the possible valuesname
- the name of the parametercomment
- a comment on the parameterrequired
- true
if the CollectionParameter
is
required, false
otherwise
CollectionParameter.InconsistentCollectionException
- if the length of keys
and values
is
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 valuescreateParameterSet(Object[], String[], String[])
public CollectionParameter(ParameterSet[] values, String[] keys, String[] comments, String name, String comment, boolean required)
CollectionParameter
from an array of
ParameterSet
s. This constructor can be used to easily construct a
CollectionParameter
that lets the user select from a list of
possible options that all require an own set of Parameter
s to be
instantiated.
values
- the array of ParameterSet
skeys
- the keys/names of the values in the collection, this is the
name the user will see in the user interfacecomments
- the comments on the possible valuesname
- the name of the parametercomment
- a comment on the parameterrequired
- true
if the parameter is required,
false
otherwisecreateParameterSet(Object[], String[], String[])
public CollectionParameter(InstanceParameterSet[] values, String name, String comment, boolean required)
CollectionParameter
from an array of
ParameterSet
s. This constructor can be used to easily construct a
CollectionParameter
that lets the user select from a list of
possible options that all require an own set of Parameter
s to be
instantiated.
values
- the array of ParameterSet
sname
- the name of the parametercomment
- a comment on the parameterrequired
- true
if the parameter is required,
false
otherwisecreateParameterSet(Object[], String[], String[])
public CollectionParameter(StringBuffer representation) throws NonParsableException
Storable
.
Restores an instance of CollectionParameter
from a XML
representation.
representation
- the XML representation as StringBuffer
NonParsableException
- if the StringBuffer
representation
could
not be parsedfromXML(StringBuffer)
Method Detail |
---|
public CollectionParameter clone() throws CloneNotSupportedException
clone
in class Parameter
CloneNotSupportedException
protected void createParameterSet(Object[] values, String[] keys, String[] comments) throws SimpleParameter.DatatypeNotValidException, SimpleParameter.IllegalValueException
ParameterSet
from an array of values, an array of
names and an array of comments.
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 arraykeys
- the keys/names of the values in the collection, this is the
name the user will see in the user interfacecomments
- the comments on the possible values
SimpleParameter.IllegalValueException
- if one of the values in values
is not of type
datatype
SimpleParameter.DatatypeNotValidException
- if the data type is not allowed, i.e. is not one of the
primitive data types, String
or
DataType.PARAMETERSET
public boolean isAtomic()
Parameter
true
if the parameter is of an atomic data type,
false
otherwise.
isAtomic
in class Parameter
true
if the parameter is atomic, false
otherwisepublic boolean hasDefault()
true
, if this CollectionParameter
has a
default value.
CollectionParameter
has a default valueCollectionParameter(ParameterSet, int, int,
boolean, String, String, boolean, DataType, String, boolean)
,
setDefault(Object)
public boolean hasDefaultOrIsSet()
Parameter
true
if the parameter either has a default value or
the value was set by the user, false
otherwise.
hasDefaultOrIsSet
in class Parameter
true
if value has a default value or was set,
false
otherwisepublic boolean isSet()
Parameter
true
if the parameter was set by the user,
false
otherwise.
isSet
in class Parameter
true
if the parameter was set, false
otherwisepublic ParameterSet getParametersInCollection()
public void setRangeable(boolean rangeable)
isRangeable()
to
rangeable
.
rangeable
- the new valuepublic boolean isRangeable()
Rangeable
true
if the parameters can be varied over a range of
values.
isRangeable
in interface Rangeable
true
if the parameter can be varied,
false
otherwisepublic boolean checkValue(Object value)
true
if the key specified by value
is
in the set of keys of this CollectionParameter
.
checkValue
in class Parameter
value
- the value to be checked
true
if the key specified by value
is
in the set of keys of this CollectionParameter
,
false
otherwisepublic String getErrorMessage()
Parameter
getErrorMessage
in class Parameter
public StringBuffer toXML()
Storable
StringBuffer
of an
instance of the implementing class.
toXML
in interface Storable
toXML
in class Parameter
protected void appendCollection(StringBuffer buf)
ParameterSet
in its XML representation (
ParameterSet.toXML()
) to the StringBuffer
buf
.
buf
- the StringBuffer
this method appends toprotected void fromXML(StringBuffer representation) throws NonParsableException
Parameter
Parameter
from a XML representation as returned by
Parameter.toXML()
.
fromXML
in class Parameter
representation
- the XML representation as StringBuffer
NonParsableException
- if the XML code could not be parsedParameter.toXML()
protected void extractCollection(StringBuffer buf) throws NonParsableException
ParameterSet
from its XML representation (
ParameterSet.toXML()
). Reverse method to
appendCollection(StringBuffer)
.
buf
- the StringBuffer
containing the XML representation
NonParsableException
- if the XML code could not be parsedpublic String getName()
Parameter
Parameter
.
getName
in class Parameter
Parameter
public DataType getDatatype()
Parameter
Parameter
.
getDatatype
in class Parameter
Parameter
public String getComment()
Parameter
Parameter
that tells something about
useful values, domains, usage of this parameter, etc.
getComment
in class Parameter
public boolean isRequired()
Parameter
true
if the Parameter
is required,
false
otherwise.
isRequired
in class Parameter
true
if the Parameter
is required,
false
otherwisepublic boolean isSelected(int idx)
true
if the option at position idx
is
selected.
idx
- the position
true
if the option at position idx
is
selected, false
otherwisepublic int getSelected()
protected int getDefault()
public boolean isUserSelected()
true
if the value was selected by the user.
true
if the value was selected by the user.public void setValue(Object value) throws SimpleParameter.IllegalValueException
value
.
setValue
in class Parameter
value
- the key of the desired value
SimpleParameter.IllegalValueException
- if the specified value is not valid for this
Parameter
public void setDefault(Object defaultValue) throws SimpleParameter.IllegalValueException
Parameter
Parameter
to
defaultValue
.
setDefault
in class Parameter
defaultValue
- the default value
SimpleParameter.IllegalValueException
public void simplify()
Parameter
Parameter
and its contents to the relevant
information. This could be e.g. to reset the contents of those values of
a CollectionParameter
that are not selected.
simplify
in class Parameter
public void reset()
Parameter
null
if no defaults are given.
reset
in class Parameter
public Object getValue()
Parameter
Parameter
.
getValue
in class Parameter
Parameter
public boolean equals(Object o2)
equals
in class Object
public Parameter getRangedInstance() throws Exception
Rangeable
RangeIterator
that has the same properties
as the current instance, but accepts a range or list of values. These
values can be obtained by the methods of RangeIterator
.
getRangedInstance
in interface Rangeable
Exception
- is thrown if Rangeable.isRangeable()
returns
false
or the ranged instance could not be
created for some other reasonpublic String toString()
toString
in class Object
public void toGalaxy(String namePrefix, String configPrefix, int depth, StringBuffer descBuffer, StringBuffer configBuffer) throws Exception
GalaxyConvertible
descBuffer
and variable configuration and appends it to configBuffer
. The variable configuation
is also used to parse user-supplied values returned by Galaxy.
toGalaxy
in interface GalaxyConvertible
namePrefix
- the prefix of the variable name used in GalaxyconfigPrefix
- the prefix for conditionalsdepth
- the depth in the parameter hierarchy, used for graphical representation of nestingdescBuffer
- the buffer for the parameter descriptionconfigBuffer
- the buffer for the configuration line
Exception
- if the conversion failspublic void fromGalaxy(String namePrefix, StringBuffer command) throws Exception
GalaxyConvertible
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.
fromGalaxy
in interface GalaxyConvertible
namePrefix
- the prefix of the variable namecommand
- the command string
Exception
- if the command string could not be parsed
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |