Class 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​(java.lang.String name, java.lang.Class<W[]> arrayClazz, WordParser<W> parser)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static WordsParameter<java.lang.Boolean> createBooleanWordsParameter​(java.lang.String name)
      Returns an instance for which words are parsed as Booleans.
      static WordsParameter<java.lang.Double> createDoubleWordsParameter​(java.lang.String name)
      Returns an instance for which words are parsed as Doubles.
      static WordsParameter<java.lang.Integer> createIntegerWordsParameter​(java.lang.String name)
      Returns an instance for which words are parsed as Integers.
      static WordsParameter<java.lang.String> createStringWordsParameter​(java.lang.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.
      void setRequiredWordCount​(int nWords)
      Sets the number of words required from this parameter.
      void setWordUsage​(java.lang.String wordUsage)
      Configures the usage of this parameter from usages for given words.
      W[] stringToObject​(uk.ac.starlink.task.Environment env, java.lang.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, 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​(java.lang.String name,
                              java.lang.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 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
      • 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​(java.lang.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,
                                  java.lang.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
      • createStringWordsParameter

        public static WordsParameter<java.lang.String> createStringWordsParameter​(java.lang.String name)
        Returns an instance for which words are simply parsed as strings.
        Parameters:
        name - parameter name
        Returns:
        new WordsParameter
      • createIntegerWordsParameter

        public static WordsParameter<java.lang.Integer> createIntegerWordsParameter​(java.lang.String name)
        Returns an instance for which words are parsed as Integers.
        Parameters:
        name - parameter name
        Returns:
        new WordsParameter
      • createDoubleWordsParameter

        public static WordsParameter<java.lang.Double> createDoubleWordsParameter​(java.lang.String name)
        Returns an instance for which words are parsed as Doubles.
        Parameters:
        name - parameter name
        Returns:
        new WordsParameter
      • createBooleanWordsParameter

        public static WordsParameter<java.lang.Boolean> createBooleanWordsParameter​(java.lang.String name)
        Returns an instance for which words are parsed as Booleans.
        Parameters:
        name - parameter name
        Returns:
        new WordsParameter