# 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

Constructors
Constructor
Description
`WordsParameter(String name, Class<W[]> arrayClazz, WordParser<W> parser)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`static WordsParameter<Boolean>`
`createBooleanWordsParameter(String name)`
Returns an instance for which words are parsed as Booleans.
`static WordsParameter<Double>`
`createDoubleWordsParameter(String name)`
Returns an instance for which words are parsed as Doubles.
`static WordsParameter<Integer>`
`createIntegerWordsParameter(String name)`
Returns an instance for which words are parsed as Integers.
`static WordsParameter<String>`
`createStringWordsParameter(String name)`
Returns an instance for which words are simply parsed as strings.
`int`
`getRequiredWordCount()`
Returns the number of words required from this parameter.
`WordParser<W>`
`getWordParser()`
Returns the parser which is being used to validate and to parse each word in the supplied value string.
`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`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### WordsParameter

public WordsParameter(String name, Class<W[]> arrayClazz, WordParser<W> parser)
Constructor.

Parameters:
  `name` - parameter name
  `arrayClazz` - array output class of this parameter
  `parser` - 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

public WordParser<W> getWordParser()
Returns the parser which is being used to validate and to parse each word in the supplied value string.

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 W[] wordsValue(uk.ac.starlink.task.Environment env) throws uk.ac.starlink.task.TaskException
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(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 class `uk.ac.starlink.task.Parameter<W[]>`
Throws:
  `uk.ac.starlink.task.TaskException`

### objectToString

public String objectToString(uk.ac.starlink.task.Environment env, W[] words)

Overrides:
  `objectToString` in class `uk.ac.starlink.task.Parameter<W[]>`

### createStringWordsParameter

public static WordsParameter<String> createStringWordsParameter(String name)
Returns an instance for which words are simply parsed as strings.

Parameters:
  `name` - parameter name
Returns:
  new WordsParameter

### createIntegerWordsParameter

public static WordsParameter<Integer> createIntegerWordsParameter(String name)
Returns an instance for which words are parsed as Integers.

Parameters:
  `name` - parameter name
Returns:
  new WordsParameter

### createDoubleWordsParameter

public static WordsParameter<Double> createDoubleWordsParameter(String name)
Returns an instance for which words are parsed as Doubles.

Parameters:
  `name` - parameter name
Returns:
  new WordsParameter

### createBooleanWordsParameter

public static WordsParameter<Boolean> createBooleanWordsParameter(String name)
Returns an instance for which words are parsed as Booleans.

Parameters:
  `name` - parameter name
Returns:
  new WordsParameter