fi.utu.cs.physics
Class EpsilonComparator

java.lang.Object
  |
  +--fi.utu.cs.physics.EpsilonComparator
All Implemented Interfaces:
java.util.Comparator

public class EpsilonComparator
extends java.lang.Object
implements java.util.Comparator

A rounding comparator for double-precision floating point values. An epsilon value is used when comparing two values (i.e., compare(f, g) returns zero, if Math.abs(f - g) < getComparisonEpsilon()).

Since:
1.1

Constructor Summary
EpsilonComparator(double e)
          Creates a comparator with the epsilon value e.
 
Method Summary
 int compare(double v1, double v2)
          Compares v1 and v2 for order.
 int compare(java.lang.Object o1, java.lang.Object o2)
          Compares the two arguments for order.
 double getEpsilon()
          Returns the epsilon.
 void setEpsilon(double e)
          Sets the epsilon value to e.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Constructor Detail

EpsilonComparator

public EpsilonComparator(double e)
Creates a comparator with the epsilon value e.

Method Detail

getEpsilon

public double getEpsilon()
Returns the epsilon.


setEpsilon

public void setEpsilon(double e)
Sets the epsilon value to e. The new epsilon must be greater than zero.


compare

public int compare(double v1,
                   double v2)
Compares v1 and v2 for order. Returns a negative integer, zero, or a positive integer as v1 is less than, equal to, or greater than v2. The values are equal, if their difference is less than epsilon.


compare

public int compare(java.lang.Object o1,
                   java.lang.Object o2)
Compares the two arguments for order. The arguments must be inherited from the class Number. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. The arguments are equal, if their difference is less than epsilon. Note: This comparator imposes orderings that are inconsistent with equals.

Specified by:
compare in interface java.util.Comparator