@Test public void testCornerCases() { try { counter.get(3); fail("Exception should have been thrown"); } catch (IllegalArgumentException e) { assertTrue(true); } try { new SlidingWindowCounter(0); fail("Exception should have been thrown"); } catch (IllegalArgumentException e) { assertTrue(true); } try { new SlidingWindowCounter(-1); fail("Exception should have been thrown"); } catch (IllegalArgumentException e) { assertTrue(true); } }
public long get(int slots) { checkArgument(slots <= windowSlots, "Requested window must be less than the total window slots"); long sum = 0; for (int i = 0; i < slots; i++) { int currentIndex = headSlot - i; if (currentIndex < 0) { currentIndex = counters.size() + currentIndex; } sum += counters.get(currentIndex).get(); } return sum; }
SlidingWindowCounter { public long get(int slots) { checkArgument(slots <= windowSlots, "Requested window must be less than the total window slots"); long sum = 0; for (int i = 0; i < slots; i++) { int currentIndex = headSlot - i; if (currentIndex < 0) { currentIndex = counters.size() + currentIndex; } sum += counters.get(currentIndex).get(); } return sum; } }
SlidingWindowCounter { public long get(int slots) { checkArgument(slots <= windowSlots, "Requested window must be less than the total window slots"); long sum = 0; for (int i = 0; i < slots; i++) { int currentIndex = headSlot - i; if (currentIndex < 0) { currentIndex = counters.size() + currentIndex; } sum += counters.get(currentIndex).get(); } return sum; } SlidingWindowCounter(int windowSlots); }
SlidingWindowCounter { public long get(int slots) { checkArgument(slots <= windowSlots, "Requested window must be less than the total window slots"); long sum = 0; for (int i = 0; i < slots; i++) { int currentIndex = headSlot - i; if (currentIndex < 0) { currentIndex = counters.size() + currentIndex; } sum += counters.get(currentIndex).get(); } return sum; } SlidingWindowCounter(int windowSlots); void destroy(); void incrementCount(); void incrementCount(long value); long get(int slots); }
SlidingWindowCounter { public long get(int slots) { checkArgument(slots <= windowSlots, "Requested window must be less than the total window slots"); long sum = 0; for (int i = 0; i < slots; i++) { int currentIndex = headSlot - i; if (currentIndex < 0) { currentIndex = counters.size() + currentIndex; } sum += counters.get(currentIndex).get(); } return sum; } SlidingWindowCounter(int windowSlots); void destroy(); void incrementCount(); void incrementCount(long value); long get(int slots);  }