Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.dinopolis.util.commandarguments
Class CommandArguments  view CommandArguments download CommandArguments.java

java.lang.Object
  extended byorg.dinopolis.util.commandarguments.CommandArguments

public class CommandArguments
extends java.lang.Object

CommandArguments takes care of command line arguments and options. It checks, if arguments are valid and simplifies checking, if an argument is set or not.

There are two different kinds of arguments: those starting with one or two minus(es) ('-', '--') (called options here) and those without. The first type is used to set options, those without are 'real' arguments.

There are short and long options. Short options are only one character long and need to be prefixed by a single minus ('-'). When they are parsed, it makes no difference, if they are written separately or all in one: e.g. -dfl is equal to -d -f -l).

Long options (more than one letter) must be prefixed by two minuses ('--'): e.g. --recursive or --long.

There are options that stand just per se. Other options require to be followed by a value (a number or a string). E.g. --filename /home/username/log.txt or --port 1234.

Version:
$Id: CommandArguments.java,v 1.1.1.1 2003/01/10 15:33:38 cdaller Exp $

Field Summary
(package private)  java.util.Map args_
           
(package private)  java.util.Vector real_arguments_
          here, the arguments, which have no leading "-" or "--" are saved.
(package private)  java.util.Map valid_args_
           
 
Constructor Summary
CommandArguments(java.lang.String[] args, java.lang.String[] valid_args)
          Format of valid_args: 'x' argument 'x' is valid 'x#' argument 'x' is valid, when followed by a number (Integer).
CommandArguments(java.util.Vector args, java.lang.String[] valid_args)
          Convertes the Vector to a String[] and calls the other constructor.
 
Method Summary
 java.lang.String getArgumentAt(int position)
          Returns the argument (not option!) at the given position.
 java.util.Vector getArguments()
          Returns all argument (not options!).
 java.lang.Double getDoubleValue(java.lang.String option_name)
          Returns the value (String or Integer) of the given option or null if the option was not set.
 java.lang.Integer getIntegerValue(java.lang.String option_name)
          Returns the value of the given option or null if the option was not set.
 java.lang.String getStringValue(java.lang.String option_name)
          Returns the value of the given option or null if the option was not set.
 java.lang.Object getValue(java.lang.String option_name)
          Returns the value (String or Integer) of the given option or null if the option was not set.
 boolean isSet(java.lang.String option_name)
          Returns true when the given option (not argument!) was specified.
 int length()
          Returns the number of arguments (not options!).
private static java.lang.String[] vectorToStringArray(java.util.Vector vector)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

args_

java.util.Map args_

valid_args_

java.util.Map valid_args_

real_arguments_

java.util.Vector real_arguments_
here, the arguments, which have no leading "-" or "--" are saved.

Constructor Detail

CommandArguments

public CommandArguments(java.util.Vector args,
                        java.lang.String[] valid_args)
                 throws CommandArgumentException
Convertes the Vector to a String[] and calls the other constructor.


CommandArguments

public CommandArguments(java.lang.String[] args,
                        java.lang.String[] valid_args)
                 throws CommandArgumentException
Format of valid_args:
  • 'x' argument 'x' is valid
  • 'x#' argument 'x' is valid, when followed by a number (Integer).
  • 'x%' argument 'x' is valid, when followed by a number (Double).
  • 'x*' argument 'x' is valid, when followed by a string.
If an argument requires an additional argument (String or number), it must be separated by a whitespace for long and short options or can be appended directly only for short options (starting with '-').

Method Detail

isSet

public boolean isSet(java.lang.String option_name)
Returns true when the given option (not argument!) was specified.


getValue

public java.lang.Object getValue(java.lang.String option_name)
Returns the value (String or Integer) of the given option or null if the option was not set.


getStringValue

public java.lang.String getStringValue(java.lang.String option_name)
Returns the value of the given option or null if the option was not set.


getIntegerValue

public java.lang.Integer getIntegerValue(java.lang.String option_name)
Returns the value of the given option or null if the option was not set.


getDoubleValue

public java.lang.Double getDoubleValue(java.lang.String option_name)
Returns the value (String or Integer) of the given option or null if the option was not set.


getArgumentAt

public java.lang.String getArgumentAt(int position)
Returns the argument (not option!) at the given position.


getArguments

public java.util.Vector getArguments()
Returns all argument (not options!).


length

public int length()
Returns the number of arguments (not options!).


vectorToStringArray

private static java.lang.String[] vectorToStringArray(java.util.Vector vector)