@Test public void current() { AtomicLong current = testSubject.current(); current.incrementAndGet(); current = testSubject.current(); assertEquals(1, current.get()); clock.timeElapses(5, TimeUnit.SECONDS); current = testSubject.current(); assertEquals(0, current.get()); }
public T current() { long key = bucket(clock.millis()); AtomicBoolean updated = new AtomicBoolean(); T bucket = buckets.computeIfAbsent(key, k -> { updated.set(true); return createOperation.get(); }); if( updated.get()) { truncate(key- maxBuckets); } return bucket; }
SlidingWindow { public T current() { long key = bucket(clock.millis()); AtomicBoolean updated = new AtomicBoolean(); T bucket = buckets.computeIfAbsent(key, k -> { updated.set(true); return createOperation.get(); }); if( updated.get()) { truncate(key- maxBuckets); } return bucket; } }
SlidingWindow { public T current() { long key = bucket(clock.millis()); AtomicBoolean updated = new AtomicBoolean(); T bucket = buckets.computeIfAbsent(key, k -> { updated.set(true); return createOperation.get(); }); if( updated.get()) { truncate(key- maxBuckets); } return bucket; } SlidingWindow(Supplier<T> createOperation, BinaryOperator<T> aggregateOperation, Clock clock);  SlidingWindow(int bucketSize, int history, TimeUnit timeUnit, Supplier<T> createOperation, BinaryOperator<T> aggregateOperation, Clock clock); }
SlidingWindow { public T current() { long key = bucket(clock.millis()); AtomicBoolean updated = new AtomicBoolean(); T bucket = buckets.computeIfAbsent(key, k -> { updated.set(true); return createOperation.get(); }); if( updated.get()) { truncate(key- maxBuckets); } return bucket; } SlidingWindow(Supplier<T> createOperation, BinaryOperator<T> aggregateOperation, Clock clock);  SlidingWindow(int bucketSize, int history, TimeUnit timeUnit, Supplier<T> createOperation, BinaryOperator<T> aggregateOperation, Clock clock); T current(); T aggregate(long time, TimeUnit timeUnit); }
SlidingWindow { public T current() { long key = bucket(clock.millis()); AtomicBoolean updated = new AtomicBoolean(); T bucket = buckets.computeIfAbsent(key, k -> { updated.set(true); return createOperation.get(); }); if( updated.get()) { truncate(key- maxBuckets); } return bucket; } SlidingWindow(Supplier<T> createOperation, BinaryOperator<T> aggregateOperation, Clock clock);  SlidingWindow(int bucketSize, int history, TimeUnit timeUnit, Supplier<T> createOperation, BinaryOperator<T> aggregateOperation, Clock clock); T current(); T aggregate(long time, TimeUnit timeUnit);  }