public Itinerary generateItinerary(GraphPath path, boolean showIntermediateStops) {
if (path.states.size() < 2) {
throw new TrivialPathException();
}
Itinerary itinerary = new Itinerary();
State[] states = new State[path.states.size()];
State lastState = path.states.getLast();
states = path.states.toArray(states);
Edge[] edges = new Edge[path.edges.size()];
edges = path.edges.toArray(edges);
Graph graph = path.getRoutingContext().graph;
FareService fareService = graph.getService(FareService.class);
State[][] legsStates = sliceStates(states);
if (fareService != null) {
itinerary.fare = fareService.getCost(path);
}
for (State[] legStates : legsStates) {
itinerary.addLeg(generateLeg(graph, legStates, showIntermediateStops));
}
addWalkSteps(graph, itinerary.legs, legsStates);
fixupLegs(itinerary.legs, legsStates);