Class CaseInsensitiveEnumArgumentType<T extends Enum<T>>

java.lang.Object
net.sourceforge.argparse4j.impl.type.CaseInsensitiveEnumArgumentType<T>
All Implemented Interfaces:
ArgumentType<T>, MetavarInference
Direct Known Subclasses:
CaseInsensitiveEnumNameArgumentType, CaseInsensitiveEnumStringArgumentType

public class CaseInsensitiveEnumArgumentType<T extends Enum<T>> extends Object implements ArgumentType<T>, MetavarInference
  • Field Details

    • type_

      protected Class<T extends Enum<T>> type_
    • lowerCasingLocale_

      private final Locale lowerCasingLocale_
  • Constructor Details

    • CaseInsensitiveEnumArgumentType

      @Deprecated public CaseInsensitiveEnumArgumentType(Class<T> type)
      Deprecated.
      Use one of the subclasses, which always convert case correctly.

      Do not use. This constructor creates a case insensitive enum name argument type, but converts the enum names and the values passed on the command line to lower case in a way that depends on the current user locale. This may result in values not matching an enum name if the program is run by a user with a different locale.

      Parameters:
      type - the enum type.
    • CaseInsensitiveEnumArgumentType

      protected CaseInsensitiveEnumArgumentType(Class<T> type, Locale lowerCasingLocale)

      Create an instance.

      Parameters:
      type - the enum type.
      lowerCasingLocale - the locale to use for converting to lower case. Sub classes should always pass Locale.ROOT.
      Since:
      0.8.0
  • Method Details

    • convert

      public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException
      Description copied from interface: ArgumentType

      Converts value to appropriate type.

      If the objects derived from RuntimeException are thrown in conversion because of invalid input from command line, subclass must catch these exceptions and wrap them in ArgumentParserException and give simple error message to explain what happened briefly.

      Specified by:
      convert in interface ArgumentType<T extends Enum<T>>
      Parameters:
      parser - The parser.
      arg - The argument this type attached to.
      value - The attribute value.
      Returns:
      Converted object.
      Throws:
      ArgumentParserException - If conversion fails.
    • toStringRepresentation

      protected String toStringRepresentation(T t)

      Convert the given enum value to its string representation.

      Parameters:
      t - the enum value to convert.
      Returns:
      the string representation of t.
      Since:
      0.8.0
    • inferMetavar

      public String[] inferMetavar()

      Infers metavar based on given type.

      The inferred metavar contains all enum constant string representation.

      Specified by:
      inferMetavar in interface MetavarInference
      Returns:
      inferred array of metavar strings, or null if there is no metavar inferred.
      Since:
      0.7.0
      See Also:
    • getStringRepresentations

      protected Object[] getStringRepresentations()

      Get the objects to be used to generate the String representations of all enum constants. Object.toString() will be invoked on these objects to obtain the actual String representation.

      Returns:
      The objects used to generate String representations.
      Since:
      0.8.0
    • toCaseInsensitiveForm

      private String toCaseInsensitiveForm(String value)
      Get the String representation of the given value.
      Parameters:
      value - The value for which to get the String representation.
      Returns:
      The String representation of value.