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

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

public class BoundedDoubleStringParser
extends com.martiansoftware.jsap.stringparsers.DoubleStringParser

A StringParser for parsing Doubles with optional minimum and maximum values. The parse(String) method delegates the actual parsing to new Double(String). If new Double(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 Double.MIN_VALUE and the default maximum limit is Double.MAX_VALUE.

Author:
James Carroll, Brigham Young University
See Also:
StringParser, DoubleStringParser, Double

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.Double max
          Maximum acceptable value.
protected  java.lang.Double min
          Minimum acceptable value.
protected  java.lang.String range
           Text representation of the range.
 
Constructor Summary
BoundedDoubleStringParser(java.lang.Double min, java.lang.Double max, java.lang.Boolean includeMin, java.lang.Boolean includeMax)
          Deprecated. Use getParser(Double, Double, Boolean, Boolean).
 
Method Summary
static BoundedDoubleStringParser getParser()
           
static BoundedDoubleStringParser getParser(java.lang.Double min, java.lang.Double max)
           
static BoundedDoubleStringParser getParser(java.lang.Double min, java.lang.Double 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 Double.
 
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.Double min
Minimum acceptable value.


max

protected java.lang.Double 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

BoundedDoubleStringParser

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

Returns a BoundedDoubleStringParser 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 Double.MIN_VALUE
max - Maximum acceptable value. If null, the maximum will be set to Double.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 BoundedDoubleStringParser getParser(java.lang.Double min,
                                                  java.lang.Double 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 Double.MIN_VALUE
max - Maximum acceptable value. If null, the maximum will be set to Double.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 BoundedDoubleStringParser 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 BoundedDoubleStringParser getParser(java.lang.Double min,
                                                  java.lang.Double max)
                                           throws java.lang.IllegalArgumentException
Parameters:
min - Minimum acceptable value. If null, the minimum will be set to Double.MIN_VALUE
max - Maximum acceptable value. If null, the maximum will be set to Double.MAX_VALUE
Returns:
A BoundedDoubleStringParser with the specified lower and upper bounds, inclusive.
Throws:
java.lang.IllegalArgumentException - if min is greater than max.

getParser

public static BoundedDoubleStringParser getParser()
                                           throws java.lang.IllegalArgumentException
Returns:
A BoundedDoubleStringParser with no lower or upper limit (other than Double.MIN_VALUE and Double.MAX_VALUE). This should behave the same as JSAP.DOUBLE_PARSER and is provided for complete flexibility.
Throws:
java.lang.IllegalArgumentException - Only if getParser(Double, Double, Boolean, Boolean) does so.
See Also:
DoubleStringParser.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 Double. This method delegates the actual parsing to new Double(String). If new Double(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 DoubleStringParser.parse(String)

Overrides:
parse in class com.martiansoftware.jsap.stringparsers.DoubleStringParser
Parameters:
arg - the argument to parse
Returns:
a Double 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 Double(arg) throws a NumberFormatException.
See Also:
Double, StringParser.parse(String)