Class ParseContext<T>

  • Type Parameters:
    T - The type of the object being populated with parsed arguments

    public class ParseContext<T>
    extends Object
    Maintains the state of the parsing process.
    • Constructor Detail

      • ParseContext

        public ParseContext​(Class<T> classType,
                            String[] args,
                            Map<Class<?>,​TypeConverter<?>> typeConverters)
                     throws ParseException
        Create a new ParseContext for the given class type and string arguments.
        Parameters:
        classType - The class type which will be instantiated and populated with the given arguments
        args - The string arguments to parse
        typeConverters - The map of value parsers to use when parsing values
        Throws:
        MissingNoArgConstructorException - If the class type does not have a public default constructor
        ParseException
    • Method Detail

      • getInstance

        public T getInstance()
      • setOrderedValue

        public void setOrderedValue​(String stringValue)
                             throws ParseException
        Sets the value of the current ordered property in the parse context to the given string value.
        Parameters:
        stringValue - The string value to parse and set
        Throws:
        ParseException - If the value cannot be parsed
      • addToCollection

        protected Object addToCollection​(Field field,
                                         Object collection,
                                         Class<?> collectionType,
                                         Class<?> elementType,
                                         Object parsedValue)
        This is broken out into its own function because the annotations required for silencing the warnings cannot be used at the statement level.
        Parameters:
        collection - The collection which will be added to
      • setNamedValue

        public void setNamedValue​(String value)
                           throws ParseException
        Sets the value of the current named property in the parse context to the given value.
        Parameters:
        value - The value to set
        Throws:
        ParseException - If the value cannot be parsed
      • isBoolean

        public boolean isBoolean()
        Returns true if the current flag is a boolean flag.
        Returns:
        true if the current flag is a boolean flag
      • getRequiredFields

        public List<Field> getRequiredFields()
      • isHelpRequested

        public boolean isHelpRequested()
      • setHelpRequested

        public ParseContext<T> setHelpRequested​(boolean helpRequested)
      • isHelpToken

        public boolean isHelpToken​(String token)