1
package org.eclipse.linuxtools.internal.lttng.jni.common;
2
/*******************************************************************************
3
* Copyright (c) 2009 Ericsson
5
* All rights reserved. This program and the accompanying materials are
6
* made available under the terms of the Eclipse Public License v1.0 which
7
* accompanies this distribution, and is available at
8
* http://www.eclipse.org/legal/epl-v10.html
11
* William Bourque (wbourque@gmail.com) - Initial API and implementation
12
*******************************************************************************/
15
* <b><u>JniTime</u></b>
17
* Used to store (event, trace, tracefile, ...) timestamp.
19
* Mimic the behavior of the LttTime C structure.
21
public class JniTime extends Jni_C_Constant implements Comparable<JniTime>
23
private long time = 0;
26
* Default constructor.<p>
28
* Note : Time will be set to 0.
38
* @param oldTime Reference to the JniTime you want to copy.
40
public JniTime(JniTime oldTime) {
41
time = oldTime.getTime();
45
* Constructor with parameters.<p>
47
* "LTT style" constructor with Seconds et Nanoseconds
49
* @param newSec Seconds of the JniTime
50
* @param newNanoSec Nanoseconds of the JniTime
52
public JniTime(long newSec, long newNanoSec) {
53
time = (newSec * NANO) + newNanoSec;
57
* Constructor with parameters.<p>
59
* Usual "nanosecond only" constructor.
61
* @param newNanoSecTime Time in nanoseconds
63
public JniTime(long newNanoSecTime) {
64
time = newNanoSecTime;
68
* Second of the time.<p>
70
* Returns seconds, i.e. multiple of 1 000 000, of the stored nanoseconds time.
72
* @return Second of this time.
74
public long getSeconds() {
79
* Getter for the nanosecond of the time.<p>
81
* Returns nanoseconds part, i.e. modulo of 1 000 000, of the stored nanoseconds time.
83
* @return Nanoseconds of this time
85
public long getNanoSeconds() {
90
* Full time, in nanoseconds.<p>
92
* @return Complete time in nanoseconds
94
public long getTime() {
99
* Changes the current time for this object<p>
101
* @param newTime New time to set, in nanoseconds.
103
public void setTime(long newTime) {
108
* Populate this time object
110
* Note: This function is called from C side.
112
* @param newTime The time we want to populate
114
@SuppressWarnings("unused")
115
private void setTimeFromC(long newTime) {
120
* Comparaison operator smaller or equal than "<=" .<p>
122
* @param comparedTime The time we want to compare with this one
124
* @return true if compared time is smaller or equal, false otherwise
126
public boolean isSmallerOrEqual(JniTime comparedTime) {
128
// NOTE : We check <= instead of just <
129
// This mean the LEFT OPERAND (comparedTime) always prevails
130
if (this.getTime() <= comparedTime.getTime() ) {
139
* compareTo operator.<p>
141
* @param right The time we want to compare with this one
143
* @return int of value -1, 0 or 1, as the pased argument is bigger, equal or smaller than this time
146
public int compareTo(JniTime right) {
147
long leftTime = this.getTime();
148
long rightTime = right.getTime();
150
if ( leftTime < rightTime ) {
153
else if ( leftTime > rightTime ) {
162
* faster equals since it is called very often
163
* @param other the object to the right of this
164
* @return true if the times are the same, false otherwise.
166
public boolean equals(JniTime other) {
167
return ((other != null) && (this.time == other.time));
171
* Overridden equals for JniTime type
173
* @param The object we want to compare too
175
* @return true if the time is the same, false otherwise.
178
public boolean equals(Object obj) {
179
if (obj instanceof JniTime) {
180
return (((JniTime) obj).time == this.time);
186
* Overridden hash code for JniTime type
190
public int hashCode() {
191
return this.toString().hashCode();
197
* <u>Intended to debug</u><p>
199
* NOTE : We output the time in the same format as LTT (seconds and nanosecond separatly)
201
* @return String Attributes of the object concatenated in String
204
@SuppressWarnings("nls")
205
public String toString() {
206
String returnData = "";
208
returnData += "seconds : " + this.getSeconds() + "\n";
209
returnData += "nanoSeconds : " + this.getNanoSeconds() + "\n";