I'm looking for a Java library class which provides a similar interface to this:
void addData(Comparable data);
int countBiggerThan(Comparable data);
void removeSmallerThan(Comparable data);
I would like to use it to make sure that in the last 10 minutes/hour/day there were no more than n
actions. For examaple:
timeWindow = now() - 1 hour;
if (counter.countBiggerThan(timeWindow) < n) {
doSomething();
counter.addData(now());
}
counter.removeSmallerThan(timeWindow);
It wouldn't be too complicated to write one but I'd not want to reinvent the wheel. I guess there is something similar in one of the well-known Java libraries but I haven't found anything useful yet.