Class AbstractChoiceParameter<T,C>

java.lang.Object
uk.ac.starlink.task.Parameter<T>
uk.ac.starlink.task.AbstractChoiceParameter<T,C>
Type Parameters:
T - parameter result type
C - option type
Direct Known Subclasses:
ChoiceParameter, MultiChoiceParameter

public abstract class AbstractChoiceParameter<T,C> extends Parameter<T>
Abstract superclass for parameters that permit choices from a given list of typed options.
Since:
17 Dec 2021
Author:
Mark Taylor
  • Constructor Details

    • AbstractChoiceParameter

      protected AbstractChoiceParameter(String name, Class<T> paramClazz, Class<C> optClazz, C[] options)
      Constructor.
      Parameters:
      name - parameter name
      paramClazz - class of result type for this parameter
      optClazz - class of typed option
      options - initial list of typed options available
  • Method Details

    • addOption

      public void addOption(C option, String name)
      Adds an option value to this parameter with a given name. The name is the parameter value string used to identify this option.
      Parameters:
      option - option object
      name - label for option
    • addOption

      public void addOption(C option)
      Adds an option value to this parameter. The option's name will be determined by this object's stringifyOption(C) method.
      Parameters:
      option - option object
    • clearOptions

      public void clearOptions()
      Clears the list of known options.
    • getOptionNames

      public String[] getOptionNames()
      Returns an array of the string values of options accepted by this parameter.
      Returns:
      permitted options, stringified
    • getOptions

      public C[] getOptions()
      Returns an array of the option objects which may form the values of this parameter.
      Returns:
      permitted options
    • getOptionValueList

      public Collection<C> getOptionValueList()
      Returns a collection of the option objects which may form the values of this parameter.
      Returns:
      permitted options
    • getName

      public String getName(C option)
      Converts an option value object to a string which is used to identify it as a string value of this parameter.
      Parameters:
      option - option value
      Returns:
      string representation
    • stringifyOption

      public String stringifyOption(C option)
      Determines how an option will be represented as a string value of this parameter if no name has explicitly been supplied. The default implementation is String.valueOf(option), but this may be overrridden.
      Parameters:
      option - option value
      Returns:
      string representation of option
    • getOption

      public C getOption(String name)
      Returns the option value associated with a given string by this parameter. Null is returned if none of the options added so far has a name as supplied. Name matching is case-insensitive.
      Parameters:
      name - name of option which has been added
      Returns:
      corresponding option object
    • stringToChoice

      protected C stringToChoice(String sval) throws ParameterValueException
      Converts a supplied string to an option value for this parameter, or throws a ParameterValueException if it is not suitable.
      Parameters:
      sval - option name
      Returns:
      option value, not null
      Throws:
      ParameterValueException - if no such option
    • choiceToString

      protected String choiceToString(C objVal)
      Provides a string representation of a given typed value for this parameter.
      Parameters:
      objVal - typed option
      Returns:
      string representation