org.fraid.utils
Class CommandLineManager

java.lang.Object
  extended by org.fraid.utils.CommandLineManager

public class CommandLineManager
extends java.lang.Object

Extract and store command line parameters. Recognizes three kinds of entities: * parameters - a word immediately preceded by a dash '-'; * parameter values - a word without a dash, preceded by a parameter; * keys - parameter without a value; Example: in the command line: java MyExecutableClass -param1 value1 -key1 -key2 -param2 value2 -key1 -param1 value3 value4 -param1 and -param2 are parameters; -param1 has values value1 and value3 (arity = 2); -param2 has value value2 (arity = 1); -key1 and -key2 are keys (they are not followed by a value); the second occurance of -key1 will be ignorred; value4 is missplaced and wil be ignorred.


Field Summary
protected  java.util.Hashtable<java.lang.String,java.util.HashSet<java.lang.String>> mHash
           
protected  java.util.HashSet<java.lang.String> mUnusedParams
           
 
Constructor Summary
CommandLineManager(java.lang.String[] aCommandLineParams)
          Process the passed command line.
 
Method Summary
 boolean isParameterUsed(java.lang.String aParam)
          Use to check if a key is used.
 boolean isParamValueUsed(java.lang.String aParam, java.lang.String aValue)
          Use wnen the values passed with this parameter belong to a predefined set.
static void main(java.lang.String[] args)
          Test driver.
 int parameterArity(java.lang.String aParam)
          Can be used instead of isParameterUsed and check for return value 0
 void printAll()
          Prints what it has found on the command line.
 void printUnused()
          After you process the parameters you are interested in processing check with this, what extra parameters were passed (by mistake or whatever).
 java.lang.String value(java.lang.String aParam)
          Use when you anticipate a single value passed with this parameter (arity 1)
 java.util.Iterator values(java.lang.String aParam)
          Use when the values passed with this parameter are not from a predefined set i.e.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mHash

protected java.util.Hashtable<java.lang.String,java.util.HashSet<java.lang.String>> mHash

mUnusedParams

protected java.util.HashSet<java.lang.String> mUnusedParams
Constructor Detail

CommandLineManager

public CommandLineManager(java.lang.String[] aCommandLineParams)
                   throws UtilsException
Process the passed command line.

Parameters:
aCommandLineParams - a String[] value
Throws:
UtilsException - if an error occurs
Method Detail

isParameterUsed

public boolean isParameterUsed(java.lang.String aParam)
Use to check if a key is used.

Parameters:
aParam - a String value
Returns:
a boolean value

isParamValueUsed

public boolean isParamValueUsed(java.lang.String aParam,
                                java.lang.String aValue)
Use wnen the values passed with this parameter belong to a predefined set. Check the elements of the set one by one with this function.

Parameters:
aParam - a String value
aValue - a String value
Returns:
a boolean value

parameterArity

public int parameterArity(java.lang.String aParam)
Can be used instead of isParameterUsed and check for return value 0

Parameters:
aParam - a String value
Returns:
an int value

value

public java.lang.String value(java.lang.String aParam)
Use when you anticipate a single value passed with this parameter (arity 1)

Parameters:
aParam - a String value
Returns:
a String value

values

public java.util.Iterator values(java.lang.String aParam)
Use when the values passed with this parameter are not from a predefined set i.e. directory names etc.

Parameters:
aParam - a String value
Returns:
an Iterator value

printAll

public void printAll()
Prints what it has found on the command line.


printUnused

public void printUnused()
After you process the parameters you are interested in processing check with this, what extra parameters were passed (by mistake or whatever).


main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Test driver.

Parameters:
args - a String[] value
Throws:
java.lang.Exception - if an error occurs


Fraid (system and language). (C) 2003-2007 Ivaylo Iliev
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
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.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.