Ride ride = null;
for (State state : path.states) {
Edge edge = state.getBackEdge();
if ( ! (edge instanceof HopEdge))
continue;
HopEdge hEdge = (HopEdge) edge;
if (ride == null || ! state.getRoute().equals(ride.route)) {
ride = new Ride();
rides.add(ride);
ride.startZone = hEdge.getBeginStop().getZoneId();
ride.zones.add(ride.startZone);
ride.route = state.getRoute();
ride.startTime = state.getBackState().getTimeSeconds();
ride.firstStop = hEdge.getBeginStop();
}
ride.lastStop = hEdge.getEndStop();
ride.endZone = ride.lastStop.getZoneId();
ride.zones.add(ride.endZone);
ride.endTime = state.getTimeSeconds();
// in default fare service, classify rides by mode
ride.classifier = state.getBackMode();