edu.ucsb.ccs.jaqual.standard
Class Equal

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

public class Equal
extends java.lang.Object
implements Assertion

An assertion to test for equality. Supports comparison by reference and value, and comparison of floating point numbers.

Example use:

   Exists.in(elements).suchThat(new Equal(5));
 

Version:
$Id: Equal.java,v 1.3 2002/07/13 09:06:30 parkera Exp $
Author:
Parker Abercrombie

Field Summary
static int CONTENT
          Constant for comparison by value.
static int REFERENCE
          Constant for comparison by reference.
 
Constructor Summary
Equal(byte value)
          Create an assertion to compare bytes.
Equal(char value)
          Create an assertion to compare characters.
Equal(double value)
          Create an assertion to compare double precision numbers, using Double.MIN_VALUE as the tolerance.
Equal(double value, double tolerance)
          Create an assertion to compare double precision numbers.
Equal(float value)
          Create an assertion to compare floating point numbers, using Float.MIN_VALUE as the tolerance.
Equal(float value, double tolerance)
          Create an assertion to compare floating point numbers.
Equal(int value)
          Create an assertion to compare integers.
Equal(long value)
          Create an assertion to compare longs.
Equal(java.lang.Object value)
          Create an assertion to compare Objects by content.
Equal(java.lang.Object value, int mode)
          Create an assertion to compare Objects.
Equal(short value)
          Create an assertion to compare shorts.
 
Method Summary
 boolean eval(java.lang.Object o)
          Test an object to see if it is equal to the target value.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTENT

public static final int CONTENT
Constant for comparison by value. In this mode, objects are compared by their value (a.equals(b)), rather than by reference (a == b).

See Also:
Constant Field Values

REFERENCE

public static final int REFERENCE
Constant for comparison by reference. In this mode, objects are compared by location in memory (a == b), rather than by value (a.equals(b)).

See Also:
Constant Field Values
Constructor Detail

Equal

public Equal(java.lang.Object value)
Create an assertion to compare Objects by content.


Equal

public Equal(java.lang.Object value,
             int mode)
Create an assertion to compare Objects.

Parameters:
value - the value to compare things with.
mode - the comparison mode, either CONTENT or REFERENCE.

Equal

public Equal(int value)
Create an assertion to compare integers.


Equal

public Equal(long value)
Create an assertion to compare longs.


Equal

public Equal(short value)
Create an assertion to compare shorts.


Equal

public Equal(byte value)
Create an assertion to compare bytes.


Equal

public Equal(char value)
Create an assertion to compare characters.


Equal

public Equal(float value)
Create an assertion to compare floating point numbers, using Float.MIN_VALUE as the tolerance.


Equal

public Equal(float value,
             double tolerance)
Create an assertion to compare floating point numbers.

Parameters:
value - the value to compare things with.
tolerance - the tolerance to use in the floating point comparison.

Equal

public Equal(double value)
Create an assertion to compare double precision numbers, using Double.MIN_VALUE as the tolerance.


Equal

public Equal(double value,
             double tolerance)
Create an assertion to compare double precision numbers.

Parameters:
value - the value to compare things with.
tolerance - the tolerance to use in the comparison.
Method Detail

eval

public boolean eval(java.lang.Object o)
Test an object to see if it is equal to the target value.

Specified by:
eval in interface Assertion
Parameters:
o - the object to test. If `o' is of type Float or Double, the comparison will be performed by value, and using a tolerance.
Returns:
true if `o' equals `value'. The test is done by reference (o == value) if the mode is set to REFERENCE, otherwise the comparison is by content (o.equals(value)).