From: SourceForge.net <no...@so...> - 2010-06-04 14:02:45
|
Patches item #3011545, was opened at 2010-06-04 16:02 Message generated for change (Tracker Item Submitted) made by ge0ffrey You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=315494&aid=3011545&group_id=15494 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Geoffrey De Smet (ge0ffrey) Assigned to: Nobody/Anonymous (nobody) Summary: MillisecondsSpendNumberFormat patch Initial Comment: I wrote this MillisecondsSpendNumberFormat and used it like this: NumberAxis xAxis = new NumberAxis("Time millis spend"); xAxis.setAutoRangeIncludesZero(false); xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat()); but I think other can use it too if its part of the jfreechart distribution. Without it, I get this: http://2.bp.blogspot.com/_DkCPgdrtcek/S4lj4X6BS5I/AAAAAAAAAGI/VvrkRnwQ2gI/s1600-h/exam_comp_set5Statistic.png With it, it says 50s instead 50000 and 1m20s instead of 100000 package org.drools.planner.benchmark.statistic; import java.text.FieldPosition; import java.text.NumberFormat; import java.text.ParsePosition; /** * @author Geoffrey De Smet */ class MillisecondsSpendNumberFormat extends NumberFormat { private final static long DAY_MILLIS = 3600000L * 24L; private final static long HOUR_MILLIS = 3600000L; private final static long MINUTE_MILLIS = 60000L; private final static long SECOND_MILLIS = 1000L; public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) { return format((long) number, toAppendTo, pos); } public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) { if (number == 0L) { toAppendTo.append("0"); } long rest = number; long days = rest / DAY_MILLIS; if (days > 0) { toAppendTo.append(days).append("d"); rest %= DAY_MILLIS; } long hours = rest / HOUR_MILLIS; if (hours > 0) { toAppendTo.append(hours).append("h"); rest %= HOUR_MILLIS; } long minutes = rest / MINUTE_MILLIS; if (minutes > 0) { toAppendTo.append(minutes).append("m"); rest %= MINUTE_MILLIS; } long seconds = rest / SECOND_MILLIS; if (seconds > 0) { toAppendTo.append(seconds).append("s"); rest %= SECOND_MILLIS; } if (rest > 0) { toAppendTo.append(rest).append("ms"); } return toAppendTo; } public Number parse(String source, ParsePosition parsePosition) { throw new UnsupportedOperationException(); } } ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=315494&aid=3011545&group_id=15494 |