|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--com.g11ntoolkit.util.Arguments
A helper utility to manage the command line arguments presented to a program.
Utility like Unix getopt. This class has been adapted from the Arguments class provided by the Apache Software Foundation.
Usage:
int c
parseArgumentTokens(argv);
while((c = getArguments()) != -1 )
{
switch (c)
{
case 'v':
System.out.println( "v" );
break;
case 'V':
System.out.println( "V" );
break;
}
}
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
See License Agreement.
| Nested Class Summary | |
private class |
Arguments.Queue
Private class to handle the queue of arguments. |
| Field Summary | |
private int |
lastPopArgument
Contains the index of the last argument popped. |
private static java.util.logging.Logger |
log
The log used for all messages from this class. |
private static int |
maxIncrement
Contains the number of items by which to extend the Queue if it runs out of room. |
private java.lang.String[] |
messageArray
Contains the elements of a message to display. |
private Arguments.Queue |
queueOfOtherStringParameters
Contains all the arguments that don't go in the other 2 queues. |
private Arguments.Queue |
queueOfSwitches
Contains all the switch arguments. |
private Arguments.Queue |
queueStringParameters
Contains all the string arguments needed by the switch arguments. |
| Constructor Summary | |
Arguments()
Default constructor. |
|
| Method Summary | |
int |
getArguments()
Returns the number of switches in the arguments. |
java.lang.String |
getlistFiles()
Returns a list of the arguments that are strings and do not apply to a switch argument. |
java.lang.String |
getStringParameter()
Returns a String type parameter from the arguments. |
void |
parseArgumentTokens(java.lang.String[] arguments,
char[] argsWithOptions)
Takes the array of standard Args passed from main() and parses the switches and other arguments from the list. |
void |
printUsage()
Prints the usage variable to the console. |
void |
setUsage(java.lang.String[] message)
Sets the usage variable so we can show the user how to use the program. |
int |
stringParameterLeft()
Returns the count of how many parameters are left in the argument list. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private static java.util.logging.Logger log
private Arguments.Queue queueOfSwitches
private Arguments.Queue queueStringParameters
private Arguments.Queue queueOfOtherStringParameters
private java.lang.String[] messageArray
private int lastPopArgument
private static final int maxIncrement
Arguments.Queue.push(java.lang.Object),
Constant Field Values| Constructor Detail |
public Arguments()
| Method Detail |
public void parseArgumentTokens(java.lang.String[] arguments,
char[] argsWithOptions)
Args passed from main() and parses the switches and other arguments from the list.
The value -1 is a special flag that is used to indicate the beginning of the queue of flags and is also to tell the end of a group of switches.
This method will generate three internal queues.
For example: -dvV will hold d, v, V, -1.
-a -v -p myvalue test.xml test1.xml will contain test.xml test1.xml.
arguments - a String array specifying the argumentsargsWithOptions - a char array specifying the switches that have string options associated with them. One character per switch in each element of this array. May be null if no switches have options.public int getArguments()
public java.lang.String getStringParameter()
String type parameter from the arguments.
String type parameterpublic java.lang.String getlistFiles()
public int stringParameterLeft()
public void setUsage(java.lang.String[] message)
message - a String array specifying the usage text to displaypublic void printUsage()
Each element of the usage array is printed on a separate line.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||