List<List<Node>> (List<FList<HeapNode<Node>>> sidetracks) { final List<List<Node>> result = new ArrayList<>(); for (FList<HeapNode<Node>> sidetrack : sidetracks) { myProgressIndicator.checkCanceled(); List<GraphEdge<Node>> edges = new ArrayList<>(); while (!sidetrack.isEmpty()) { edges.add(sidetrack.getHead().myEdge); sidetrack = sidetrack.getTail(); } Node current = myStart; final List<Node> path = new ArrayList<>(); path.add(current); int i = edges.size() - 1; while (!current.equals(myFinish) || i >= 0) { if (i >= 0 && edges.get(i).getStart().equals(current)) { current = edges.get(i).getFinish(); i--; } else { current = myNextNodes.get(current); LOG.assertTrue(current != null); } path.add(current); } result.add(path); } return result; }