@SuppressWarnings("unchecked")
 private void renameRoute(
     BaseRoute route,
     BaseRoute routeToWrite,
     int startIndex,
     int endIndex,
     int trackIndex,
     OutputStream... targets) {
   // gives splitted TomTomRoute and SimpleRoute routes a more useful name for the fragment
   if (route.getFormat() instanceof TomTomRouteFormat
       || route.getFormat() instanceof SimpleFormat
       || route.getFormat() instanceof GpxFormat
           && routeToWrite.getFormat() instanceof BcrFormat) {
     String name = createRouteName(routeToWrite.getPositions().subList(startIndex, endIndex));
     if (targets.length > 1) name = "Track" + (trackIndex + 1) + ": " + name;
     routeToWrite.setName(name);
   }
 }
  private NavigationFormat determineFormat(
      List<BaseRoute> routes, NavigationFormat preferredFormat) {
    NavigationFormat result = preferredFormat;
    for (BaseRoute route : routes) {
      // more than one route: the same result
      if (result.equals(route.getFormat())) continue;

      // result is capable of storing multiple routes
      if (result.isSupportsMultipleRoutes()) continue;

      // result from GPSBabel-based format which allows only one route but is represented by GPX 1.0
      if (result instanceof BabelFormat) continue;

      // default for multiple routes is GPX 1.1
      result = new Gpx11Format();
    }
    return result;
  }