edu.ucsb.ccs.jaqual.standard
Class InRange

java.lang.Object
  |
  +--edu.ucsb.ccs.jaqual.standard.InRange
All Implemented Interfaces:
Assertion

public class InRange
extends java.lang.Object
implements Assertion

An assertion to determine if a number falls in a given range. The assertion supports both integer and floating point comparison. You can specify whether or not the bounding values are included or excluded from the range.

Version:
$Id: InRange.java,v 1.3 2002/07/13 09:08:10 parkera Exp $
Author:
Parker Abercrombie

Field Summary
static int EXCLUSIVE
          Constant to indicate the bound is exclusive.
static int INCLUSIVE
          Constant to indicate the bound is inclusive.
 
Constructor Summary
InRange(double minVal, double maxVal, double tolerance)
          Create an assertion to test that a value falls in the interval [minVal, maxVal].
InRange(double minVal, double maxVal, double tolerance, int mode)
          Create an assertion to test that a value falls in the interval [minVal, maxVal].
InRange(double minVal, double maxVal, double tolerance, int lowerMode, int upperMode)
          Create an assertion to test that a value falls in the interval [minVal, maxVal].
InRange(long minVal, long maxVal)
          Create an assertion to test that a value falls in the interval [minVal, maxVal].
InRange(long minVal, long maxVal, int mode)
          Create an assertion to test that a value falls between `minVal' and `maxVal'.
InRange(long minVal, long maxVal, int lowerMode, int upperMode)
          Create an assertion to test that a value falls between `minVal' and `maxVal'.
 
Method Summary
 boolean eval(java.lang.Object o)
          Determine if a value is in the allowed range.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INCLUSIVE

public static final int INCLUSIVE
Constant to indicate the bound is inclusive. The bounding value is included in the range.

See Also:
Constant Field Values

EXCLUSIVE

public static final int EXCLUSIVE
Constant to indicate the bound is exclusive. The bounding value is not included in the range.

See Also:
Constant Field Values
Constructor Detail

InRange

public InRange(long minVal,
               long maxVal)
Create an assertion to test that a value falls in the interval [minVal, maxVal]. The bounds are inclusive, and the values are integers.

Parameters:
minVal - the lower bound.
maxVal - the upper bound.

InRange

public InRange(long minVal,
               long maxVal,
               int mode)
Create an assertion to test that a value falls between `minVal' and `maxVal'. The values are integers.

Parameters:
minVal - the lower bound.
maxVal - the upper bound.
mode - the comparison mode to use for both bounds, either INCLUSIVE or EXCLUSIVE.

InRange

public InRange(long minVal,
               long maxVal,
               int lowerMode,
               int upperMode)
Create an assertion to test that a value falls between `minVal' and `maxVal'. The values are integers.

Parameters:
minVal - the lower bound.
maxVal - the upper bound.
lowerMode - the comparison mode to use for the lower bound, either INCLUSIVE or EXCLUSIVE.
upperMode - the comparison mode to use for the upper bound, either INCLUSIVE or EXCLUSIVE.

InRange

public InRange(double minVal,
               double maxVal,
               double tolerance)
Create an assertion to test that a value falls in the interval [minVal, maxVal]. The bounds are inclusive, and the values are floating point.

Parameters:
minVal - the lower bound.
maxVal - the upper bound.
tolerance - the tolerance to use in the floating point comparison.

InRange

public InRange(double minVal,
               double maxVal,
               double tolerance,
               int mode)
Create an assertion to test that a value falls in the interval [minVal, maxVal]. The values are floating point.

Parameters:
minVal - the lower bound.
maxVal - the upper bound.
tolerance - the tolerance to use in the floating point comparison.
mode - the comparison mode to use for both bounds, either INCLUSIVE or EXCLUSIVE.

InRange

public InRange(double minVal,
               double maxVal,
               double tolerance,
               int lowerMode,
               int upperMode)
Create an assertion to test that a value falls in the interval [minVal, maxVal]. The values are floating point.

Parameters:
minVal - the lower bound.
maxVal - the upper bound.
tolerance - the tolerance to use in the floating point comparison.
lowerMode - the comparison mode to use for the lower bound, either INCLUSIVE or EXCLUSIVE.
upperMode - the comparison mode to use for the upper bound, either INCLUSIVE or EXCLUSIVE.
Method Detail

eval

public boolean eval(java.lang.Object o)
             throws java.lang.IllegalArgumentException
Determine if a value is in the allowed range. If the comparison type is FLOAT_COMPARISON, the comparison is performed using a tolerance.

Specified by:
eval in interface Assertion
Parameters:
o - the value to examine. This must be an instance of java.lang.Number.
Returns:
true if the assertion evaluates true.
Throws:
java.lang.IllegalArgumentException - if `o' is not an instance of java.lang.Number.