TrackDataTrimmer { @NonNull static List<MLocation> autoTrim(@NonNull List<MLocation> points) { final int margin_size = 50; final int n = points.size(); int index_start = 0; int index_end = n; for (int i = 0; i < n; i++) { final MLocation point = points.get(i); if (index_start == 0 && point.climb < -4) { index_start = i; } if (point.climb < -2.5 && index_start < i) { index_end = i; } } index_start = Math.max(index_start - margin_size, 0); index_end = Math.min(index_end + margin_size + 1, n); return points.subList(index_start, index_end); }    }
@Test public void autoTrim() { List<MLocation> untrimmed = new ArrayList<>(); addPoints(untrimmed, 0, 100); addPoints(untrimmed, -20, 100); addPoints(untrimmed, 0, 100); List<MLocation> trimmed = TrackDataTrimmer.autoTrim(untrimmed); assertEquals(200, trimmed.size()); }