@Test public void mergeTracks() { final GPX gpx = nextGPX(new Random(1)).toBuilder() .addTrack(nextTrack(new Random(2))) .addTrack(nextTrack(new Random(3))) .addTrack(nextTrack(new Random(4))) .build(); final GPX merged = gpx.toBuilder() .trackFilter() .listMap(Filters::mergeTracks) .filter(Track::nonEmpty) .build() .build(); Assert.assertEquals(merged.getTracks().size(), 1); final int segments = merged.getTracks().stream() .mapToInt(t -> t.getSegments().size()) .sum(); Assert.assertEquals(segments, 38); }
public static List<Track> mergeTracks(final List<Track> tracks) { final List<TrackSegment> segments = tracks.stream() .flatMap(Track::segments) .collect(toUnmodifiableList()); return tracks.isEmpty() ? List.of() : List.of( tracks.get(0).toBuilder() .segments(segments) .build() ); }
Filters { public static List<Track> mergeTracks(final List<Track> tracks) { final List<TrackSegment> segments = tracks.stream() .flatMap(Track::segments) .collect(toUnmodifiableList()); return tracks.isEmpty() ? List.of() : List.of( tracks.get(0).toBuilder() .segments(segments) .build() ); } }
Filters { public static List<Track> mergeTracks(final List<Track> tracks) { final List<TrackSegment> segments = tracks.stream() .flatMap(Track::segments) .collect(toUnmodifiableList()); return tracks.isEmpty() ? List.of() : List.of( tracks.get(0).toBuilder() .segments(segments) .build() ); } private  Filters(); }
Filters { public static List<Track> mergeTracks(final List<Track> tracks) { final List<TrackSegment> segments = tracks.stream() .flatMap(Track::segments) .collect(toUnmodifiableList()); return tracks.isEmpty() ? List.of() : List.of( tracks.get(0).toBuilder() .segments(segments) .build() ); } private  Filters(); static List<TrackSegment> mergeSegments(
		final List<TrackSegment> segments
	); static List<Track> mergeTracks(final List<Track> tracks); static List<Track> fullyMergeTracks(final List<Track> tracks); static GPX nonEmptyGPX(final GPX gpx); static List<Route> nonEmptyRoutes(final List<Route> routes); static List<Track> nonEmptyTracks(final List<Track> tracks); static List<TrackSegment> nonEmptySegments(
		final List<TrackSegment> segments
	); }
Filters { public static List<Track> mergeTracks(final List<Track> tracks) { final List<TrackSegment> segments = tracks.stream() .flatMap(Track::segments) .collect(toUnmodifiableList()); return tracks.isEmpty() ? List.of() : List.of( tracks.get(0).toBuilder() .segments(segments) .build() ); } private  Filters(); static List<TrackSegment> mergeSegments(
		final List<TrackSegment> segments
	); static List<Track> mergeTracks(final List<Track> tracks); static List<Track> fullyMergeTracks(final List<Track> tracks); static GPX nonEmptyGPX(final GPX gpx); static List<Route> nonEmptyRoutes(final List<Route> routes); static List<Track> nonEmptyTracks(final List<Track> tracks); static List<TrackSegment> nonEmptySegments(
		final List<TrackSegment> segments
	);  }