Here you can find the source of formatRate(double events, double time, String event)
Parameter | Description |
---|---|
events | number of events. |
time | timespan in seconds. |
event | event name. |
public static String formatRate(double events, double time, String event)
//package com.java2s; import java.text.DecimalFormat; import java.text.NumberFormat; public class Main { /**// www . j a v a 2 s .c o m * Renders a human readable event rate esitmation. * * @param events number of events. * @param time timespan in seconds. * @param event event name. * @return a human readable event rate esitmation. */ public static String formatRate(double events, double time, String event) { StringBuffer buff = new StringBuffer(); NumberFormat format = new DecimalFormat("#.##"); if (events > time) { buff.append(format.format(events / time) + " " + event + "s / 1s on average"); } else { double interval = time / events; int d = (int) (interval / (24 * 3600)); interval -= d * 24 * 3600; int h = (int) (interval / 3600); interval -= h * 3600; int m = (int) (interval / 60); interval -= m * 60; buff.append("1 " + event + " / "); if (d > 0) { buff.append(d + "d "); } if (h > 0 || d > 0) { buff.append(h + "h "); } if (m > 0 || h > 0 || d > 0) { buff.append(m + "m "); } buff.append(format.format(interval) + " s on average"); } return buff.toString(); } }