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
  • 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(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 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