uk.ac.starlink.ttools.task
Class WordsParameter

java.lang.Object
  extended by uk.ac.starlink.task.Parameter
      extended by uk.ac.starlink.ttools.task.WordsParameter

public class WordsParameter
extends uk.ac.starlink.task.Parameter

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
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 setValueFromString(uk.ac.starlink.task.Environment env, String sval)
           
 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[] wordsValue(uk.ac.starlink.task.Environment env)
          Returns the value of this parameter as an array of words.
 
Methods inherited from class uk.ac.starlink.task.Parameter
checkGotValue, clearValue, getDefault, getDescription, getName, getPosition, getPreferExplicit, getPrompt, getUsage, isNullPermitted, setDefault, setDescription, setDescription, setGotValue, setName, setNullPermitted, setPosition, setPreferExplicit, setPrompt, setStringValue, setUsage, stringValue, 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
Returns the value of this parameter as an array of 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 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

setValueFromString

public void setValueFromString(uk.ac.starlink.task.Environment env,
                               String sval)
                        throws uk.ac.starlink.task.TaskException
Overrides:
setValueFromString in class uk.ac.starlink.task.Parameter
Throws:
uk.ac.starlink.task.TaskException


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