### Question:
LeapArray { WindowWrap<T> getValidHead(long timeMillis) { int idx = calculateTimeIdx(timeMillis + windowLengthInMs); WindowWrap<T> wrap = array.get(idx); if (wrap == null || isWindowDeprecated(wrap)) { return null; } return wrap; } LeapArray(int sampleCount, int intervalInMs); WindowWrap<T> currentWindow(); abstract T newEmptyBucket(long timeMillis); WindowWrap<T> currentWindow(long timeMillis); WindowWrap<T> getPreviousWindow(long timeMillis); WindowWrap<T> getPreviousWindow(); T getWindowValue(long timeMillis); boolean isWindowDeprecated(/*@NonNull*/ WindowWrap<T> windowWrap); boolean isWindowDeprecated(long time, WindowWrap<T> windowWrap); List<WindowWrap<T>> list(); List<WindowWrap<T>> list(long validTime); List<WindowWrap<T>> listAll(); List<T> values(); List<T> values(long timeMillis); WindowWrap<T> getValidHead(); int getSampleCount(); int getIntervalInMs(); double getIntervalInSecond(); void debug(long time); long currentWaiting(); void addWaiting(long time, int acquireCount);  }### Answer:
@Test public void testGetValidHead() { int windowLengthInMs = 100; int intervalInMs = 1000; int sampleCount = intervalInMs / windowLengthInMs; LeapArray<AtomicInteger> leapArray = new LeapArray<AtomicInteger>(sampleCount, intervalInMs) { @Override public AtomicInteger newEmptyBucket(long time) { return new AtomicInteger(0); } @Override protected WindowWrap<AtomicInteger> resetWindowTo(WindowWrap<AtomicInteger> windowWrap, long startTime) { windowWrap.resetTo(startTime); windowWrap.value().set(0); return windowWrap; } }; WindowWrap<AtomicInteger> expected1 = leapArray.currentWindow(); expected1.value().addAndGet(1); sleep(windowLengthInMs); WindowWrap<AtomicInteger> expected2 = leapArray.currentWindow(); expected2.value().addAndGet(2); for (int i = 0; i < sampleCount - 2; i++) { sleep(windowLengthInMs); leapArray.currentWindow().value().addAndGet(i + 3); } assertSame(expected1, leapArray.getValidHead()); sleep(windowLengthInMs); assertSame(expected2, leapArray.getValidHead()); }