|
1 | 1 | package org.jlab.utils.benchmark; |
2 | 2 |
|
3 | 3 | import java.util.Arrays; |
| 4 | +import java.util.ArrayList; |
4 | 5 | import java.util.Collection; |
| 6 | +import java.util.Collections; |
| 7 | +import java.util.Comparator; |
5 | 8 | import java.util.LinkedHashMap; |
| 9 | +import java.util.List; |
6 | 10 | import java.util.Map; |
7 | 11 | import java.util.Timer; |
8 | 12 | import java.util.TimerTask; |
|
12 | 16 | * |
13 | 17 | * @author gavalian |
14 | 18 | */ |
15 | | -public class Benchmark { |
16 | | - |
| 19 | +public class Benchmark implements Comparator<String> { |
| 20 | + |
17 | 21 | private static final Benchmark benchmarkInstance = new Benchmark(); |
18 | | - private final Map<String,BenchmarkMultiTimer> timerStore = new LinkedHashMap<>(); |
| 22 | + private Map<String,BenchmarkMultiTimer> timerStore = new LinkedHashMap<>(); |
19 | 23 | private Timer updateTimer = null; |
| 24 | + private final ArrayList<String> specials = new ArrayList<>(); |
20 | 25 |
|
21 | 26 | public Benchmark() {} |
22 | | - |
| 27 | + |
| 28 | + public Benchmark(String[] specials) { |
| 29 | + this.specials.addAll(Arrays.asList(specials)); |
| 30 | + } |
| 31 | + |
23 | 32 | public static Benchmark getInstance(){ |
24 | 33 | return benchmarkInstance; |
25 | 34 | } |
@@ -111,4 +120,22 @@ public String[] toCSV() { |
111 | 120 | }; |
112 | 121 | } |
113 | 122 |
|
| 123 | + public void sortByName() { |
| 124 | + List<String> keys = new ArrayList<>(timerStore.keySet()); |
| 125 | + Collections.sort(keys, this); |
| 126 | + Map<String,BenchmarkMultiTimer> timers = new LinkedHashMap<>(); |
| 127 | + for (String s : keys) |
| 128 | + timers.put(s, timerStore.get(s)); |
| 129 | + timerStore = timers; |
| 130 | + } |
| 131 | + |
| 132 | + @Override |
| 133 | + public int compare(String s1, String s2) { |
| 134 | + if (specials.contains(s1)) { |
| 135 | + return specials.contains(s2) ? s1.compareTo(s2) : -1; |
| 136 | + } else { |
| 137 | + return specials.contains(s2) ? 1 : s1.compareTo(s2); |
| 138 | + } |
| 139 | + } |
| 140 | + |
114 | 141 | } |
0 commit comments