SlidingTimeWindowMovingAverages implements MovingAverages { int normalizeIndex(int index) { int mod = index % NUMBER_OF_BUCKETS; return mod >= 0 ? mod : mod + NUMBER_OF_BUCKETS; } SlidingTimeWindowMovingAverages();  SlidingTimeWindowMovingAverages(Clock clock); @Override void update(long n); @Override void tickIfNecessary(); @Override double getM15Rate(); @Override double getM5Rate(); @Override double getM1Rate();  }
@Test public void normalizeIndex() { SlidingTimeWindowMovingAverages stwm = new SlidingTimeWindowMovingAverages(); assertThat(stwm.normalizeIndex(0), is(0)); assertThat(stwm.normalizeIndex(900), is(0)); assertThat(stwm.normalizeIndex(9000), is(0)); assertThat(stwm.normalizeIndex(-900), is(0)); assertThat(stwm.normalizeIndex(1), is(1)); assertThat(stwm.normalizeIndex(899), is(899)); assertThat(stwm.normalizeIndex(-1), is(899)); assertThat(stwm.normalizeIndex(-901), is(899)); }