public static boolean isEstablishedAtAltitude(Track track, Instant queryTime, Duration duration) {
        TimeWindow window = TimeWindow.of(queryTime.minus(duration), queryTime);
        NavigableSet<Point> recentPoints = (NavigableSet<Point>) track.subset(window);

        if (recentPoints.isEmpty()) {
            return false;
        }

        List<Distance> recentDistances = recentPoints
            .stream()
            .map(Point::altitude)
            .collect(toList());

        Distance min = min(recentDistances);
        Distance max = max(recentDistances);
        Distance altitudeRange = max.minus(min);

        boolean allAltitudesWithin100Feet = altitudeRange.isLessThanOrEqualTo(Distance.ofFeet(100));
        boolean atLeastTwoPoints = recentPoints.size() >= 2;

        return atLeastTwoPoints && allAltitudesWithin100Feet;
    }
@Test
    public void isEstablishedAtAltitude_providesCorrectAnswer() {

        Track track = makeTrackFromNopData(getResourceFile("Track2.txt"));

        Duration fiveSeconds = Duration.ofSeconds(5);

        assertThat(
            isEstablishedAtAltitude(track, track.startTime(), fiveSeconds),
            is(false)
        );

        //first time at 8,000ft
        Instant timeAt8000 = parseNopTime("07/08/2017", "14:23:13.220");

        //when you JUST hit 8,000ft you ARE established if you require 31 seconds (because you'll only have 7900 and 8000 foot altitudes)
        assertThat(
            isEstablishedAtAltitude(track, timeAt8000, Duration.ofSeconds(31)),
            is(true)
        );
        //when you JUST hit 8,000ft you ARE NOT established if you require 32 seconds (because you'll have 7800, 7900, and 8000 foot altitudes)
        assertThat(
            isEstablishedAtAltitude(track, timeAt8000, Duration.ofSeconds(32)),
            is(false)
        );

        //2nd point at 8,000ft
        Instant timeAt8000_2 = parseNopTime("07/08/2017", "14:23:17.249");

        //you are established at an altitude after the 2nd point
        assertThat(
            isEstablishedAtAltitude(track, timeAt8000_2, fiveSeconds),
            is(true)
        );

        //another point at 8,000ft
        Instant timeAt8000_4 = parseNopTime("07/08/2017", "14:23:24.147");
        assertThat(
            isEstablishedAtAltitude(track, timeAt8000_4, fiveSeconds),
            is(true)
        );

        //you can make the test above fail by requiring a long duration at the same altitude
        assertThat(
            isEstablishedAtAltitude(track, timeAt8000_4, Duration.ofMinutes(10)),
            is(false)
        );

        Instant timeAt7900 = parseNopTime("07/08/2017", "14:36:40.981");

        //you'll still be established at the altitude even though dropped from 8,000ft to 7,900ft.
        assertThat(
            isEstablishedAtAltitude(track, timeAt7900, Duration.ofSeconds(30)),
            is(true)
        );
    }