code: private static Point2D computePolygonCentroid(Polygon polygon)
      {
          int pathCount = polygon.getPathCount();
  
          if (pathCount == 1) {
              return getPolygonSansHolesCentroid(polygon);
          }
  
          double xSum = 0;
          double ySum = 0;
          double areaSum = 0;
  
          for (int i = 0; i < pathCount; i++) {
              int startIndex = polygon.getPathStart(i);
              int endIndex = polygon.getPathEnd(i);
  
              Polygon sansHoles = getSubPolygon(polygon, startIndex, endIndex);
  
              Point2D centroid = getPolygonSansHolesCentroid(sansHoles);
              double area = sansHoles.calculateArea2D();
  
              xSum += centroid.x * area;
              ySum += centroid.y * area;
              areaSum += area;
          }
  
          return new Point2D(xSum / areaSum, ySum / areaSum);
      }
docs: Polygon centroid: area weighted average of centroids in case of holes