Class ToleranceDoubleComparator

  • All Implemented Interfaces:
    java.io.Serializable, java.util.Comparator<java.lang.Double>

    public class ToleranceDoubleComparator
    extends java.lang.Object
    implements java.util.Comparator<java.lang.Double>, java.io.Serializable
    A double comparator with adjustable tolerance.
    Author:
    Dimitrios Michail
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static double DEFAULT_EPSILON
      Default tolerance used by the comparator.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(java.lang.Double o1, java.lang.Double o2)
      Compares two floating point values.
      • 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, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Field Detail

      • DEFAULT_EPSILON

        public static final double DEFAULT_EPSILON
        Default tolerance used by the comparator.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ToleranceDoubleComparator

        public ToleranceDoubleComparator()
        Construct a new comparator with a DEFAULT_EPSILON tolerance.
      • ToleranceDoubleComparator

        public ToleranceDoubleComparator​(double epsilon)
        Construct a new comparator with a specified tolerance.
        Parameters:
        epsilon - the tolerance
    • Method Detail

      • compare

        public int compare​(java.lang.Double o1,
                           java.lang.Double o2)
        Compares two floating point values. Returns 0 if they are equal, -1 if o1 < o2, 1 otherwise
        Specified by:
        compare in interface java.util.Comparator<java.lang.Double>
        Parameters:
        o1 - the first value
        o2 - the second value
        Returns:
        0 if they are equal, -1 if o1 < o2, 1 otherwise