Closed JensN closed 10 years ago
Thanks for bringing this up. since it's a float, would returning Float.POSITIVE_INFINITY be more appropriate?
something like:
public float getCacheMissPercentage() {
if (statistics.getCacheHitCount() == 0.0 && statistics.getCacheMissCount() == 0.0) {
return Float.POSITIVE_INFINITY;
}
return (statistics.getCacheMissCount() / (statistics.getCacheHitCount() + statistics.getCacheMissCount()));
}
(and something similar for the cache miss percentage)
The two methods getCacheMissPercentage() and getCacheHitPercentage() throw an ArithmeticException (dividing by zero) if you want to print statistics after the cache just started (hit + miss count = 0).
Workarounds are:
@Override public float getCacheMissPercentage() { long sum = this.statistics.getCacheHitCount() + this.statistics.getCacheMissCount(); if (sum <= 0) { return 0; } return (float) (this.statistics.getCacheMissCount() / ((double)sum)) * 100; }
respectively
@Override public float getCacheHitPercentage() { long sum = this.statistics.getCacheHitCount() + this.statistics.getCacheMissCount(); if (sum <= 0) { return 0; } return (float) ((this.statistics.getCacheHitCount() / ((double)sum)) * 100); }