Class AbstractChoiceParameter<T,​C>

  • Type Parameters:
    C - option type
    T - parameter result 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 Detail

      • AbstractChoiceParameter

        protected AbstractChoiceParameter​(java.lang.String name,
                                          java.lang.Class<T> paramClazz,
                                          java.lang.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 Detail

      • addOption

        public void addOption​(C option,
                              java.lang.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 java.lang.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 java.util.Collection<C> getOptionValueList()
        Returns a collection of the option objects which may form the values of this parameter.
        Returns:
        permitted options
      • getName

        public java.lang.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 java.lang.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​(java.lang.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​(java.lang.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 java.lang.String choiceToString​(C objVal)
        Provides a string representation of a given typed value for this parameter.
        Parameters:
        objVal - typed option
        Returns:
        string representation