@Test public void whenLastKnownVersionIsTooOldReturnEmpty() { whenLogContainsEvents5to14(); assertThat(slidingWindow.getNextEvents(3)).isEmpty(); }
public Optional<List<LockWatchEvent>> getNextEvents(long version) { if (versionInTheFuture(version) || versionTooOld(version)) { return Optional.empty(); } int startIndex = LongMath.mod(version + 1, maxSize); int windowSize = Ints.saturatedCast(lastVersion() - version); List<LockWatchEvent> events = new ArrayList<>(windowSize); for (int i = startIndex; events.size() < windowSize; i = incrementAndMod(i)) { events.add(buffer[i]); } return Optional.of(events); }
ArrayLockEventSlidingWindow { public Optional<List<LockWatchEvent>> getNextEvents(long version) { if (versionInTheFuture(version) || versionTooOld(version)) { return Optional.empty(); } int startIndex = LongMath.mod(version + 1, maxSize); int windowSize = Ints.saturatedCast(lastVersion() - version); List<LockWatchEvent> events = new ArrayList<>(windowSize); for (int i = startIndex; events.size() < windowSize; i = incrementAndMod(i)) { events.add(buffer[i]); } return Optional.of(events); } }
ArrayLockEventSlidingWindow { public Optional<List<LockWatchEvent>> getNextEvents(long version) { if (versionInTheFuture(version) || versionTooOld(version)) { return Optional.empty(); } int startIndex = LongMath.mod(version + 1, maxSize); int windowSize = Ints.saturatedCast(lastVersion() - version); List<LockWatchEvent> events = new ArrayList<>(windowSize); for (int i = startIndex; events.size() < windowSize; i = incrementAndMod(i)) { events.add(buffer[i]); } return Optional.of(events); } ArrayLockEventSlidingWindow(int maxSize); }
ArrayLockEventSlidingWindow { public Optional<List<LockWatchEvent>> getNextEvents(long version) { if (versionInTheFuture(version) || versionTooOld(version)) { return Optional.empty(); } int startIndex = LongMath.mod(version + 1, maxSize); int windowSize = Ints.saturatedCast(lastVersion() - version); List<LockWatchEvent> events = new ArrayList<>(windowSize); for (int i = startIndex; events.size() < windowSize; i = incrementAndMod(i)) { events.add(buffer[i]); } return Optional.of(events); } ArrayLockEventSlidingWindow(int maxSize); Optional<List<LockWatchEvent>> getNextEvents(long version); }
ArrayLockEventSlidingWindow { public Optional<List<LockWatchEvent>> getNextEvents(long version) { if (versionInTheFuture(version) || versionTooOld(version)) { return Optional.empty(); } int startIndex = LongMath.mod(version + 1, maxSize); int windowSize = Ints.saturatedCast(lastVersion() - version); List<LockWatchEvent> events = new ArrayList<>(windowSize); for (int i = startIndex; events.size() < windowSize; i = incrementAndMod(i)) { events.add(buffer[i]); } return Optional.of(events); } ArrayLockEventSlidingWindow(int maxSize); Optional<List<LockWatchEvent>> getNextEvents(long version);  }