GraphLayoutImpl (@NotNull LinearGraph graph, @NotNull IntComparator headNodeIndexComparator) { IntList heads = new IntArrayList(); for (int i = 0; i < graph.nodesCount(); i++) { if (getUpNodes(graph, i).isEmpty()) { heads.add(i); } } try { heads.sort(headNodeIndexComparator); } catch (ProcessCanceledException pce) { throw pce; } catch (Exception e) { // protection against possible comparator flaws LOG.error(e); } GraphLayoutBuilder builder = new GraphLayoutBuilder(graph, heads); return builder.build(); }