scale.test
Class CmdParam

java.lang.Object
  extended by scale.test.CmdParam

public class CmdParam
extends java.lang.Object

This class provides standard processing of command line parameters.

$Id: CmdParam.java,v 1.43 2007-10-04 19:58:39 burrill Exp $

Copyright 2008 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.

This class provides standard processing of command line parameters. Command line parameters can be of the form

string
-s abcdefg
integer
-l 9
real
-prob 0.89
switch
-w
list
-i file1 file2 file3


Field Summary
static int INT
          Parameter is an integer.
static int LIST
          Parameter is a list of strings.
static int REAL
          Parameter is a real.
static int STRING
          Parameter is a String.
static int SWITCH
          Parameter is a switch.
 
Constructor Summary
CmdParam(java.lang.String longName, boolean optional, int type, java.lang.Object defaultValue, int helpMsg)
          Define a parameter.
CmdParam(java.lang.String name, boolean optional, int type, java.lang.Object defaultValue, java.lang.String description)
          Define a parameter.
 
Method Summary
 int getIntValue()
          Return the int value of the parameter.
 java.lang.String getStringValue()
          Return the string value of the parameter.
 Vector<java.lang.String> getStringValues()
          Return the string value of the parameter.
 java.lang.Object getValue()
          Return the value of the parameter.
static void parse(java.lang.String command, java.lang.String[] cmdParameters, CmdParam[] parameters)
          Parse a string for parameters.
static boolean parse(java.lang.String command, java.lang.String[] cmdParameters, CmdParam[] parameters, CmdParam unspecified)
          Parse a string for parameters.
 boolean specified()
          Return true if the parameter was specified.
 java.lang.String toString()
           
static void usage(java.io.PrintStream s, java.lang.String command, CmdParam[] parameters)
          Print out a usage message based upon the parameters.
static void usage(java.io.PrintStream s, java.lang.String command, CmdParam[] parameters, CmdParam unspecified)
          Print out a usage message based upon the parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STRING

public static final int STRING
Parameter is a String.

See Also:
Constant Field Values

INT

public static final int INT
Parameter is an integer.

See Also:
Constant Field Values

REAL

public static final int REAL
Parameter is a real.

See Also:
Constant Field Values

SWITCH

public static final int SWITCH
Parameter is a switch.

See Also:
Constant Field Values

LIST

public static final int LIST
Parameter is a list of strings.

See Also:
Constant Field Values
Constructor Detail

CmdParam

public CmdParam(java.lang.String longName,
                boolean optional,
                int type,
                java.lang.Object defaultValue,
                int helpMsg)
Define a parameter.

Parameters:
longName - of the parameter
optional - true if this is an optional parameter
type - the parameter type
defaultValue - the default value - may be null
helpMsg - an index to a description of the parameter - may be null
See Also:
Msg

CmdParam

public CmdParam(java.lang.String name,
                boolean optional,
                int type,
                java.lang.Object defaultValue,
                java.lang.String description)
Define a parameter.

Parameters:
name - of the parameter
optional - true if this is an optional parameter
type - the parameter type
defaultValue - the default value - may be null
description - a description of the parameter - may be null
See Also:
Msg
Method Detail

getValue

public java.lang.Object getValue()
Return the value of the parameter.


getIntValue

public int getIntValue()
Return the int value of the parameter.


getStringValue

public java.lang.String getStringValue()
Return the string value of the parameter.


getStringValues

public Vector<java.lang.String> getStringValues()
Return the string value of the parameter.


specified

public boolean specified()
Return true if the parameter was specified.


parse

public static void parse(java.lang.String command,
                         java.lang.String[] cmdParameters,
                         CmdParam[] parameters)
                  throws InvalidKeyException
Parse a string for parameters.

Parameters:
command - is the command used
cmdParameters - the array of strings specifying the command line parameters
parameters - an array of allowed parameters
Throws:
InvalidKeyException - if there is a command line parameter error

parse

public static boolean parse(java.lang.String command,
                            java.lang.String[] cmdParameters,
                            CmdParam[] parameters,
                            CmdParam unspecified)
                     throws InvalidKeyException
Parse a string for parameters.

Parameters:
command - is the command used
cmdParameters - the array of strings specifying the command line parameters
parameters - an array of allowed parameters
unspecified - is non-null if prameters may be supplied without switches
Returns:
true if system should terminate with status 0
Throws:
InvalidKeyException - if there is a command line parameter error

usage

public static void usage(java.io.PrintStream s,
                         java.lang.String command,
                         CmdParam[] parameters)
Print out a usage message based upon the parameters.

Parameters:
s - is the stream to be printed on
command - is the command name
parameters - is the array of parameter definitions

usage

public static void usage(java.io.PrintStream s,
                         java.lang.String command,
                         CmdParam[] parameters,
                         CmdParam unspecified)
Print out a usage message based upon the parameters.

Parameters:
s - is the stream to be printed on
command - is the command name
parameters - is the array of parameter definitions
unspecified - is non-null if prameters may be supplied without switches

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object