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
26
27
28
29
30
31
32 package org.spf4j.perf.impl.chart;
33
34 import java.util.List;
35 import org.jfree.chart.axis.NumberTickUnit;
36 import org.spf4j.base.ComparablePair;
37 import org.spf4j.perf.impl.Quanta;
38
39
40
41
42
43 final class QuantizedNumberTickUnit extends NumberTickUnit {
44
45 private static final long serialVersionUID = 1L;
46
47 private final List<ComparablePair<Quanta, Integer>> quantas;
48
49 QuantizedNumberTickUnit(final double size, final List<ComparablePair<Quanta, Integer>> quantas) {
50 super(size);
51 this.quantas = quantas;
52 }
53
54 @Override
55 public String valueToString(final double value) {
56 int idx = (int) Math.round(value);
57 if (idx < 0) {
58 return "NI";
59 } else if (idx >= quantas.size()) {
60 return "PI";
61 }
62 long val = quantas.get(idx).getFirst().getIntervalStart();
63 if (val == Long.MIN_VALUE) {
64 return "NI";
65 } else {
66 return Long.toString(val);
67 }
68 }
69
70 @Override
71 public int hashCode() {
72 int hash = 3;
73 return 37 * hash + (this.quantas != null ? this.quantas.hashCode() : 0);
74 }
75
76 @Override
77 public boolean equals(final Object obj) {
78 if (obj == null) {
79 return false;
80 }
81 if (getClass() != obj.getClass()) {
82 return false;
83 }
84 final QuantizedNumberTickUnit other = (QuantizedNumberTickUnit) obj;
85 return (!(this.quantas != other.quantas && (this.quantas == null || !this.quantas.equals(other.quantas))));
86 }
87
88 }