com.martiansoftware.jsap.stringparsers
Class EnumeratedStringParser

java.lang.Object
  extended bycom.martiansoftware.jsap.StringParser
      extended bycom.martiansoftware.jsap.stringparsers.EnumeratedStringParser

public class EnumeratedStringParser
extends StringParser

A StringParser that enforces a limited set of String options for its values.
These values are provided in the constructor together with one or two parameters
that control the processing of these values.

EnumeratedStringParser was generously contributed to JSAP by Klaus-Peter Berg of Siemens AG, Munich, Germany.

Since:
1.03
Version:
2.0
Author:
Klaus-Peter Berg, Siemens AG, Munich, Germany

Field Summary
static char CONSTRUCTOR_VALUE_SEPARATOR
          char used to separate enumerated values when they are supplied to the constructor
 
Constructor Summary
EnumeratedStringParser(String validOptionValues)
          Constructs a new instance of EnumeratedStringParser with parameter
"caseSensitive" set to false
and "checkOptionChars" set to true.
All command line arguments for this parser and the values provided
by the user in this constructor are converted to lower case.
EnumeratedStringParser(String validOptionValues, boolean caseSensitive)
          Constructs a new instance of EnumeratedStringParser with parameter "checkOptionChars" set to true.
EnumeratedStringParser(String validOptionValues, boolean caseSensitive, boolean checkOptionChars)
          Constructs a new instance of EnumeratedParameterParser.
 
Method Summary
 Object parse(String arg)
          Parses the specified argument, making sure it matches one of the valid options supplied to its constructor.
If the specified argument is not a valid option, a ParseException is thrown.
 
Methods inherited from class com.martiansoftware.jsap.StringParser
setUp, tearDown
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONSTRUCTOR_VALUE_SEPARATOR

public static final char CONSTRUCTOR_VALUE_SEPARATOR
char used to separate enumerated values when they are supplied to the constructor

See Also:
Constant Field Values
Constructor Detail

EnumeratedStringParser

public EnumeratedStringParser(String validOptionValues,
                              boolean caseSensitive,
                              boolean checkOptionChars)
                       throws IllegalArgumentException
Constructs a new instance of EnumeratedParameterParser.

Parameters:
caseSensitive - tells the parser whether the option value is case sensitive
checkOptionChars - tells the parser whether to check for Java identifier conformant characters.
Throws:
IllegalArgumentException - if the option value string has wrong format
or is empty

EnumeratedStringParser

public EnumeratedStringParser(String validOptionValues,
                              boolean caseSensitive)
                       throws IllegalArgumentException
Constructs a new instance of EnumeratedStringParser with parameter "checkOptionChars" set to true.

Parameters:
caseSensitive - tells the parser wether the option value is case sensitive
Throws:
IllegalArgumentException - if the option value string has wrong format
or is empty

EnumeratedStringParser

public EnumeratedStringParser(String validOptionValues)
                       throws IllegalArgumentException
Constructs a new instance of EnumeratedStringParser with parameter
"caseSensitive" set to false
and "checkOptionChars" set to true.
All command line arguments for this parser and the values provided
by the user in this constructor are converted to lower case.

Throws:
IllegalArgumentException - if the option value string has wrong format
or is empty
Method Detail

parse

public Object parse(String arg)
             throws ParseException
Parses the specified argument, making sure it matches one of the valid options supplied to its constructor.
If the specified argument is not a valid option, a ParseException is thrown.

Specified by:
parse in class StringParser
Parameters:
arg - the argument to parse
Returns:
the String resulting from the parsed argument.
Throws:
ParseException - if the specified argument cannot be parsed.


Copyright © 2002-2004, Martian Software, Inc.. All Rights Reserved.
For the latest version and documentation, please visit http://www.martiansoftware.com/jsap