@Test public void testFormatDuration () { assertEquals("0s",Collector.formatDuration(0)); assertEquals("3s",Collector.formatDuration(3000)); assertEquals("7s",Collector.formatDuration(7000)); assertEquals("2.345s",Collector.formatDuration(2345)); assertEquals("1m",Collector.formatDuration(60000)); assertEquals("2m",Collector.formatDuration(120000)); assertEquals("2m3.456s",Collector.formatDuration(123456)); assertEquals("2m0.456s",Collector.formatDuration(120456)); assertEquals("1h",Collector.formatDuration(3600*1000)); assertEquals("2h",Collector.formatDuration(2*3600*1000)); assertEquals("1h1m1s",Collector.formatDuration(3600*1000+60000+1000)); assertEquals("1h0m1s",Collector.formatDuration(3600*1000+1000)); assertEquals("1d",Collector.formatDuration(3600*1000*24)); assertEquals("1d0h0m0.001s",Collector.formatDuration(3600*1000*24+1)); }
public static String formatDuration(long millis) { if (getDurationsMs()) { return new Long(millis).toString(); } if (millis==0) { return "0s"; } boolean force = false; StringBuilder buf = new StringBuilder(); if (force || millis >= (1000*3600*24)) { long d = millis/(1000*3600*24); buf.append(d); buf.append("d"); millis%=(1000*3600*24); force = millis!=0; } if (force || millis >= (1000*3600)) { long h = millis/(1000*3600); buf.append(h); buf.append("h"); millis%=(1000*3600); force = millis!=0; } if (force || millis >= 60000) { long m = millis/60000; buf.append(m); buf.append("m"); millis %= 60000; force=millis!=0; } if (millis!=0) { long s = millis/1000; buf.append(s); if(millis%1000 !=0) { buf.append("."); buf.append(String.format("%03d", millis%1000)); } buf.append("s"); } return buf.toString(); }
Collector { public static String formatDuration(long millis) { if (getDurationsMs()) { return new Long(millis).toString(); } if (millis==0) { return "0s"; } boolean force = false; StringBuilder buf = new StringBuilder(); if (force || millis >= (1000*3600*24)) { long d = millis/(1000*3600*24); buf.append(d); buf.append("d"); millis%=(1000*3600*24); force = millis!=0; } if (force || millis >= (1000*3600)) { long h = millis/(1000*3600); buf.append(h); buf.append("h"); millis%=(1000*3600); force = millis!=0; } if (force || millis >= 60000) { long m = millis/60000; buf.append(m); buf.append("m"); millis %= 60000; force=millis!=0; } if (millis!=0) { long s = millis/1000; buf.append(s); if(millis%1000 !=0) { buf.append("."); buf.append(String.format("%03d", millis%1000)); } buf.append("s"); } return buf.toString(); } }
Collector { public static String formatDuration(long millis) { if (getDurationsMs()) { return new Long(millis).toString(); } if (millis==0) { return "0s"; } boolean force = false; StringBuilder buf = new StringBuilder(); if (force || millis >= (1000*3600*24)) { long d = millis/(1000*3600*24); buf.append(d); buf.append("d"); millis%=(1000*3600*24); force = millis!=0; } if (force || millis >= (1000*3600)) { long h = millis/(1000*3600); buf.append(h); buf.append("h"); millis%=(1000*3600); force = millis!=0; } if (force || millis >= 60000) { long m = millis/60000; buf.append(m); buf.append("m"); millis %= 60000; force=millis!=0; } if (millis!=0) { long s = millis/1000; buf.append(s); if(millis%1000 !=0) { buf.append("."); buf.append(String.format("%03d", millis%1000)); } buf.append("s"); } return buf.toString(); }  }
Collector { public static String formatDuration(long millis) { if (getDurationsMs()) { return new Long(millis).toString(); } if (millis==0) { return "0s"; } boolean force = false; StringBuilder buf = new StringBuilder(); if (force || millis >= (1000*3600*24)) { long d = millis/(1000*3600*24); buf.append(d); buf.append("d"); millis%=(1000*3600*24); force = millis!=0; } if (force || millis >= (1000*3600)) { long h = millis/(1000*3600); buf.append(h); buf.append("h"); millis%=(1000*3600); force = millis!=0; } if (force || millis >= 60000) { long m = millis/60000; buf.append(m); buf.append("m"); millis %= 60000; force=millis!=0; } if (millis!=0) { long s = millis/1000; buf.append(s); if(millis%1000 !=0) { buf.append("."); buf.append(String.format("%03d", millis%1000)); } buf.append("s"); } return buf.toString(); }  void setSearchString(String searchString); void setSortColumn(SortColumn sortFlag); void setSortOrder(SortOrder sortOrder); Collector.SortColumn getSortColumn(); String getSearchString(); static void setDurationsMs(boolean durationsMs); static boolean getDurationsMs(); void addLog(String logMessage); Date getStartTime(); LogMessage getFirstValidLogMessage(); LogMessage getLastValidLogMessage(); Date getEndTime(); long getDuration(); String getFormattedDuration(); int getServiceCount(); Map<String, ServiceCollector> getm_ServiceCollectors(); int compareLongs(long l1, long l2); Set<String> getServices(); List<ServiceCollector> getServiceCollectors(); Comparator<ServiceCollector> getColumnComparator(); int getThreadCount(); int getCollectionsPerService(String serviceID); long getAverageCollectionTimePerService(String serviceID); long getTotalCollectionTimePerService(String serviceID); void readLogMessagesFromFile(String fileName); void printGlobalStats(PrintWriter out); static String formatDuration(long millis); void printServiceHeader(PrintWriter out); void printReport(PrintWriter out); void printServiceStats(String serviceID, PrintWriter out); }
Collector { public static String formatDuration(long millis) { if (getDurationsMs()) { return new Long(millis).toString(); } if (millis==0) { return "0s"; } boolean force = false; StringBuilder buf = new StringBuilder(); if (force || millis >= (1000*3600*24)) { long d = millis/(1000*3600*24); buf.append(d); buf.append("d"); millis%=(1000*3600*24); force = millis!=0; } if (force || millis >= (1000*3600)) { long h = millis/(1000*3600); buf.append(h); buf.append("h"); millis%=(1000*3600); force = millis!=0; } if (force || millis >= 60000) { long m = millis/60000; buf.append(m); buf.append("m"); millis %= 60000; force=millis!=0; } if (millis!=0) { long s = millis/1000; buf.append(s); if(millis%1000 !=0) { buf.append("."); buf.append(String.format("%03d", millis%1000)); } buf.append("s"); } return buf.toString(); }  void setSearchString(String searchString); void setSortColumn(SortColumn sortFlag); void setSortOrder(SortOrder sortOrder); Collector.SortColumn getSortColumn(); String getSearchString(); static void setDurationsMs(boolean durationsMs); static boolean getDurationsMs(); void addLog(String logMessage); Date getStartTime(); LogMessage getFirstValidLogMessage(); LogMessage getLastValidLogMessage(); Date getEndTime(); long getDuration(); String getFormattedDuration(); int getServiceCount(); Map<String, ServiceCollector> getm_ServiceCollectors(); int compareLongs(long l1, long l2); Set<String> getServices(); List<ServiceCollector> getServiceCollectors(); Comparator<ServiceCollector> getColumnComparator(); int getThreadCount(); int getCollectionsPerService(String serviceID); long getAverageCollectionTimePerService(String serviceID); long getTotalCollectionTimePerService(String serviceID); void readLogMessagesFromFile(String fileName); void printGlobalStats(PrintWriter out); static String formatDuration(long millis); void printServiceHeader(PrintWriter out); void printReport(PrintWriter out); void printServiceStats(String serviceID, PrintWriter out); static final String SERVICE_TITLE_FORMAT; static final String SERVICE_DATA_FORMAT; }