Class for finding the median of a two-dimensional space I have a simple static class that it's purpose is given an RDD of Point to find the median of each dimension and return that as a new Point using Spark's reduce functions.

This is the class:

public class MedianPointFinder {

    public static Point findMedianPoint(JavaRDD&lt;Point&gt; points) {
        Point biggestPointByXDimension = points.reduce((a, b) -&gt; getBiggestPointByXDimension(a, b));
        Point biggestPointByYDimension = points.reduce((a, b) -&gt; getBiggestPointByYDimension(a, b));

        double xDimensionMedian = biggestPointByXDimension.getX() / 2.0;
        double yDimensionMedian = biggestPointByYDimension.getY() / 2.0;

        return new Point(xDimensionMedian, yDimensionMedian);
    }

    private static Point getBiggestPointByXDimension(Point first, Point second) {
        return first.getX() &gt; second.getX() ? first : second;
    }

    private static Point getBiggestPointByYDimension(Point first, Point second) {
        return first.getY() &gt; second.getY() ? first : second;
    }
}


Point class is a simple class for storing an (x, y) point.
I guess your Point is not a java.awt.Point since that holds x and y as int and you're using double.

Why not getting rid of your Point class by making the "Finder" class itself a MedianPoint?

import java.awt.geom.Point2D;

public class MedianPoint extends Point2D.Double {

  public MedianPoint(JavaRDD&lt;Point&gt; points) {
    super(
      /* your x calculation */,
      /* your y calculation */
      );
  }

  private static Point2D.Double greaterByXOf(Point2D.Double p1, Point2D.Double p2) {
    // ...
  }

  private static Point2D.Double greaterByYOf(Point2D.Double p1, Point2D.Double p2) {
    // ...
  }

} // MedianPoint