name.kevinlocke.ultragetopt
Class CommandLineOption

java.lang.Object
  extended by name.kevinlocke.ultragetopt.CommandLineOption

public class CommandLineOption
extends java.lang.Object

Class representing a command-line option.

Author:
Kevin Locke <kwl7@cornell.edu>

Field Summary
protected  ArgumentDisposition argreq
          The argument requirement for this option.
protected  java.lang.String longopt
          The long option name for this option.
protected  java.lang.Character shortopt
          The short option character for this option.
 
Constructor Summary
CommandLineOption(java.lang.Character shortopt, java.lang.String longopt, ArgumentDisposition argreq)
          Construct a new command-line option.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Test if an object is representing the same command-line option.
 ArgumentDisposition getArgumentRequirement()
          Gets the argument requirements for this option.
 java.lang.String getLongOption()
          Gets the long-option character for this option.
 java.lang.Character getShortOption()
          Gets the short-option character for this option.
 int hashCode()
           
 boolean optionEncountered(java.lang.String argument)
          Callback mechanism for sub-classes.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

shortopt

protected final java.lang.Character shortopt
The short option character for this option.


longopt

protected final java.lang.String longopt
The long option name for this option.


argreq

protected final ArgumentDisposition argreq
The argument requirement for this option.

Constructor Detail

CommandLineOption

public CommandLineOption(java.lang.Character shortopt,
                         java.lang.String longopt,
                         ArgumentDisposition argreq)
Construct a new command-line option. An example invocation of this constructor would be new CommandLineOption('h', "help", Argument.NO_ARGUMENT)

Parameters:
shortopt - The short-option form for this option (or null if none)
longopt - The long-option form for this option (or null if none). Leader characters should be omitted (for example, use "help" instead of "--help")
argreq - The argument requirements of this option
Throws:
java.lang.IllegalArgumentException - if shortopt and longopt are both null (which would not represent any command-line option)
Method Detail

equals

public boolean equals(java.lang.Object obj)
Test if an object is representing the same command-line option.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to compare to this
Returns:
true if obj is a CommandLineOption with the same short and long options and the same argument requirement

hashCode

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

getLongOption

public java.lang.String getLongOption()
Gets the long-option character for this option.

Returns:
The long-option character for this option, or null if none

getShortOption

public java.lang.Character getShortOption()
Gets the short-option character for this option.

Returns:
The short-option character for this option, or null if none

getArgumentRequirement

public ArgumentDisposition getArgumentRequirement()
Gets the argument requirements for this option.

Returns:
The argument requirement of this option

optionEncountered

public boolean optionEncountered(java.lang.String argument)
                          throws InvalidOptionException
Callback mechanism for sub-classes. This method is currently empty, resulting in no action when this option is encountered. Sub-classes may override this method and invoke behavior as the options are encountered during parsing of the command-line.

Parameters:
argument - The argument to this option, or null if none
Returns:
true if command-line processing should continue, false otherwise
Throws:
InvalidOptionException - if the option (or its argument) is invalid in such a way that having the UltraGetopt constructor return would be meaningless (only thrown by user-implemented functions)