Commit | Line | Data |
---|---|---|
5179fc01 FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 2012 Ericsson | |
f8177ba2 | 3 | * |
5179fc01 FC |
4 | * All rights reserved. This program and the accompanying materials are |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
f8177ba2 | 8 | * |
5179fc01 FC |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.core.event; | |
14 | ||
15 | /** | |
7636a88e | 16 | * The fundamental time reference in the TMF. |
17 | * <p> | |
18 | * It defines a generic timestamp interface in its most basic form: | |
19 | * <ul> | |
20 | * <li>timestamp = [value] * 10**[scale] +/- [precision] | |
21 | * </ul> | |
22 | * Where: | |
23 | * <ul> | |
24 | * <li>[value] is an unstructured integer value | |
25 | * <li>[scale] is the magnitude of the value wrt some application-specific | |
26 | * base unit (e.g. the second) | |
27 | * <li>[precision] indicates the error on the value (useful for comparing | |
28 | * timestamps in different scales). Default: 0. | |
29 | * </ul> | |
f8177ba2 FC |
30 | * |
31 | * @version 2.0 | |
d337369a | 32 | * @author Francois Chouinard |
f8177ba2 | 33 | * |
f7703ed6 | 34 | * @see ITmfEvent |
d337369a | 35 | * @see TmfTimeRange |
5179fc01 | 36 | */ |
0316808c | 37 | public interface ITmfTimestamp extends Comparable<ITmfTimestamp> { |
5179fc01 | 38 | |
f8177ba2 FC |
39 | // ------------------------------------------------------------------------ |
40 | // Constants | |
41 | // ------------------------------------------------------------------------ | |
42 | ||
43 | /** | |
44 | * The millisecond scale factor (10e0) | |
45 | * @since 2.0 | |
46 | */ | |
d96e9054 | 47 | public static final int SECOND_SCALE = 0; |
f8177ba2 FC |
48 | |
49 | /** | |
50 | * The millisecond scale factor (10e-3) | |
51 | * @since 2.0 | |
52 | */ | |
d96e9054 | 53 | public static final int MILLISECOND_SCALE = -3; |
f8177ba2 FC |
54 | |
55 | /** | |
56 | * The microsecond scale factor (10e-6) | |
57 | * @since 2.0 | |
58 | */ | |
d96e9054 | 59 | public static final int MICROSECOND_SCALE = -6; |
f8177ba2 FC |
60 | |
61 | /** | |
62 | * The nanosecond scale factor (10e-9) | |
63 | * @since 2.0 | |
64 | */ | |
d96e9054 | 65 | public static final int NANOSECOND_SCALE = -9; |
f8177ba2 | 66 | |
a4115405 FC |
67 | // ------------------------------------------------------------------------ |
68 | // Getters | |
69 | // ------------------------------------------------------------------------ | |
70 | ||
5179fc01 FC |
71 | /** |
72 | * @return the timestamp value (magnitude) | |
73 | */ | |
74 | public long getValue(); | |
75 | ||
76 | /** | |
77 | * @return the timestamp scale (exponent) | |
78 | */ | |
79 | public int getScale(); | |
80 | ||
81 | /** | |
82 | * @return the timestamp precision (measurement tolerance) | |
83 | */ | |
84 | public int getPrecision(); | |
85 | ||
a4115405 FC |
86 | // ------------------------------------------------------------------------ |
87 | // Operations | |
88 | // ------------------------------------------------------------------------ | |
89 | ||
5179fc01 | 90 | /** |
f8177ba2 FC |
91 | * Normalize (adjust scale and offset) of the timestamp |
92 | * | |
5179fc01 FC |
93 | * @param offset the offset to apply to the timestamp value (after scaling) |
94 | * @param scale the new timestamp scale | |
95 | * @return a new 'adjusted' ITmfTimestamp | |
96 | */ | |
b9e37ffd | 97 | public ITmfTimestamp normalize(long offset, int scale); |
5179fc01 FC |
98 | |
99 | /** | |
100 | * Compares [this] and [ts] within timestamp precision | |
f8177ba2 | 101 | * |
5179fc01 FC |
102 | * @param ts the other timestamp |
103 | * @param withinPrecision consider the precision when testing for equality | |
104 | * @return -1, 0 or 1 (less than, equals, greater than) | |
105 | */ | |
106 | public int compareTo(ITmfTimestamp ts, boolean withinPrecision); | |
107 | ||
108 | /** | |
085d898f | 109 | * Returns the difference between [this] and [ts] as a timestamp |
f8177ba2 | 110 | * |
5179fc01 FC |
111 | * @param ts the other timestamp |
112 | * @return the time difference (this - other) as an ITmfTimestamp | |
113 | */ | |
114 | public ITmfTimestamp getDelta(ITmfTimestamp ts); | |
115 | ||
a4115405 FC |
116 | // ------------------------------------------------------------------------ |
117 | // Comparable | |
118 | // ------------------------------------------------------------------------ | |
119 | ||
7636a88e | 120 | /* (non-Javadoc) |
121 | * @see java.lang.Comparable#compareTo(java.lang.Object) | |
122 | */ | |
d7dbf09a | 123 | @Override |
b9e37ffd | 124 | int compareTo(ITmfTimestamp ts); |
4df4581d | 125 | |
f8177ba2 FC |
126 | /** |
127 | * Format the timestamp as per the format provided | |
128 | * | |
129 | * @param format the timestamp formatter | |
130 | * @return the formatted timestamp | |
131 | * @since 2.0 | |
132 | */ | |
133 | public String toString(final TmfTimestampFormat format); | |
134 | ||
5179fc01 | 135 | } |