Class ComparatorFactory


  • public class ComparatorFactory
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static <T extends java.lang.Number>
      java.math.BigDecimal
      asBigDecimal​(T number)
      Convert to a precise BigDecimal object using an intermediate String.
      java.util.Comparator<java.lang.Double> doubleComparatorWithPrecision​(double precision)  
      java.util.Comparator<java.lang.Float> floatComparatorWithPrecision​(float precision)  
      private static <T extends java.lang.Number>
      boolean
      isWithinPrecision​(T actual, T expected, T precision)
      Returns true if the abs(expected - precision) is <= precision, false otherwise.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ComparatorFactory

        public ComparatorFactory()
    • Method Detail

      • doubleComparatorWithPrecision

        public java.util.Comparator<java.lang.Double> doubleComparatorWithPrecision​(double precision)
      • floatComparatorWithPrecision

        public java.util.Comparator<java.lang.Float> floatComparatorWithPrecision​(float precision)
      • asBigDecimal

        private static <T extends java.lang.Number> java.math.BigDecimal asBigDecimal​(T number)
        Convert to a precise BigDecimal object using an intermediate String.
        Type Parameters:
        T - type of expected and precision, which should be the subclass of java.lang.Number and java.lang.Comparable
        Parameters:
        number - the Number to convert
        Returns:
        the built BigDecimal
      • isWithinPrecision

        private static <T extends java.lang.Number> boolean isWithinPrecision​(T actual,
                                                                              T expected,
                                                                              T precision)
        Returns true if the abs(expected - precision) is <= precision, false otherwise.
        Type Parameters:
        T - type of number to compare including the precision
        Parameters:
        actual - the actual value
        expected - the expected value
        precision - the acceptable precision
        Returns:
        whether true if the abs(expected - precision) is <= precision, false otherwise.