public ClosestPointPairAlgorithm(Collection<Point2D> points) {
    if (points == null) {
      throw new NullPointerException("points is null");
    }
    if (points.size() < 2) {
      throw new IllegalArgumentException("points is too small");
    }
    pointsOrderedByXCoordinate = new ArrayList<Point2D>(points);
    Collections.sort(pointsOrderedByXCoordinate, (o1, o2) -> {
      double delta = o1.getX() - o2.getX();
      if (delta == 0.0) {
        delta = o1.getY() - o2.getY();
      }
      return delta < 0 ? -1 : delta > 0 ? 1 : 0;
    });
    pointsOrderedByYCoordinate = new ArrayList<Point2D>(points);
    Collections.sort(pointsOrderedByYCoordinate, (o1, o2) -> {
      double delta = o1.getY() - o2.getY();
      if (delta == 0.0) {
        delta = o1.getX() - o2.getX();
      }
      return delta < 0 ? -1 : delta > 0 ? 1 : 0;
    });
  }