1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.dishevelled.timer.report;
26
27 import java.io.IOException;
28
29 import java.text.NumberFormat;
30
31 import java.util.Map;
32
33 import org.dishevelled.timer.Timer;
34
35
36
37
38 public final class TextTimerReport
39 extends AbstractTimerReport
40 {
41 private final NumberFormat numberFormat;
42
43 public TextTimerReport(final NumberFormat numberFormat)
44 {
45 this.numberFormat = numberFormat;
46 }
47
48
49 public <T extends Appendable> T append(final Map<? extends Runnable, Timer> timers, final T appendable)
50 throws IOException
51 {
52 if (timers == null)
53 {
54 throw new IllegalArgumentException("timers must not be null");
55 }
56 if (appendable == null)
57 {
58 throw new IllegalArgumentException("appendable must not be null");
59 }
60 append(appendable, "Runnable");
61 append(appendable, "Size");
62 append(appendable, "Min (ns)");
63 append(appendable, "Mean (ns)");
64 append(appendable, "Max (ns)");
65 append(appendable, "Standard Deviation (ns)");
66 appendLast(appendable, "Sum (ns)");
67
68 for (Map.Entry<? extends Runnable, Timer> entry : timers.entrySet())
69 {
70 append(appendable, String.valueOf(entry.getKey()));
71 append(appendable, numberFormat.format(entry.getValue().size()));
72 append(appendable, numberFormat.format(entry.getValue().min()));
73 append(appendable, numberFormat.format(entry.getValue().mean()));
74 append(appendable, numberFormat.format(entry.getValue().max()));
75 append(appendable, numberFormat.format(entry.getValue().standardDeviation()));
76 appendLast(appendable, numberFormat.format(entry.getValue().sum()));
77 }
78 return appendable;
79 }
80
81 private static <T extends Appendable> void append(final T appendable, final String value) throws IOException
82 {
83 appendable.append(value);
84 appendable.append("\t");
85 }
86
87 private static <T extends Appendable> void appendLast(final T appendable, final String value) throws IOException
88 {
89 appendable.append(value);
90 appendable.append("\n");
91 }
92 }