Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/datastructures/graphs/BoruvkaAlgorithm.java (Java)

Code before:
        Component(final int parent, final int rank) {
            this.parent = parent;
            this.rank = rank;
        }
    }

    /**
     * Represents the state of Union-Find components and the result list
     */
    static class BoruvkaState {
        List<Edge> result;
        Component[] components;
        Graph graph;

        BoruvkaState(Graph graph) {
            this.result = new ArrayList<>();
            this.components = initializeSubsets(graph);
            this.graph = graph;
        }

        /**
         * Adds the cheapest edges to the result list and performs Union operation on the subsets.
         *
         * @param cheapest Array containing the cheapest edge for each subset.
         */
        void merge(Edge[] cheapest) {
            for (int i = 0; i < graph.vertex; ++i) {
                if (cheapest[i] != null) {
                    final var set1 = find(components, cheapest[i].src);
                    final var set2 = find(components, cheapest[i].dest);

                    if (set1 != set2) {
                        result.add(cheapest[i]);
                        union(components, set1, set2);
                    }
                }
            }
        }

        /**
         * Checks if there are more edges to add to the result list
         *
         * @return true if there are more edges to add, false otherwise
         */
        boolean hasMoreEdgesToAdd() {
            return result.size() < graph.vertex - 1;
        }

        /**
         * Computes the cheapest edges for each subset in the Union-Find structure.
         *

Review comment (suggestion):
```suggestion
        void merge(final Edge[] cheapest) {
```

Code after:
        Component(final int parent, final int rank) {
            this.parent = parent;
            this.rank = rank;
        }
    }

    /**
     * Represents the state of Union-Find components and the result list
     */
    private static class BoruvkaState {
        List<Edge> result;
        Component[] components;
        final Graph graph;

        BoruvkaState(final Graph graph) {
            this.result = new ArrayList<>();
            this.components = initializeComponents(graph);
            this.graph = graph;
        }

        /**
         * Adds the cheapest edges to the result list and performs Union operation on the subsets.
         *
         * @param cheapest Array containing the cheapest edge for each subset.
         */
        void merge(final Edge[] cheapest) {
            for (int i = 0; i < graph.vertex; ++i) {
                if (cheapest[i] != null) {
                    final var component1 = find(components, cheapest[i].src);
                    final var component2 = find(components, cheapest[i].dest);

                    if (component1 != component2) {
                        result.add(cheapest[i]);
                        union(components, component1, component2);
                    }
                }
            }
        }

        /**
         * Checks if there are more edges to add to the result list
         *
         * @return true if there are more edges to add, false otherwise
         */
        boolean hasMoreEdgesToAdd() {
            return result.size() < graph.vertex - 1;
        }

        /**
         * Computes the cheapest edges for each subset in the Union-Find structure.
         *