String (ReachableNodes reachableNodes, Set<Integer> branches, int nodesCount) { StringBuilder s = new StringBuilder(); for (int nodeIndex = 0; nodeIndex < nodesCount; nodeIndex++) { if (nodeIndex != 0) s.append("\n"); List<Integer> branchNodeIndexes = new ArrayList<>(reachableNodes.getContainingBranches(nodeIndex, branches)); if (branchNodeIndexes.isEmpty()) { s.append("none"); continue; } Collections.sort(branchNodeIndexes); boolean first = true; for (int branchNodeIndex : branchNodeIndexes) { if (first) { first = false; } else { s.append(" "); } s.append(branchNodeIndex); } } return s.toString(); }