uk.ac.starlink.ttools.task
Class WordsParameter

java.lang.Object
  extended by uk.ac.starlink.task.Parameter<String[]>
      extended by uk.ac.starlink.ttools.task.WordsParameter

public class WordsParameter
extends uk.ac.starlink.task.Parameter<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

Field Summary
 
Fields inherited from class uk.ac.starlink.task.Parameter
BY_NAME
 
Constructor Summary
WordsParameter(String name)
          Constructor.
 
Method Summary
 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.
 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 the wordsValue(uk.ac.starlink.task.Environment) using the currently installed WordParser.
 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(String wordUsage)
          Configures the usage of this parameter from usages for given words.
 String[] stringToObject(uk.ac.starlink.task.Environment env, String sval)
           
 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WordsParameter

public WordsParameter(String name)
Constructor.

Parameters:
name - parameter name
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(String wordUsage)
Configures the usage of this parameter from usages for given words.

Parameters:
wordUsage - per-word usage

wordsValue

public 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 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 the wordsValue(uk.ac.starlink.task.Environment) using the currently installed WordParser. 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 String[] stringToObject(uk.ac.starlink.task.Environment env,
                               String sval)
                        throws uk.ac.starlink.task.TaskException
Specified by:
stringToObject in class uk.ac.starlink.task.Parameter<String[]>
Throws:
uk.ac.starlink.task.TaskException


Copyright © 2018 Central Laboratory of the Research Councils. All Rights Reserved.