StageAggregation { public String histogram() { Long costs = 0L; Long items = 0L; Long max = 0L; Long min = Long.MAX_VALUE; Long tps = 0L; Long tpm = 0L; Long avg = 0L; Long lastTime = 0L; Long tpsCount = 0L; Long tpsTotal = 0L; Long tpsSecond = 0L; Long tpmCount = 0L; Long tpmTotal = 0L; Long tpmMinute = 0L; for (int i = 0; i < table.length; i++) { AggregationItem aggregation = table[i]; if (aggregation != null) { Long cost = aggregation.getEndTime() - aggregation.getStartTime(); items += 1; costs += cost; if (cost > max) { max = cost; } if (cost < min) { min = cost; } if (lastTime != 0) { if (lastTime > aggregation.getEndTime() - ONE_SECOND) { tpsCount++; } else { tpsTotal += tpsCount; tpsSecond++; tpsCount = 0L; } if (lastTime > aggregation.getEndTime() - ONE_MINUTE) { tpmCount++; } else { tpmTotal += tpmCount; tpmMinute++; tpmCount = 0L; } } lastTime = aggregation.getEndTime(); } } tpsTotal += tpsCount; tpsSecond++; tpsCount = 0L; tpmTotal += tpmCount; tpmMinute++; tpmCount = 0L; if (items != 0) { avg = costs / items; } if (tpsSecond != 0) { tps = tpsTotal / tpsSecond; } if (tpmMinute != 0) { tpm = tpmTotal / tpmMinute; } if (min == Long.MAX_VALUE) { min = 0L; } return String.format(HISTOGRAM_FORMAT, new Object[] { sequence.get() + 1, items, max, min, avg, tps, tpm }); } StageAggregation(int bufferSize); void push(AggregationItem aggregation); Long count(); String histogram();  }
@Test public void test_zero() { StageAggregation aggregation = new StageAggregation(256); String result = aggregation.histogram(); System.out.println(result); }