private GpxType createGpxType(List<GpxRoute> routes) { ObjectFactory objectFactory = new ObjectFactory(); GpxType gpxType = null; for (GpxRoute route : routes) { gpxType = recycleGpxType(route); if (gpxType != null) break; } if (gpxType == null) gpxType = objectFactory.createGpxType(); gpxType.setCreator(GENERATED_BY); gpxType.setVersion(VERSION); for (GpxRoute route : routes) { switch (route.getCharacteristics()) { case Waypoints: gpxType.setMetadata(createMetaData(route, gpxType)); gpxType.getWpt().addAll(createWayPoints(route, 0, route.getPositionCount())); break; case Route: gpxType.getRte().addAll(createRoute(route, 0, route.getPositionCount())); break; case Track: gpxType.getTrk().addAll(createTrack(route, 0, route.getPositionCount())); break; default: throw new IllegalArgumentException( "Unknown RouteCharacteristics " + route.getCharacteristics()); } } return gpxType; }
private GpxType createGpxType(GpxRoute route, int startIndex, int endIndex) { ObjectFactory objectFactory = new ObjectFactory(); GpxType gpxType = recycleGpxType(route); if (gpxType == null) gpxType = objectFactory.createGpxType(); gpxType.setCreator(GENERATED_BY); gpxType.setVersion(VERSION); if (route.getCharacteristics().equals(Waypoints)) gpxType.setMetadata(createMetaData(route, gpxType)); gpxType.getWpt().addAll(createWayPoints(route, startIndex, endIndex)); gpxType.getRte().addAll(createRoute(route, startIndex, endIndex)); gpxType.getTrk().addAll(createTrack(route, startIndex, endIndex)); return gpxType; }