Package uk.ac.starlink.ttools.task
Class WordsParameter<W>
java.lang.Object
uk.ac.starlink.task.Parameter<W[]>
uk.ac.starlink.ttools.task.WordsParameter<W>
- Type Parameters:
W
- parsed type of each word
public class WordsParameter<W>
extends uk.ac.starlink.task.Parameter<W[]>
Parameter which can split its value up into an array of words,
each parsed as a parameterised type.
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
ConstructorsConstructorDescriptionWordsParameter
(String name, Class<W[]> arrayClazz, WordParser<W> parser) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic WordsParameter
<Boolean> Returns an instance for which words are parsed as Booleans.static WordsParameter
<Double> Returns an instance for which words are parsed as Doubles.static WordsParameter
<Integer> Returns an instance for which words are parsed as Integers.static WordsParameter
<String> Returns an instance for which words are simply parsed as strings.int
Returns the number of words required from this parameter.Returns the parser which is being used to validate and to parse each word in the supplied value string.objectToString
(uk.ac.starlink.task.Environment env, W[] words) void
setRequiredWordCount
(int nWords) Sets the number of words required from this parameter.void
setWordUsage
(String wordUsage) Configures the usage of this parameter from usages for given words.W[]
stringToObject
(uk.ac.starlink.task.Environment env, String sval) W[]
wordsValue
(uk.ac.starlink.task.Environment env) Returns the typed value of this parameter.Methods inherited from class uk.ac.starlink.task.Parameter
clearValue, getDescription, getName, getPosition, getPreferExplicit, getPrompt, getStringDefault, getUsage, getValueClass, isNullPermitted, objectValue, setDescription, setDescription, setName, setNullPermitted, setPosition, setPreferExplicit, setPrompt, setStringDefault, setUsage, setValue, setValueFromObject, setValueFromString, stringValue, toArray, toString
-
Constructor Details
-
WordsParameter
Constructor.- Parameters:
name
- parameter namearrayClazz
- array output class of this parameterparser
- converts each input word string to a typed value
-
-
Method Details
-
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
-
getWordParser
Returns the parser which is being used to validate and to parse each word in the supplied value string.- Returns:
- word parser
-
setWordUsage
Configures the usage of this parameter from usages for given words.- Parameters:
wordUsage
- per-word usage
-
wordsValue
Returns the typed value of this parameter. If the required word count value of this parameter is non-negative, then the return value is guaranteed to contain that number of elements.This is just an alias for
Parameter.objectValue(uk.ac.starlink.task.Environment)
.- Parameters:
env
- execution environment- Returns:
- array of words constituting the value of this parameter
- Throws:
uk.ac.starlink.task.TaskException
-
stringToObject
public W[] stringToObject(uk.ac.starlink.task.Environment env, String sval) throws uk.ac.starlink.task.TaskException - Specified by:
stringToObject
in classuk.ac.starlink.task.Parameter<W[]>
- Throws:
uk.ac.starlink.task.TaskException
-
objectToString
- Overrides:
objectToString
in classuk.ac.starlink.task.Parameter<W[]>
-
createStringWordsParameter
Returns an instance for which words are simply parsed as strings.- Parameters:
name
- parameter name- Returns:
- new WordsParameter
-
createIntegerWordsParameter
Returns an instance for which words are parsed as Integers.- Parameters:
name
- parameter name- Returns:
- new WordsParameter
-
createDoubleWordsParameter
Returns an instance for which words are parsed as Doubles.- Parameters:
name
- parameter name- Returns:
- new WordsParameter
-
createBooleanWordsParameter
Returns an instance for which words are parsed as Booleans.- Parameters:
name
- parameter name- Returns:
- new WordsParameter
-