SlidingTimeWindowMovingAverages implements MovingAverages { int calculateIndexOfTick(Instant tickTime) { return (int) (Duration.between(bucketBaseTime, tickTime).toNanos() / TICK_INTERVAL); } SlidingTimeWindowMovingAverages();  SlidingTimeWindowMovingAverages(Clock clock); @Override void update(long n); @Override void tickIfNecessary(); @Override double getM15Rate(); @Override double getM5Rate(); @Override double getM1Rate();  }
@Test public void calculateIndexOfTick() { SlidingTimeWindowMovingAverages stwm = new SlidingTimeWindowMovingAverages(clock); assertThat(stwm.calculateIndexOfTick(Instant.ofEpochSecond(0L)), is(0)); assertThat(stwm.calculateIndexOfTick(Instant.ofEpochSecond(1L)), is(1)); }