diff --git a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/utils/BfsUtil.kt b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/utils/BfsUtil.kt index 451378210d18..3f2041a2020a 100644 --- a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/utils/BfsUtil.kt +++ b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/utils/BfsUtil.kt @@ -13,59 +13,55 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.vcs.log.graph.utils; +package com.intellij.vcs.log.graph.utils -import com.intellij.util.containers.ContainerUtil; -import com.intellij.vcs.log.graph.api.LiteLinearGraph; -import org.jetbrains.annotations.NotNull; +import com.intellij.util.containers.ContainerUtil +import com.intellij.vcs.log.graph.api.LiteLinearGraph +import java.util.* -import java.util.ArrayList; -import java.util.List; -import java.util.Queue; +object BfsUtil { + fun getCorrespondingParent(graph: LiteLinearGraph, startNode: Int, endNode: Int, visited: Flags): Int { + val candidates = graph.getNodes(startNode, LiteLinearGraph.NodeFilter.DOWN) + if (candidates.size == 1) return candidates[0] + if (candidates.contains(endNode)) return endNode -public class BfsUtil { - public static int getCorrespondingParent(@NotNull LiteLinearGraph graph, int startNode, int endNode, @NotNull Flags visited) { - List candidates = graph.getNodes(startNode, LiteLinearGraph.NodeFilter.DOWN); - if (candidates.size() == 1) return candidates.get(0); - if (candidates.contains(endNode)) return endNode; - - List> queues = new ArrayList<>(candidates.size()); - for (int candidate : candidates) { - queues.add(ContainerUtil.newLinkedList(candidate)); + val queues = ArrayList>(candidates.size) + for (candidate in candidates) { + queues.add(ContainerUtil.newLinkedList(candidate)) } - int emptyCount; - visited.setAll(false); + var emptyCount: Int + visited.setAll(false) do { - emptyCount = 0; - for (Queue queue : queues) { + emptyCount = 0 + for (queue in queues) { if (queue.isEmpty()) { - emptyCount++; + emptyCount++ } else { - boolean found = runNextBfsStep(graph, queue, visited, endNode); + val found = runNextBfsStep(graph, queue, visited, endNode) if (found) { - return candidates.get(queues.indexOf(queue)); + return candidates[queues.indexOf(queue)] } } } } - while (emptyCount < queues.size()); + while (emptyCount < queues.size) - return candidates.get(0); + return candidates[0] } - private static boolean runNextBfsStep(@NotNull LiteLinearGraph graph, @NotNull Queue queue, @NotNull Flags visited, int target) { + private fun runNextBfsStep(graph: LiteLinearGraph, queue: Queue, visited: Flags, target: Int): Boolean { while (!queue.isEmpty()) { - Integer node = queue.poll(); - if (!visited.get(node)) { - visited.set(node, true); - List next = graph.getNodes(node, LiteLinearGraph.NodeFilter.DOWN); - if (next.contains(target)) return true; - queue.addAll(next); - return false; + val node = queue.poll() + if (!visited.get(node!!)) { + visited.set(node, true) + val next = graph.getNodes(node, LiteLinearGraph.NodeFilter.DOWN) + if (next.contains(target)) return true + queue.addAll(next) + return false } } - return false; + return false } }