/** * {@inheritDoc} */ public String toString() { return "PeakRateCounter{config=" + config + ", max rate per second=" + getValue() + '}'; }
/** * {@inheritDoc} */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj == null || !(obj instanceof PeakRateCounter)) { return false; } final PeakRateCounter c = (PeakRateCounter) obj; final double v = getValue().doubleValue(); final double otherV = c.getValue().doubleValue(); return config.equals(c.getConfig()) && Double.compare(v, otherV) == 0; }
/** * {@inheritDoc} */ @Override public int hashCode() { int result = getConfig().hashCode(); final long n = Double.doubleToLongBits(getValue().doubleValue()); result = 31 * result + (int) (n ^ (n >>> 32)); return result; }
@Test public void testIncrement() throws Exception { PeakRateCounter c = newInstance("foo"); assertEquals(c.getValue().longValue(), 0L); for (int i = 0; i < 5; i++) { clock.set(i * 1000L); c.increment(); } assertEquals(c.getValue().longValue(), 1L, "Delta of 5 in 5 seconds, e.g. peak rate = average, 1 per second"); for (int i = 0; i < 5; i++) { clock.set((5 + i) * 1000L); c.increment(3); } assertEquals(c.getValue().longValue(), 3L, "Delta of 15 in 5 seconds, e.g. peak rate = average, 3 per second"); clock.set(10 * 1000L); c.increment(10); for (int i = 0; i < 3; i++) { clock.set((11 + i) * 1000L); c.increment(3); } c.increment(); assertEquals(c.getValue().longValue(), 10L, "Delta of 15 in 5 seconds, e.g. peak rate = 10, average = 3, min = 1 per second"); clock.set(19 * 1000L); assertEquals(c.getValue().longValue(), 10L, "Delta of 0 in 5 seconds, e.g. peak rate = previous max, 10 per second"); }
/** * {@inheritDoc} */ public String toString() { return "PeakRateCounter{config=" + config + ", max rate per second=" + getValue() + '}'; }
/** * {@inheritDoc} */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj == null || !(obj instanceof PeakRateCounter)) { return false; } final PeakRateCounter c = (PeakRateCounter) obj; final double v = getValue().doubleValue(); final double otherV = c.getValue().doubleValue(); return config.equals(c.getConfig()) && Double.compare(v, otherV) == 0; }
/** * {@inheritDoc} */ @Override public int hashCode() { int result = getConfig().hashCode(); final long n = Double.doubleToLongBits(getValue().doubleValue()); result = 31 * result + (int) (n ^ (n >>> 32)); return result; }