for (Vertex v : shortestPath.vertices.subList(1, shortestPath.vertices.size())) {
State lastState = newPath.states.getLast();
GraphPath subPath = paths.get(lastVertex).get(v);
//add a leg-switching state
LegSwitchingEdge legSwitchingEdge = new LegSwitchingEdge(lastVertex, lastVertex);
lastState = legSwitchingEdge.traverse(lastState);
newPath.edges.add(legSwitchingEdge);
newPath.states.add(lastState);
//add the next subpath
for (Edge e : subPath.edges) {
lastState = e.traverse(lastState);