Commit | Line | Data |
---|---|---|
6040f86c ASL |
1 | /** |
2 | * | |
3 | */ | |
2e5e79d5 | 4 | package org.eclipse.linuxtools.internal.lttng.stubs; |
6040f86c | 5 | |
6c13869b | 6 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; |
6040f86c ASL |
7 | |
8 | /** | |
9 | * @author francois | |
10 | * | |
11 | */ | |
3b38ea61 | 12 | @SuppressWarnings("nls") |
6040f86c ASL |
13 | public class LTTngTimestampStub extends TmfTimestamp { |
14 | ||
15 | /** | |
16 | * | |
17 | */ | |
1b70b6dc PT |
18 | @SuppressWarnings("unused") |
19 | private static final long serialVersionUID = 216576768443708259L; | |
6040f86c ASL |
20 | |
21 | /** | |
22 | * @param value | |
23 | * @param scale | |
24 | * @param precision | |
25 | */ | |
26 | public LTTngTimestampStub(long value) { | |
27 | super(value, (byte) -3, 0); // millisecs | |
28 | } | |
29 | ||
30 | /* (non-Javadoc) | |
31 | * @see org.eclipse.linuxtools.tmf.event.TmfTimestamp#toString() | |
32 | */ | |
33 | @Override | |
34 | public String toString() { | |
35 | ||
b9e37ffd FC |
36 | long value = getValue(); |
37 | int scale = getScale(); | |
38 | ||
6040f86c ASL |
39 | // If we are dealing with units of seconds (or higher), |
40 | // use the plain formatter | |
b9e37ffd FC |
41 | if (scale >= 0) { |
42 | Double dvalue = value * Math.pow(10, scale); | |
43 | return dvalue.toString(); | |
6040f86c ASL |
44 | } |
45 | ||
46 | // Define a format string | |
b9e37ffd | 47 | String format = String.format("%%1d.%%0%dd", -scale); |
6040f86c ASL |
48 | |
49 | // And format the timestamp value | |
b9e37ffd FC |
50 | double dscale = Math.pow(10, scale); |
51 | long seconds = (long) (value * dscale); | |
52 | long fracts = value - (long) ((double) seconds / dscale); | |
6040f86c ASL |
53 | String result = String.format(format, seconds, fracts); |
54 | ||
55 | return result; | |
56 | } | |
57 | } |