FromJpx { Set<Trail> mapToTrails(final GPX gpx) { final Set<Trail> trails = new LinkedHashSet<>(); final Set<Waypoint> waypoints = new LinkedHashSet<>(); if (!gpx.getWayPoints().isEmpty() && 1 < gpx.getTracks().size()) { LOGGER.warn( Markers.IO.getMarker(), "{} | {} | {}.", Actions.PARSE, StatusCodes.NOT_ACCEPTABLE.getCode(), logMessages.getString("Error.WaypointsForManyTracks")); } else { waypoints.addAll( gpx.getWayPoints().stream() .map(this::handlePoint) .filter(Objects::nonNull) .collect(Collectors.toSet())); } if (gpx.getTracks().isEmpty()) { LOGGER.warn( Markers.IO.getMarker(), "{} | {} | {}.", Actions.PARSE, StatusCodes.NOT_FOUND.getCode(), logMessages.getString("Error.NoTrack")); } else { for (final Track trk : gpx.getTracks()) { trails.addAll(handleTrack(trk, waypoints)); } } if (!(gpx.getRoutes().isEmpty())) { LOGGER.warn( Markers.IO.getMarker(), "{} | {} | {}.", Actions.PARSE, StatusCodes.NOT_ACCEPTABLE.getCode(), logMessages.getString("Error.Route")); } return trails; } FromJpx(final boolean groupSubTrails);   }
@Test public void mapGpxType() throws IOException { Preferences.userRoot().node("ws.sosna.pinetrail.UserSettings").put("level", "INTERMEDIATE"); final GPX gpx = GPX.read( FileSystems.getDefault().getPath(".", "src/test/resources/2014-05-18_Wispertal.gpx")); final FromJpx mapper = new FromJpx(false); final Set<Trail> trails = mapper.mapToTrails(gpx); assertEquals(1, trails.size()); for (final Trail trail : trails) { assertEquals(779, trail.getWaypoints().size()); final List<Waypoint> list = new ArrayList<>(trail.getWaypoints()); final Waypoint first = list.get(0); final Waypoint last = list.get(list.size() - 1); assertEquals(Instant.parse("2014-05-18T08:25:32Z"), first.getTime()); assertEquals(Double.parseDouble("50.1181208342"), first.getCoordinates().getLatitude(), 0); assertEquals(Double.parseDouble("7.9630853701"), first.getCoordinates().getLongitude(), 0); assertEquals(Instant.parse("2014-05-18T12:06:55Z"), last.getTime()); assertEquals(Double.parseDouble("50.1181969419"), last.getCoordinates().getLatitude(), 0); assertEquals(Double.parseDouble("7.9630940873"), last.getCoordinates().getLongitude(), 0); } }
@Test public void ignoreInvalidPoint() throws IOException { final GPX gpx = GPX.read( FileSystems.getDefault() .getPath(".", "src/test/resources/2014-05-18_Wispertal_NotValidBusinessRules.gpx")); final FromJpx mapper = new FromJpx(false); final Set<Trail> trails = mapper.mapToTrails(gpx); assertEquals(1, trails.size()); for (final Trail trail : trails) { assertEquals(778, trail.getWaypoints().size()); final List<Waypoint> list = new ArrayList<>(trail.getWaypoints()); final Waypoint first = list.get(0); final Waypoint last = list.get(list.size() - 1); assertEquals(Instant.parse("2014-05-18T08:25:32Z"), first.getTime()); assertEquals(Double.parseDouble("50.1181208342"), first.getCoordinates().getLatitude(), 0); assertEquals(Double.parseDouble("7.9630853701"), first.getCoordinates().getLongitude(), 0); assertEquals(Instant.parse("2014-05-18T12:06:55Z"), last.getTime()); assertEquals(Double.parseDouble("50.1181969419"), last.getCoordinates().getLatitude(), 0); assertEquals(Double.parseDouble("7.9630940873"), last.getCoordinates().getLongitude(), 0); } }
@Test public void ignoreMissingElevation() throws IOException { final GPX gpx = GPX.read( FileSystems.getDefault() .getPath(".", "src/test/resources/2014-05-18_Wispertal_MissingElevation.gpx")); final FromJpx mapper = new FromJpx(false); final Set<Trail> trails = mapper.mapToTrails(gpx); assertEquals(1, trails.size()); for (final Trail trail : trails) { assertEquals(779, trail.getWaypoints().size()); final List<Waypoint> list = new ArrayList<>(trail.getWaypoints()); final Waypoint first = list.get(0); final Waypoint last = list.get(list.size() - 1); assertEquals(Instant.parse("2014-05-18T08:25:32Z"), first.getTime()); assertEquals(Double.parseDouble("50.1181208342"), first.getCoordinates().getLatitude(), 0); assertEquals(Double.parseDouble("7.9630853701"), first.getCoordinates().getLongitude(), 0); assertEquals(Instant.parse("2014-05-18T12:06:55Z"), last.getTime()); assertEquals(Double.parseDouble("50.1181969419"), last.getCoordinates().getLatitude(), 0); assertEquals(Double.parseDouble("7.9630940873"), last.getCoordinates().getLongitude(), 0); } }