Class CaseInsensitiveEnumArgumentType<T extends java.lang.Enum<T>>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Locale lowerCasingLocale_  
      protected java.lang.Class<T> type_  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        CaseInsensitiveEnumArgumentType​(java.lang.Class<T> type)
      Deprecated.
      Use one of the subclasses, which always convert case correctly.
      protected CaseInsensitiveEnumArgumentType​(java.lang.Class<T> type, java.util.Locale lowerCasingLocale)
      Create an instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T convert​(ArgumentParser parser, Argument arg, java.lang.String value)
      Converts value to appropriate type.
      protected java.lang.Object[] getStringRepresentations()
      Get the objects to be used to generate the String representations of all enum constants.
      java.lang.String[] inferMetavar()
      Infers metavar based on given type.
      private java.lang.String toCaseInsensitiveForm​(java.lang.String value)
      Get the String representation of the given value.
      protected java.lang.String toStringRepresentation​(T t)
      Convert the given enum value to its string representation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • type_

        protected java.lang.Class<T extends java.lang.Enum<T>> type_
      • lowerCasingLocale_

        private final java.util.Locale lowerCasingLocale_
    • Constructor Detail

      • CaseInsensitiveEnumArgumentType

        @Deprecated
        public CaseInsensitiveEnumArgumentType​(java.lang.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​(java.lang.Class<T> type,
                                                  java.util.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 Detail

      • convert

        public T convert​(ArgumentParser parser,
                         Argument arg,
                         java.lang.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 java.lang.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 java.lang.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 java.lang.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:
        MetavarInference.inferMetavar()
      • getStringRepresentations

        protected java.lang.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 java.lang.String toCaseInsensitiveForm​(java.lang.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.