Class Coordinate.DimensionalComparator

  • All Implemented Interfaces:
    java.util.Comparator<Coordinate>
    Enclosing class:
    Coordinate

    public static class Coordinate.DimensionalComparator
    extends java.lang.Object
    implements java.util.Comparator<Coordinate>
    Compares two Coordinates, allowing for either a 2-dimensional or 3-dimensional comparison, and handling NaN values correctly.
    • Constructor Summary

      Constructors 
      Constructor Description
      DimensionalComparator()
      Creates a comparator for 2 dimensional coordinates.
      DimensionalComparator​(int dimensionsToTest)
      Creates a comparator for 2 or 3 dimensional coordinates, depending on the value provided.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static int compare​(double a, double b)
      Compare two doubles, allowing for NaN values.
      int compare​(Coordinate c1, Coordinate c2)
      Compares two Coordinates along to the number of dimensions specified.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Constructor Detail

      • DimensionalComparator

        public DimensionalComparator()
        Creates a comparator for 2 dimensional coordinates.
      • DimensionalComparator

        public DimensionalComparator​(int dimensionsToTest)
        Creates a comparator for 2 or 3 dimensional coordinates, depending on the value provided.
        Parameters:
        dimensionsToTest - the number of dimensions to test
    • Method Detail

      • compare

        public static int compare​(double a,
                                  double b)
        Compare two doubles, allowing for NaN values. NaN is treated as being less than any valid number.
        Parameters:
        a - a double
        b - a double
        Returns:
        -1, 0, or 1 depending on whether a is less than, equal to or greater than b
      • compare

        public int compare​(Coordinate c1,
                           Coordinate c2)
        Compares two Coordinates along to the number of dimensions specified.
        Specified by:
        compare in interface java.util.Comparator<Coordinate>
        Parameters:
        c1 - a Coordinate
        c2 - a {link Coordinate}
        Returns:
        -1, 0, or 1 depending on whether o1 is less than, equal to, or greater than 02