* @param states The array of states to base the leg on
* @param showIntermediateStops Whether to include intermediate stops in the leg or not
* @return The generated leg
*/
private Leg generateLeg(Graph graph, State[] states, boolean showIntermediateStops) {
Leg leg = new Leg();
Edge[] edges = new Edge[states.length - 1];
leg.startTime = makeCalendar(states[0]);
leg.endTime = makeCalendar(states[states.length - 1]);
// Calculate leg distance and fill array of edges
leg.distance = 0.0;
for (int i = 0; i < edges.length; i++) {
edges[i] = states[i + 1].getBackEdge();
leg.distance += edges[i].getDistance();
}
addModeAndAlerts(graph, leg, states);
TimeZone timeZone = leg.startTime.getTimeZone();
leg.agencyTimeZoneOffset = timeZone.getOffset(leg.startTime.getTimeInMillis());
addTripFields(leg, states);
addPlaces(leg, states, edges, showIntermediateStops);
if (leg.isTransitLeg()) addRealTimeData(leg, states);
CoordinateArrayListSequence coordinates = makeCoordinates(edges);
Geometry geometry = GeometryUtils.getGeometryFactory().createLineString(coordinates);
leg.legGeometry = PolylineEncoder.createEncodings(geometry);