Class EnumeratedStringParser

java.lang.Object
com.martiansoftware.jsap.StringParser
com.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

    Fields
    Modifier and Type Field Description
    static char CONSTRUCTOR_VALUE_SEPARATOR
    char used to separate enumerated values when they are supplied to the constructor
  • Constructor Summary

    Constructors
    Constructor Description
    EnumeratedStringParser​(java.lang.String validOptionValues)
    Deprecated.
    EnumeratedStringParser​(java.lang.String validOptionValues, boolean caseSensitive)
    Deprecated.
    EnumeratedStringParser​(java.lang.String validOptionValues, boolean caseSensitive, boolean checkOptionChars)
  • Method Summary

    Modifier and Type Method Description
    static EnumeratedStringParser getParser​(java.lang.String validOptionValues)
    Returns an EnumeratedParameterParser with parameter "caseSensitive" set to false and "checkOptionChars" set to true.
    static EnumeratedStringParser getParser​(java.lang.String validOptionValues, boolean caseSensitive)
    Returns an EnumeratedParameterParser with parameter "checkOptionChars" set to true.
    static EnumeratedStringParser getParser​(java.lang.String validOptionValues, boolean caseSensitive, boolean checkOptionChars)
    Returns an EnumeratedParameterParser.
    java.lang.Object parse​(java.lang.String arg)
    Parses the specified argument, making sure it matches one of the valid options supplied to its constructor.

    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 Details

    • 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 Details

    • EnumeratedStringParser

      public EnumeratedStringParser​(java.lang.String validOptionValues, boolean caseSensitive, boolean checkOptionChars) throws java.lang.IllegalArgumentException
      Constructs a new instance of EnumeratedParameterParser.
      Parameters:
      validOptionValues - a string that contains valid values for an option in the format "value_1;value_2;..;value_n"; spaces between values are allowed to make things more readable, e.g., "value_1; value_2"; option values have to be constructed using Java identifier characters if the checkOptionChars parameter tells the parser to do this.
      caseSensitive - tells the parser whether the option value is case sensitive
      checkOptionChars - tells the parser whether to check for Java identifier conformant characters.
      Throws:
      java.lang.IllegalArgumentException - if the option value string has wrong format or is empty
    • EnumeratedStringParser

      public EnumeratedStringParser​(java.lang.String validOptionValues, boolean caseSensitive) throws java.lang.IllegalArgumentException
      Deprecated.
      Constructs a new instance of EnumeratedStringParser.
      Throws:
      java.lang.IllegalArgumentException
    • EnumeratedStringParser

      public EnumeratedStringParser​(java.lang.String validOptionValues) throws java.lang.IllegalArgumentException
      Deprecated.
      Constructs a new instance of EnumeratedStringParser.
      Throws:
      java.lang.IllegalArgumentException
  • Method Details

    • getParser

      public static EnumeratedStringParser getParser​(java.lang.String validOptionValues, boolean caseSensitive, boolean checkOptionChars) throws java.lang.IllegalArgumentException
      Returns an EnumeratedParameterParser.
      Parameters:
      validOptionValues - a string that contains valid values for an option in the format "value_1;value_2;..;value_n"; spaces between values are allowed to make things more readable, e.g., "value_1; value_2"; option values have to be constructed using Java identifier characters if the checkOptionChars parameter tells the parser to do this.
      caseSensitive - tells the parser whether the option value is case sensitive
      checkOptionChars - tells the parser whether to check for Java identifier conformant characters.
      Throws:
      java.lang.IllegalArgumentException - if the option value string has wrong format or is empty
    • getParser

      public static EnumeratedStringParser getParser​(java.lang.String validOptionValues, boolean caseSensitive) throws java.lang.IllegalArgumentException
      Returns an EnumeratedParameterParser with parameter "checkOptionChars" set to true.
      Parameters:
      validOptionValues - a string that contains valid values for an option in the format "value_1;value_2;..;value_n"; spaces between values are allowed to make things more readable, e.g., "value_1; value_2"; option values have to be constructed using Java identifier characters.
      caseSensitive - tells the parser wether the option value is case sensitive
      Throws:
      java.lang.IllegalArgumentException - if the option value string has wrong format or is empty
    • getParser

      public static EnumeratedStringParser getParser​(java.lang.String validOptionValues) throws java.lang.IllegalArgumentException
      Returns an EnumeratedParameterParser 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 the returned parser are converted to lower case.
      Parameters:
      validOptionValues - a string that contains valid values for an option in the format "value_1;value_2;..;value_n"; spaces between values are allowed to make things more readable, e.g., "value_1; value_2"; option values have to be constructed using Java identifier characters.
      Throws:
      java.lang.IllegalArgumentException - if the option value string has wrong format or is empty
    • parse

      public java.lang.Object parse​(java.lang.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.