Package pro.johndunlap.getopt
Class ParseContext<T>
- java.lang.Object
-
- pro.johndunlap.getopt.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 Summary
Constructors Constructor Description ParseContext(Class<T> classType, String[] args, Map<Class<?>,TypeConverter<?>> typeConverters)Create a new ParseContext for the given class type and string arguments.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ObjectaddToCollection(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.TgetInstance()Stack<String>getQueue()List<Field>getRequiredFields()booleanisBoolean()Returns true if the current flag is a boolean flag.booleanisHelpRequested()booleanisHelpToken(String token)protected Objectparse(String value, Class<?> fieldType, TypeConverter<?> typeConverter)ParseContext<T>setCurrentName(String currentName)ParseContext<T>setHelpRequested(boolean helpRequested)voidsetNamedValue(String value)Sets the value of the current named property in the parse context to the given value.voidsetOrderedValue(String stringValue)Sets the value of the current ordered property in the parse context to the given string value.
-
-
-
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 argumentsargs- The string arguments to parsetypeConverters- The map of value parsers to use when parsing values- Throws:
MissingNoArgConstructorException- If the class type does not have a public default constructorParseException
-
-
Method Detail
-
setCurrentName
public ParseContext<T> setCurrentName(String currentName)
-
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
-
parse
protected Object parse(String value, Class<?> fieldType, TypeConverter<?> typeConverter) throws ParseException
- Throws:
ParseException
-
isBoolean
public boolean isBoolean()
Returns true if the current flag is a boolean flag.- Returns:
- true if the current flag is a boolean flag
-
isHelpRequested
public boolean isHelpRequested()
-
setHelpRequested
public ParseContext<T> setHelpRequested(boolean helpRequested)
-
isHelpToken
public boolean isHelpToken(String token)
-
-