edu.byu.ece.edif.util.jsap
Class BoundedIntegerStringParser

java.lang.Object
  extended by com.martiansoftware.jsap.StringParser
      extended by com.martiansoftware.jsap.stringparsers.IntegerStringParser
          extended by edu.byu.ece.edif.util.jsap.BoundedIntegerStringParser

public class BoundedIntegerStringParser
extends com.martiansoftware.jsap.stringparsers.IntegerStringParser

A StringParser for parsing Integers with optional minimum and maximum values. The parse(String) method delegates the actual parsing to new Integer(String). If new Integer(String) throws a NumberFormatException, it is encapsulated in a ParseException and re-thrown. Also, if the parameter is lower than the minimum or higher than the maximum, a ParseException is thrown.

The default minimum limit is Integer.MIN_VALUE and the default maximum limit is Integer.MAX_VALUE.

Author:
James Carroll, Brigham Young University
See Also:
StringParser, IntegerStringParser, Integer

Field Summary
protected  java.lang.Boolean includeMax
          If true, the valid range includes the maximum value.
protected  java.lang.Boolean includeMin
          If true, the valid range includes the minimum value.
protected  java.lang.Integer max
          Maximum acceptable value.
protected  java.lang.Integer min
          Minimum acceptable value.
protected  java.lang.String range
           Text representation of the range.
 
Constructor Summary
BoundedIntegerStringParser(java.lang.Integer min, java.lang.Integer max, java.lang.Boolean includeMin, java.lang.Boolean includeMax)
          Deprecated. Use getParser(Integer, Integer, Boolean, Boolean).
 
Method Summary
static BoundedIntegerStringParser getParser()
           
static BoundedIntegerStringParser getParser(java.lang.Integer min, java.lang.Integer max)
           
static BoundedIntegerStringParser getParser(java.lang.Integer min, java.lang.Integer max, java.lang.Boolean includeMin, java.lang.Boolean includeMax)
           
 java.lang.String getRange()
           
 java.lang.Object parse(java.lang.String arg)
          Parses the specified argument into a Integer.
 
Methods inherited from class com.martiansoftware.jsap.StringParser
setUp, tearDown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

includeMin

protected java.lang.Boolean includeMin
If true, the valid range includes the minimum value.


includeMax

protected java.lang.Boolean includeMax
If true, the valid range includes the maximum value.


min

protected java.lang.Integer min
Minimum acceptable value.


max

protected java.lang.Integer max
Maximum acceptable value.


range

protected java.lang.String range

Text representation of the range.

Examples:

[0,1]
Zero to one, inclusive
(-100,100)
-100 to 100, non-inclusive
[3.14,6.28)
3.14 to 6.28, including 3.14 and not including 6.28

Constructor Detail

BoundedIntegerStringParser

@Deprecated
public BoundedIntegerStringParser(java.lang.Integer min,
                                             java.lang.Integer max,
                                             java.lang.Boolean includeMin,
                                             java.lang.Boolean includeMax)
                           throws java.lang.IllegalArgumentException
Deprecated. Use getParser(Integer, Integer, Boolean, Boolean).

Returns a BoundedIntegerStringParser with the specified minimum and maximum values. Also, the minimum and maximum can each optionally be inclusive or non-inclusive.

Parameters:
min - Minimum acceptable value. If null, the minimum will be set to Integer.MIN_VALUE
max - Maximum acceptable value. If null, the maximum will be set to Integer.MAX_VALUE
includeMax - Determines if max should be considered part of the valid range. If true, the valid range includes max. If null, includeMax will default to true.
Throws:
java.lang.IllegalArgumentException - if min is greater than max.
Method Detail

getParser

public static BoundedIntegerStringParser getParser(java.lang.Integer min,
                                                   java.lang.Integer max,
                                                   java.lang.Boolean includeMin,
                                                   java.lang.Boolean includeMax)
                                            throws java.lang.IllegalArgumentException
Parameters:
min - Minimum acceptable value. If null, the minimum will be set to Integer.MIN_VALUE
max - Maximum acceptable value. If null, the maximum will be set to Integer.MAX_VALUE
includeMin - Determines if min should be considered part of the valid range. If true, the valid range includes min. If null, includeMin will default to true.
includeMax - Determines if max should be considered part of the valid range. If true, the valid range includes max. If null, includeMax will default to true.
Returns:
A BoundedIntegerStringParser with the specified lower and upper bounds and specified inclusion or non-inclusion for each of the bounds.
Throws:
java.lang.IllegalArgumentException - if min is greater than max.

getParser

public static BoundedIntegerStringParser getParser(java.lang.Integer min,
                                                   java.lang.Integer max)
                                            throws java.lang.IllegalArgumentException
Parameters:
min - Minimum acceptable value. If null, the minimum will be set to Integer.MIN_VALUE
max - Maximum acceptable value. If null, the maximum will be set to Integer.MAX_VALUE
Returns:
A BoundedIntegerStringParser with the specified lower and upper bounds, inclusive.
Throws:
java.lang.IllegalArgumentException - if min is greater than max.

getParser

public static BoundedIntegerStringParser getParser()
                                            throws java.lang.IllegalArgumentException
Returns:
A BoundedIntegerStringParser with no lower or upper limit (other than Integer.MIN_VALUE and Integer.MAX_VALUE). This should behave the same as JSAP.INTEGER_PARSER and is provided for complete flexibility.
Throws:
java.lang.IllegalArgumentException - Only if getParser(Integer, Integer, Boolean, Boolean) does so.
See Also:
IntegerStringParser.getParser()

getRange

public java.lang.String getRange()
Returns:
A String representation of the range, as illustrated in range.

parse

public java.lang.Object parse(java.lang.String arg)
                       throws com.martiansoftware.jsap.ParseException
Parses the specified argument into a Integer. This method delegates the actual parsing to new Integer(String). If new Integer(String) throws a NumberFormatException, it is encapsulated in a ParseException and re-thrown. Also ensures that the value specified is in the range for this parser.
Overrides IntegerStringParser.parse(String)

Overrides:
parse in class com.martiansoftware.jsap.stringparsers.IntegerStringParser
Parameters:
arg - the argument to parse
Returns:
a Integer object with the value contained in the specified argument.
Throws:
com.martiansoftware.jsap.ParseException - if the specified value is outside the valid range or if new Integer(arg) throws a NumberFormatException.
See Also:
Integer, StringParser.parse(String)