*
* @param oldestCounter
* @return fraction [0, 1]
*/
protected float getExpiredFraction(EventCounterIf<C> oldestCounter) {
ReadableDateTime windowStart = getWindowStart();
//counter.getEnd() >= window.getStart()
checkArgument(
!oldestCounter.getEnd().isBefore(windowStart),
"counter should have end %s >= window start %s", oldestCounter.getEnd(), windowStart
);
ReadableDateTime counterStart = oldestCounter.getStart();
//counter.getstart() < window.getStart()
checkArgument(
counterStart.isBefore(windowStart),
"counter should have start %s <= window start %s", counterStart, windowStart
);
//
long expiredPortionMillis = windowStart.getMillis() - counterStart.getMillis();
long lengthMillis = oldestCounter.getEnd().getMillis() - counterStart.getMillis();
float expiredFraction = expiredPortionMillis / (float) lengthMillis;
checkState(
expiredFraction >= 0 && expiredFraction <= 1.0,
"%s not in [0, 1]",