/** * Both coordinates lists are equals if (and only if) coordinates are one by one equals, i.e. same X, same Y. * * @param coordinate * The left one * @param coordinate2 * The right one * @return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second * @warning The code is not safe against on the coordinates ordering. */ private int compareCoordinates(final List<Coordinate> coordinate1, final List<Coordinate> coordinate2) { final int sizeDifference = Integer.signum(coordinate1.size() - coordinate2.size()); if ((sizeDifference == 0) && (!coordinate2.isEmpty())) { // Both are of the same size and are not empty int cpt = 0; final int size = coordinate1.size(); int coordinateDifference; do { coordinateDifference = Float.compare(coordinate1.get(cpt).getX(), coordinate2.get(cpt).getX()); if (coordinateDifference == 0) { coordinateDifference = Float.compare(coordinate1.get(cpt).getY(), coordinate2.get(cpt).getY()); } cpt++; } while ((coordinateDifference == 0) && (cpt < size)); // Return the signum of the first difference between two coordinates. return coordinateDifference; } return sizeDifference; }