private List<RteType> createRoute(GpxRoute route, int startIndex, int endIndex) {
   ObjectFactory objectFactory = new ObjectFactory();
   List<RteType> rteTypes = new ArrayList<RteType>();
   RteType rteType = route.getOrigin(RteType.class);
   if (rteType != null) rteType.getRtept().clear();
   else rteType = objectFactory.createRteType();
   if (isWriteName()) {
     rteType.setName(asRouteName(route.getName()));
     rteType.setDesc(asDescription(route.getDescription()));
   }
   rteTypes.add(rteType);
   List<GpxPosition> positions = route.getPositions();
   for (int i = startIndex; i < endIndex; i++) {
     GpxPosition position = positions.get(i);
     WptType wptType = createWptType(position);
     if (wptType != null) rteType.getRtept().add(wptType);
   }
   return rteTypes;
 }
  private List<GpxPosition> extractRouteWithGarminExtensions(
      RteType rteType, boolean hasSpeedInMeterPerSecondInsteadOfKilometerPerHour) {
    List<GpxPosition> positions = new ArrayList<GpxPosition>();
    if (rteType != null) {
      for (WptType wptType : rteType.getRtept()) {
        positions.add(
            new GpxPosition(
                wptType.getLon(),
                wptType.getLat(),
                wptType.getEle(),
                getSpeed(wptType, hasSpeedInMeterPerSecondInsteadOfKilometerPerHour),
                getHeading(wptType),
                parseTime(wptType.getTime()),
                asComment(wptType.getName(), wptType.getDesc()),
                wptType.getHdop(),
                wptType.getPdop(),
                wptType.getVdop(),
                wptType.getSat(),
                wptType));

        ExtensionsType extensions = wptType.getExtensions();
        if (extensions != null) {
          for (Object any : extensions.getAny()) {
            if (any instanceof JAXBElement) {
              Object anyValue = ((JAXBElement) any).getValue();
              if (anyValue instanceof RoutePointExtensionT) {
                RoutePointExtensionT routePoint = (RoutePointExtensionT) anyValue;
                for (AutoroutePointT autoroutePoint : routePoint.getRpt()) {
                  positions.add(
                      new GpxPosition(
                          autoroutePoint.getLon(),
                          autoroutePoint.getLat(),
                          null,
                          null,
                          null,
                          null,
                          null,
                          null,
                          null,
                          null,
                          null,
                          null));
                }
              }
            }
          }
        }
      }
    }
    return positions;
  }
  private List<GpxRoute> extractRoutes(
      GpxType gpxType, boolean hasSpeedInMeterPerSecondInsteadOfKilometerPerHour) {
    List<GpxRoute> result = new ArrayList<GpxRoute>();

    for (RteType rteType : gpxType.getRte()) {
      String name = rteType.getName();
      String desc = rteType.getDesc();
      List<String> descriptions = asDescription(desc);
      List<GpxPosition> positions =
          extractRoute(rteType, hasSpeedInMeterPerSecondInsteadOfKilometerPerHour);
      result.add(new GpxRoute(this, Route, name, descriptions, positions, gpxType, rteType));

      // Garmin Extensions v3
      if (rteType.getExtensions() != null && rteType.getExtensions().getAny().size() > 0) {
        List<GpxPosition> extendedPositions =
            extractRouteWithGarminExtensions(
                rteType, hasSpeedInMeterPerSecondInsteadOfKilometerPerHour);
        result.add(
            new GpxRoute(this, Track, name, descriptions, extendedPositions, gpxType, rteType));
      }
    }

    return result;
  }
 private List<GpxPosition> extractRoute(
     RteType rteType, boolean hasSpeedInMeterPerSecondInsteadOfKilometerPerHour) {
   List<GpxPosition> positions = new ArrayList<GpxPosition>();
   if (rteType != null) {
     for (WptType wptType : rteType.getRtept()) {
       positions.add(
           new GpxPosition(
               wptType.getLon(),
               wptType.getLat(),
               wptType.getEle(),
               getSpeed(wptType, hasSpeedInMeterPerSecondInsteadOfKilometerPerHour),
               getHeading(wptType),
               parseTime(wptType.getTime()),
               asComment(wptType.getName(), wptType.getDesc()),
               wptType.getHdop(),
               wptType.getPdop(),
               wptType.getVdop(),
               wptType.getSat(),
               wptType));
     }
   }
   return positions;
 }