Class EnumeratedStringOption


public final class EnumeratedStringOption
extends EnumeratedOption<String>
Implementation of an Option with value restricted to a specified enumeration of type String.
Author:
Giles Winstanley
  • Constructor Details

    • EnumeratedStringOption

      public EnumeratedStringOption​(String shortName, String longName, String description, int minCount, int maxCount, Collection<String> allowedValues, boolean ignoreCase)
      Creates a new EnumeratedStringOption instance.
      Parameters:
      shortName - short name of the option (e.g. -t)
      longName - long name of the option (e.g. --type)
      description - helpful description of the option (printed for usage message)
      minCount - minimum number of occurrences required for this option
      maxCount - maximum number of occurrences required for this option
      allowedValues - collection of possible values this option can take
      ignoreCase - whether to ignore the case in string evaluations
    • EnumeratedStringOption

      public EnumeratedStringOption​(String shortName, String longName, String description, boolean mandatory, boolean allowMany, Collection<String> allowedValues, boolean ignoreCase)
      Creates a new EnumeratedStringOption instance.
      Parameters:
      shortName - short name of the option (e.g. -t)
      longName - long name of the option (e.g. --type)
      description - helpful description of the option (printed for usage message)
      mandatory - whether this option must be specified
      allowMany - whether this option can take more than one value (i.e. be specified more than once)
      allowedValues - collection of possible values this option can take
      ignoreCase - whether to ignore the case in string evaluations
  • Method Details

    • isValueValid

      public boolean isValueValid​(String value, Locale locale)
      Overrides:
      isValueValid in class EnumeratedOption<String>
      Parameters:
      value - value to check for validity
      locale - Locale to use for i18n (if needed)
      Returns:
      Whether the specified value is valid.
    • parseValue

      protected String parseValue​(String arg, Locale locale) throws OptionException
      Parses the argument string for an option value, optionally using the specified locale for reference (e.g. for date parsing).
      Specified by:
      parseValue in class Option<String>
      Parameters:
      arg - string argument from which a value is to be parsed
      locale - locale as specified when initializing the CLAParser instance
      Returns:
      Value of the parsed argument string
      Throws:
      OptionException - if a problem occurs while parsing the argument string
    • getType

      public Class<String> getType()
      Returns the class type of value this option can take.
      Specified by:
      getType in class Option<String>
      Returns:
      Class instance
    • getAllowedValuesString

      public String getAllowedValuesString()
      Returns the default version of the string denoting the values that can be assigned to this option.
      Overrides:
      getAllowedValuesString in class EnumeratedOption<String>
      Returns:
      comma-separated quoted string of allowed values