### Question:
PathBidirRef extends Path { @Override public Path extract() { if (sptEntry == null || edgeTo == null) return this; if (sptEntry.adjNode != edgeTo.adjNode) throw new IllegalStateException("Locations of the 'to'- and 'from'-Edge has to be the same." + toString() + ", fromEntry:" + sptEntry + ", toEntry:" + edgeTo); extractSW.start(); if (switchFromAndToSPTEntry) { SPTEntry ee = sptEntry; sptEntry = edgeTo; edgeTo = ee; } SPTEntry currEdge = sptEntry; boolean nextEdgeValid = EdgeIterator.Edge.isValid(currEdge.edge); int nextEdge; while (nextEdgeValid) { nextEdgeValid = EdgeIterator.Edge.isValid(currEdge.parent.edge); nextEdge = nextEdgeValid ? currEdge.parent.edge : EdgeIterator.NO_EDGE; processEdge(currEdge.edge, currEdge.adjNode, nextEdge); currEdge = currEdge.parent; } setFromNode(currEdge.adjNode); reverseOrder(); currEdge = edgeTo; int prevEdge = nextEdgeValid ? sptEntry.edge : EdgeIterator.NO_EDGE; int tmpEdge = currEdge.edge; while (EdgeIterator.Edge.isValid(tmpEdge)) { currEdge = currEdge.parent; processEdge(tmpEdge, currEdge.adjNode, prevEdge); prevEdge = tmpEdge; tmpEdge = currEdge.edge; } setEndNode(currEdge.adjNode); extractSW.stop(); return setFound(true); } PathBidirRef(Graph g, Weighting weighting);   PathBidirRef(PathBidirRef p); PathBidirRef setSwitchToFrom(boolean b); PathBidirRef setSPTEntryTo(SPTEntry edgeTo); @Override Path extract();  }### Answer:
@Test public void testExtract() { Graph g = createGraph(); g.edge(1, 2, 10, true); PathBidirRef pw = new PathBidirRef(g, new FastestWeighting(carEncoder)); EdgeExplorer explorer = g.createEdgeExplorer(carOutEdges); EdgeIterator iter = explorer.setBaseNode(1); iter.next(); pw.sptEntry = new SPTEntry(iter.getEdge(), 2, 0); pw.sptEntry.parent = new SPTEntry(EdgeIterator.NO_EDGE, 1, 10); pw.edgeTo = new SPTEntry(EdgeIterator.NO_EDGE, 2, 0); Path p = pw.extract(); assertEquals(Helper.createTList(1, 2), p.calcNodes()); assertEquals(10, p.getDistance(), 1e-4); }
@Test public void testExtract2() { Graph g = createGraph(); g.edge(1, 2, 10, false); g.edge(2, 3, 20, false); EdgeExplorer explorer = g.createEdgeExplorer(carOutEdges); EdgeIterator iter = explorer.setBaseNode(1); iter.next(); PathBidirRef pw = new PathBidirRef(g, new FastestWeighting(carEncoder)); pw.sptEntry = new SPTEntry(iter.getEdge(), 2, 10); pw.sptEntry.parent = new SPTEntry(EdgeIterator.NO_EDGE, 1, 0); explorer = g.createEdgeExplorer(new DefaultEdgeFilter(carEncoder, true, false)); iter = explorer.setBaseNode(3); iter.next(); pw.edgeTo = new SPTEntry(iter.getEdge(), 2, 20); pw.edgeTo.parent = new SPTEntry(EdgeIterator.NO_EDGE, 3, 0); Path p = pw.extract(); assertEquals(Helper.createTList(1, 2, 3), p.calcNodes()); assertEquals(30, p.getDistance(), 1e-4); }