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

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

 class BoundedFloatStringParser
extends com.martiansoftware.jsap.stringparsers.FloatStringParser

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

Author:
James Carroll, Brigham Young University
See Also:
StringParser, FloatStringParser, Float

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


max

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

BoundedFloatStringParser

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

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

getParser

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

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