Package uk.ac.starlink.ttools.task
Class WordsParameter
- java.lang.Object
-
- uk.ac.starlink.task.Parameter<java.lang.String[]>
-
- uk.ac.starlink.ttools.task.WordsParameter
-
public class WordsParameter extends uk.ac.starlink.task.Parameter<java.lang.String[]>
Parameter which can split its value up into an array of words. Words are generally delimited by whitespace, but can be quoted using single or double quotes as in the shell. You can specify the required number of words.- Since:
- 1 Sep 2005
- Author:
- Mark Taylor
-
-
Constructor Summary
Constructors Constructor Description WordsParameter(java.lang.String name)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getRequiredWordCount()
Returns the number of words required from this parameter.WordParser
getWordParser()
Returns the parser which is being used to validate and to parse each word in the supplied value string.java.lang.Object[]
parsedWordsValue(uk.ac.starlink.task.Environment env)
Returns the value of this parameter as an array of objects which have resulted from the parsing of thewordsValue(uk.ac.starlink.task.Environment)
using the currently installedWordParser
.void
setRequiredWordCount(int nWords)
Sets the number of words required from this parameter.void
setWordParser(WordParser parser)
Sets a parser which will be used to validate and to parse each word in the supplied value string.void
setWordUsage(java.lang.String wordUsage)
Configures the usage of this parameter from usages for given words.java.lang.String[]
stringToObject(uk.ac.starlink.task.Environment env, java.lang.String sval)
java.lang.String[]
wordsValue(uk.ac.starlink.task.Environment env)
If the required word count value of this parameter is non-negative, then the return value is guaranteed to contain that number of elements.-
Methods inherited from class uk.ac.starlink.task.Parameter
clearValue, getDescription, getName, getPosition, getPreferExplicit, getPrompt, getStringDefault, getUsage, getValueClass, isNullPermitted, objectToString, objectValue, setDescription, setDescription, setName, setNullPermitted, setPosition, setPreferExplicit, setPrompt, setStringDefault, setUsage, setValue, setValueFromObject, setValueFromString, stringValue, toArray, toString
-
-
-
-
Method Detail
-
setRequiredWordCount
public void setRequiredWordCount(int nWords)
Sets the number of words required from this parameter. If it is -1 (the default), then no restrictions are placed on the number of words. Otherwise, attempting to set the value to the wrong number of words is an error.- Parameters:
nWords
- required number of words
-
getRequiredWordCount
public int getRequiredWordCount()
Returns the number of words required from this parameter. If it is -1 (the default), then no restrictions are placed on the number of words. Otherwise, attempting to set the value to the wrong number of words is an error.- Returns:
- required number of words
-
setWordParser
public void setWordParser(WordParser parser)
Sets a parser which will be used to validate and to parse each word in the supplied value string. If null, no validation is performed and the parsed words are just the tokenized strings.- Parameters:
parser
- word parser to install
-
getWordParser
public WordParser getWordParser()
Returns the parser which is being used to validate and to parse each word in the supplied value string. If null, no validation is being performed and the parsed words are just the tokenized strings.- Returns:
- word parser
-
setWordUsage
public void setWordUsage(java.lang.String wordUsage)
Configures the usage of this parameter from usages for given words.- Parameters:
wordUsage
- per-word usage
-
wordsValue
public java.lang.String[] wordsValue(uk.ac.starlink.task.Environment env) throws uk.ac.starlink.task.TaskException
If the required word count value of this parameter is non-negative, then the return value is guaranteed to contain that number of elements.- Parameters:
env
- execution environment- Returns:
- array of words constituting the value of this parameter
- Throws:
uk.ac.starlink.task.TaskException
-
parsedWordsValue
public java.lang.Object[] parsedWordsValue(uk.ac.starlink.task.Environment env) throws uk.ac.starlink.task.TaskException
Returns the value of this parameter as an array of objects which have resulted from the parsing of thewordsValue(uk.ac.starlink.task.Environment)
using the currently installedWordParser
. If no word parser is installed, this will have the same contents (Strings) as the words. If the required word count value of this parameter is non-negative, then the return value is guaranteed to contain that number of elements.- Parameters:
env
- execution environment- Returns:
- array of objects representing the value of this parameter
- Throws:
uk.ac.starlink.task.TaskException
-
stringToObject
public java.lang.String[] stringToObject(uk.ac.starlink.task.Environment env, java.lang.String sval) throws uk.ac.starlink.task.TaskException
- Specified by:
stringToObject
in classuk.ac.starlink.task.Parameter<java.lang.String[]>
- Throws:
uk.ac.starlink.task.TaskException
-
-