Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/geometry/GrahamScan.java (Java)

Code before:
        }

        int indexPoint2;
        for (indexPoint2 = indexPoint1 + 1; indexPoint2 < points.length; indexPoint2++) {
            if (Point.orientation(points[0], points[indexPoint1], points[indexPoint2]) != 0) {
                break;
            }
        }
        hull.push(points[indexPoint2 - 1]);

        // Process the remaining points and update the hull
        for (int i = indexPoint2; i < points.length; i++) {
            Point top = hull.pop();
            while (Point.orientation(hull.peek(), top, points[i]) <= 0) {
                top = hull.pop();
            }
            hull.push(top);
            hull.push(points[i]);
        }
    }

    /**
     * @return An iterable collection of points representing the convex hull.
     */
    public Iterable<Point> hull() {
        Stack<Point> s = new Stack<>();
        for (Point p : hull) {
            s.push(p);
        }
        return s;
    }

    public record Point(int x, int y) implements Comparable<Point> {

        /**
         * Default constructor
         * @param x x-coordinate
         * @param y y-coordinate
         */
        public Point {
        }

        /**
         * @return the x-coordinate
         */
        @Override
        public int x() {
            return x;
        }

        /**

Review comment (refactor):
The point was to simplify code. 

This method returns an `Iterable<Point>`. Since we were using a `Stack`, a loop was necessary to transfer all points from the stack into a new `Stack`. However, because the method returns an `Iterable`, the specific collection used doesn't matter as long as it implements `Iterable`. Therefore, we can simplify the method by using:

```
public Iterable<Point> hull() {
    return new ArrayList<>(stack);
}
```

This approach eliminates the need for the loop and still returning the required `Iterable<Point>`. 

But perhaps using Stack is important for some reasons.

Code after:
            }
        }

        if (firstNonEqualIndex == points.length) {
            return;
        }

        int firstNonCollinearIndex;
        for (firstNonCollinearIndex = firstNonEqualIndex + 1; firstNonCollinearIndex < points.length; firstNonCollinearIndex++) {
            if (Point.orientation(points[0], points[firstNonEqualIndex], points[firstNonCollinearIndex]) != 0) {
                break;
            }
        }

        hull.push(points[firstNonCollinearIndex - 1]);

        // Process the remaining points and update the hull
        for (int i = firstNonCollinearIndex; i < points.length; i++) {
            Point top = hull.pop();
            while (Point.orientation(hull.peek(), top, points[i]) <= 0) {
                top = hull.pop();
            }
            hull.push(top);
            hull.push(points[i]);
        }
    }

    /**
     * @return An iterable collection of points representing the convex hull.
     */
    public Iterable<Point> hull() {
        return new ArrayList<>(hull);
    }

    public record Point(int x, int y) implements Comparable<Point> {

        /**
         * Default constructor
         * @param x x-coordinate
         * @param y y-coordinate
         */
        public Point {
        }

        /**
         * @return the x-coordinate
         */
        @Override
        public int x() {
            return x;
        }