org.metasyntactic.utilities
Class Argument

java.lang.Object
  |
  +--org.metasyntactic.utilities.Argument

public class Argument
extends java.lang.Object

Argument is perhaps a confusing term to use for this class. Argument actually represents the switches (or non-switches) following a programname. In this example:

	 programname option1 option2 -f file1 -h --prefix=c:\,d:\,e:\ 
-f,-h,--prefix are all Arguments AND there is an anonymous Argument which immediately follows the programname. Here's the confusing part. The Arguments can take from 0 to UNLIMITED options. In the previous example file1 is an option of the Argument -f, c:\ d:\ and e:\ are options of --prefix AND option1 option2 are options of the program name. option1 option2 would be considered a non-switch Argument (where there can only be one) and -f, -h and --prefix would be considered switch Arguments.


Field Summary
static int UNLIMITED_OPTIONS
          Constant to be used with maxOptions to allow an arbitrary number of arguments to follow
 
Constructor Summary
Argument(char switchSymbol, java.lang.String switchName)
          Creates a new switch argument with no minimum, maximum, defaults, or explanation.
Argument(char switchSymbol, java.lang.String switchName, int minOptions, int maxOptions, java.lang.String[] defaultOptions, java.lang.String explanation)
          Creates a new switch argument.
Argument(char switchSymbol, java.lang.String switchName, java.lang.String explanation)
           
Argument(int minOptions, int maxOptions)
          Creates a new non-switch argument with no minimum, maximum, defaults, or explanation.
Argument(int minOptions, int maxOptions, java.lang.String explanation)
           
Argument(int minOptions, int maxOptions, java.lang.String[] defaultOptions, java.lang.String explanation)
          Creates a new non-switch argument
 
Method Summary
 boolean equals(Argument other)
           
 boolean equals(java.lang.Object obj)
          Two arguments are equals if all of their traits are identical.
 java.lang.String[] getDefaultOptions()
          The default Options for this Argument
 java.util.List getDefaultOptionsAsList()
           
 java.lang.String getExplanation()
          The explanation text for this Argument
 int getMaxOptions()
          The maximum # of Options this argument can take.
 int getMinOptions()
          The minimum # of Options this Arugment must take
 java.lang.String getSwitchName()
          Gets this fully qualified name of this switch
 char getSwitchSymbol()
          Gets the symbol for this Argument
 int hashCode()
           
 boolean isSwitch()
          Is this Argument a switch or not?
static void main(java.lang.String[] args)
           
 java.lang.String toString()
          Returns a string representation of this argument properly formatted whether or not it is a switch
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

UNLIMITED_OPTIONS

public static final int UNLIMITED_OPTIONS
Constant to be used with maxOptions to allow an arbitrary number of arguments to follow

See Also:
Constant Field Values
Constructor Detail

Argument

public Argument(char switchSymbol,
                java.lang.String switchName)
Creates a new switch argument with no minimum, maximum, defaults, or explanation.


Argument

public Argument(char switchSymbol,
                java.lang.String switchName,
                java.lang.String explanation)

Argument

public Argument(int minOptions,
                int maxOptions)
Creates a new non-switch argument with no minimum, maximum, defaults, or explanation.


Argument

public Argument(int minOptions,
                int maxOptions,
                java.lang.String explanation)

Argument

public Argument(char switchSymbol,
                java.lang.String switchName,
                int minOptions,
                int maxOptions,
                java.lang.String[] defaultOptions,
                java.lang.String explanation)
Creates a new switch argument.

Parameters:
switchSymbol - The char to use for the switch. example: 'h' for -h.
switchName - The fully qualified name of this switch. example: "help" for --help.
minOptions - The minimum number of Options that this Argument must take. Use 0 if no Options are required.
maxOptions - The maximum number of Options that this Argument can take. Use UNLIMITED_OPTIONS if the Argument can take an indeterminate amount of Options.
defaultOptions - The default Options that will be returned if the user leaves out this switch. If this is null then the user has to specify this switch.
explanation - The explanation used to explain what this switch does.

Argument

public Argument(int minOptions,
                int maxOptions,
                java.lang.String[] defaultOptions,
                java.lang.String explanation)
Creates a new non-switch argument

Parameters:
minOptions - The minimum number of Options that this Argument must take. Use 0 if no Options are required.
maxOptions - The maximum number of Options that this Argument can take. Use UNLIMITED_OPTIONS if the Argument can take an indeterminate amount of Options.
defaultOptions - The default Options that will be returned if the user leaves out this switch. If this is null then the user has to specify this switch.
explanation - The explanation used to explain what this switch does.
Method Detail

isSwitch

public boolean isSwitch()
Is this Argument a switch or not?

Returns:
Whether or not this argument is a switch

getSwitchSymbol

public char getSwitchSymbol()
Gets the symbol for this Argument

Returns:
The symbol if this is a switch or 0 if it isn't

getSwitchName

public java.lang.String getSwitchName()
Gets this fully qualified name of this switch

Returns:
The name if this is a switch, or null if this is a non-switch

getMinOptions

public int getMinOptions()
The minimum # of Options this Arugment must take

Returns:
The minimum # of Options required

getMaxOptions

public int getMaxOptions()
The maximum # of Options this argument can take. Users should test this against UNLIMITED_ARGUMENTS to see if this Argument can take UNLIMITED Options.

Returns:
The maximum # of Options this Argument can take

getDefaultOptions

public java.lang.String[] getDefaultOptions()
The default Options for this Argument

Returns:
The default Options for thi Argument

getDefaultOptionsAsList

public java.util.List getDefaultOptionsAsList()

getExplanation

public java.lang.String getExplanation()
The explanation text for this Argument

Returns:
The explanation text

equals

public boolean equals(java.lang.Object obj)
Two arguments are equals if all of their traits are identical.

Overrides:
equals in class java.lang.Object

equals

public boolean equals(Argument other)

toString

public java.lang.String toString()
Returns a string representation of this argument properly formatted whether or not it is a switch

Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

main

public static void main(java.lang.String[] args)