Class EnumeratedOption<E>

java.lang.Object
snaq.util.jclap.Option<E>
snaq.util.jclap.EnumeratedOption<E>
Type Parameters:
E - the return type of the option
Direct Known Subclasses:
EnumeratedIntegerOption, EnumeratedStringOption

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

    • EnumeratedOption

      public EnumeratedOption​(String shortName, String longName, String description, int minCount, int maxCount, Collection<E> allowedValues)
      Creates a new EnumeratedOption 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
    • EnumeratedOption

      public EnumeratedOption​(String shortName, String longName, String description, boolean mandatory, boolean allowMany, Collection<E> allowedValues)
      Creates a new EnumeratedOption 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
  • Method Details

    • isValueValid

      public boolean isValueValid​(E value, Locale locale)
      Parameters:
      value - value to check for validity
      locale - Locale to use for i18n (if needed)
      Returns:
      Whether the specified value is valid.
    • getAllowedValues

      public Collection<E> getAllowedValues()
      Returns an unmodifiable collection of the values that can be assigned to this option.
      Returns:
      collection of allowed option values
    • getAllowedValuesString

      public String getAllowedValuesString​(String prefix, String suffix, String separator)
      Returns a string denoting the values that can be assigned to this option.
      Parameters:
      prefix - prefix string for each allowed value
      suffix - suffix string for each allowed value
      separator - string to use for delimiting individual values
      Returns:
      A string denoting the values that can be assigned to this option.
    • getAllowedValuesString

      public String getAllowedValuesString()
      Returns:
      The default version of the string denoting the values that can be assigned to this option.
    • toString

      public String toString()
      Overrides:
      toString in class Option<E>