com.ohrasys.app
Class AppOption

java.lang.Object
  extended by com.ohrasys.app.AppOption

public class AppOption
extends java.lang.Object

An object representing a command line option.


Field Summary
static int FLAG_TYPE
          Indicates the option is a simple flag
static int LIST_TYPE
          Indicates the option contains a list of arguments
static int OPTION_TYPE
          Indicates the option contains an argument
static int UNKNOWN
          Indicates the option type is not known
static int UNLIMITED_LENGTH
          Indicates that a list option has an unconstrained argument list length
 
Method Summary
static AppOption findListOption(AppOption[] options)
          Returns a list type application option if one exists in the list provided.
static AppOption findOption(java.lang.String name, AppOption[] options)
          Returns an option with the given name.
static AppOption getFlag(java.lang.String name)
          Creates a new flag type option.
 int getLen()
          Returns the number of data values associated with this option.
static AppOption getList()
          Creates a new list type option.
 java.lang.String getName()
          Returns the name of this option.
static AppOption getOption(java.lang.String name)
          Returns a named option having one value.
static AppOption getOption(java.lang.String name, int numvalues)
          Returns a named option having a finite number of values.
 int getType()
          Returns the type of this option.
 java.lang.String getValue()
          Returns the value of this option in a string representation.
static AppOption[] parseCLArgs(java.lang.String[] args, AppOption[] templates)
          Parses the command line arguments of an application and compares those options against a list of expected options.
 void setValue(java.lang.String value)
          Sets the value of this option.
 java.lang.String toString()
          Returns a string representation of the values associated with this option.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FLAG_TYPE

public static final int FLAG_TYPE
Indicates the option is a simple flag

See Also:
Constant Field Values

OPTION_TYPE

public static final int OPTION_TYPE
Indicates the option contains an argument

See Also:
Constant Field Values

LIST_TYPE

public static final int LIST_TYPE
Indicates the option contains a list of arguments

See Also:
Constant Field Values

UNKNOWN

public static final int UNKNOWN
Indicates the option type is not known

See Also:
Constant Field Values

UNLIMITED_LENGTH

public static final int UNLIMITED_LENGTH
Indicates that a list option has an unconstrained argument list length

See Also:
Constant Field Values
Method Detail

findListOption

public static AppOption findListOption(AppOption[] options)
Returns a list type application option if one exists in the list provided.

Parameters:
options - The options to search through.
Returns:
The first list type application option or null if none are found.

findOption

public static AppOption findOption(java.lang.String name,
                                   AppOption[] options)
Returns an option with the given name.

Parameters:
name - The option name to search for
options - The list of options to search through
Returns:
The named option from the list or null if it doesn't exist

getFlag

public static AppOption getFlag(java.lang.String name)
Creates a new flag type option. These types of options are used to indicate some application switch is either on or off.

Parameters:
name - The name of the option
Returns:
The option

getList

public static AppOption getList()
Creates a new list type option. These types of options are used to supply lists of data such as filenames as command line arguments

Returns:
The option

getOption

public static AppOption getOption(java.lang.String name)
Returns a named option having one value. An example may be a logfile option for a program.

program -log <logfile>

In this case the -log option has a length of one value of <logfile>.

Parameters:
name - The name of the option.
Returns:
The option.

getOption

public static AppOption getOption(java.lang.String name,
                                  int numvalues)
Returns a named option having a finite number of values. This is used to supply a finite list of arguments associated with a named option. An example may be a 'files' option for a diff program.

diff -files <file1> <file2>

In this case the -files option has a length of two values of <file1> and <file2>

Parameters:
name - The name of the option
numvalues - The number of values associated with the option.
Returns:
The option

parseCLArgs

public static AppOption[] parseCLArgs(java.lang.String[] args,
                                      AppOption[] templates)
                               throws AppException
Parses the command line arguments of an application and compares those options against a list of expected options.

Parameters:
args - The command line arguments to parse
templates - The template list of application options.
Returns:
A list of options that are present on the command line, are valid for the application and have data populated in them.
Throws:
AppException - If an error in processing occurs.

getLen

public int getLen()
Returns the number of data values associated with this option.

Returns:
The number of data values associated with this option.

getName

public java.lang.String getName()
Returns the name of this option.

Returns:
The name of this option.

getType

public int getType()
Returns the type of this option.

Returns:
The type of this option.

getValue

public java.lang.String getValue()
Returns the value of this option in a string representation.

Returns:
The value of this option.

setValue

public void setValue(java.lang.String value)
Sets the value of this option.

Parameters:
value - The new value of the option.

toString

public java.lang.String toString()
Returns a string representation of the values associated with this option.

Overrides:
toString in class java.lang.Object
Returns:
The values associated with this option.