public abstract class ProgramOptions extends Object
Modifier and Type | Class and Description |
---|---|
protected static class |
ProgramOptions.Option<T>
Encapsulation of an option name and type.
|
Modifier and Type | Field and Description |
---|---|
protected static String |
ORGANIZATION
Organization under which this program is developed.
|
protected static String |
ORGANIZATION_TEAM
Organization team that develops this program.
|
Constructor and Description |
---|
ProgramOptions() |
Modifier and Type | Method and Description |
---|---|
static <T> ProgramOptions.Option<T> |
createKey(String name,
Class<T> type,
String usage)
Helper creator of Option Hash map key objects.
|
Map<ProgramOptions.Option<?>,Object> |
getOptions() |
<T> T |
getValue(String optionname,
Class<T> optiontype)
Get the value for an option.
|
<T> void |
initValue(String optionname,
T optionvalue,
String usage)
Initialize an option.
|
protected static boolean |
isOptionValue(String[] args,
int index)
Check if the argument in the specified index is an assignable, non option
value.
|
abstract boolean |
parseCommandLine(String[] arguments)
Parse the program's command line options.
|
abstract void |
printUsage(PrintStream os)
Prints program's usage help message to the specified output stream.
|
protected static String |
removeQuotes(String str)
Removes single or double quotes from the start and end of an input
String . |
<T> void |
setValue(String optionname,
T optionvalue)
Set a value based only on option name and type.
|
protected abstract boolean |
validateOptions()
This is the program options validator and should be implemented by all
subclasses.
|
protected static final String ORGANIZATION
protected static final String ORGANIZATION_TEAM
public <T> void initValue(String optionname, T optionvalue, String usage) throws IllegalArgumentException
T
- the type of the option value.optionname
- The option name to set the value for.optionvalue
- The option value to set.usage
- the option usage text.IllegalArgumentException
- If any of the arguments is
null
.public <T> void setValue(String optionname, T optionvalue) throws IllegalArgumentException
T
- the type of the option value.optionname
- The option name.optionvalue
- The option value.IllegalArgumentException
- If any of the arguments is
null
.public <T> T getValue(String optionname, Class<T> optiontype)
T
- the type of the class type.optionname
- The option name to get the value of.optiontype
- The class type of the specified option.public final Map<ProgramOptions.Option<?>,Object> getOptions()
public static <T> ProgramOptions.Option<T> createKey(String name, Class<T> type, String usage)
T
- the option type class type.name
- Option name.type
- Option type.usage
- Option usage, null
if you want just a key for
retrieval.public abstract void printUsage(PrintStream os)
os
- the output stream to direct messages to.public abstract boolean parseCommandLine(String[] arguments)
arguments
- Array of String
containing the command line
arguments (as passed to main function of main application
class).true
on successful parsing, false
otherwise.protected static String removeQuotes(String str)
String
. Unfortunately the Java VM passes quoted command line
arguments to the application.protected static boolean isOptionValue(String[] args, int index)
args
- Arguments String
array.index
- Index of argument to check.true
if the value in the args_index position is OK,
false
otherwise.protected abstract boolean validateOptions()
true
if the options set via
setValue(String, Object)
are valid,
false
otherwise.Copyright © 2020. All rights reserved.