diff --git a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/ReachableNodes.java b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/ReachableNodes.java index 260e47c0bff2..01a94a058008 100644 --- a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/ReachableNodes.java +++ b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/ReachableNodes.java @@ -50,36 +50,29 @@ public class ReachableNodes { return nodesVisibility; } - final UnsignedBitSet result = new UnsignedBitSet(); + UnsignedBitSet result = new UnsignedBitSet(); ReachableNodes getter = new ReachableNodes(LinearGraphUtils.asLiteLinearGraph(permanentGraph)); - getter.walk(headNodeIndexes, new Consumer() { - @Override - public void consume(Integer node) { - result.set(node, true); - } + getter.walk(headNodeIndexes, node -> result.set(node, true)); + + return result; + } + + @NotNull + public Set getContainingBranches(int nodeIndex, @NotNull Collection branchNodeIndexes) { + Set result = new HashSet<>(); + + walk(Collections.singletonList(nodeIndex), false, node -> { + if (branchNodeIndexes.contains(node)) result.add(node); }); return result; } - public Set getContainingBranches(int nodeIndex, @NotNull final Collection branchNodeIndexes) { - final Set result = new HashSet<>(); - - walk(Collections.singletonList(nodeIndex), false, new Consumer() { - @Override - public void consume(Integer integer) { - if (branchNodeIndexes.contains(integer)) result.add(integer); - } - }); - - return result; - } - - public void walk(@NotNull Collection headIds, @NotNull final Consumer consumer) { + public void walk(@NotNull Collection headIds, @NotNull Consumer consumer) { walk(headIds, true, consumer); } - private void walk(@NotNull Collection startNodes, final boolean goDown, @NotNull final Consumer consumer) { + private void walk(@NotNull Collection startNodes, boolean goDown, @NotNull Consumer consumer) { synchronized (myTempFlags) { myTempFlags.setAll(false); @@ -89,19 +82,16 @@ public class ReachableNodes { myTempFlags.set(start, true); consumer.consume(start); - myDfsUtil.nodeDfsIterator(start, new DfsUtil.NextNode() { - @Override - public int fun(int currentNode) { - for (int downNode : myGraph.getNodes(currentNode, goDown ? LiteLinearGraph.NodeFilter.DOWN : LiteLinearGraph.NodeFilter.UP)) { - if (!myTempFlags.get(downNode)) { - myTempFlags.set(downNode, true); - consumer.consume(downNode); - return downNode; - } + myDfsUtil.nodeDfsIterator(start, currentNode -> { + for (int downNode : myGraph.getNodes(currentNode, goDown ? LiteLinearGraph.NodeFilter.DOWN : LiteLinearGraph.NodeFilter.UP)) { + if (!myTempFlags.get(downNode)) { + myTempFlags.set(downNode, true); + consumer.consume(downNode); + return downNode; } - - return NODE_NOT_FOUND; } + + return DfsUtil.NextNode.NODE_NOT_FOUND; }); } }