- Minor modification of the FW API (better trace/parser integration)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / src / org / eclipse / linuxtools / lttng / jni / JniTime.java
1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
3 *
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
8 *
9 * Contributors:
10 * William Bourque (wbourque@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.lttng.jni;
14
15 /**
16 * <b><u>JniTime</u></b>
17 * <p>
18 * JniTime object linked to the LttTime C structure
19 */
20 public final class JniTime extends Jni_C_Common
21 {
22 private long time = 0;
23
24 /**
25 * Default constructor.
26 *
27 */
28 JniTime() {
29 time = 0;
30 }
31
32 /**
33 * Copy constructor.
34 *
35 * @param oldTime A reference to the JniTime you want to copy.
36 */
37 JniTime(JniTime oldTime) {
38 time = oldTime.getTime();
39 }
40
41 /**
42 * Constructor with parameters
43 * <br>
44 * "Ltt style" constructor with Seconds et Nanoseconds
45 *
46 * @param newSec Seconds of the JniTime
47 * @param newNanoSec Nanoseconds of the JniTime
48 */
49 JniTime(long newSec, long newNanoSec) {
50 time = (newSec * NANO) + newNanoSec;
51 }
52
53 /**
54 * Constructor with parameters
55 * <br>
56 * Usual "nanosecond only" constructor
57 *
58 * @param newNanoSecTime JniTime in nanoseconds
59 */
60 public JniTime(long newNanoSecTime) {
61 time = newNanoSecTime;
62 }
63
64 /**
65 * Getter for the second of the time
66 * <br>
67 * This only return seconds part, i.e. multiple of 1 000 000, of the stored time
68 *
69 * @return long Second of the time
70 */
71 public long getSeconds() {
72 return (time / NANO);
73 }
74
75 /**
76 * Getter for the nanosecond of the time
77 * <br>
78 * This only nanosecondspart , i.e. modulo of 1 000 000, of the stored time
79 *
80 * @return long Nanoseconds of the time
81 */
82 public long getNanoSeconds() {
83 return time % NANO;
84 }
85
86 /**
87 * Getter for the full time, in nanoseconds
88 *
89 * @return The complete time in nanoseconds
90 */
91 public long getTime() {
92 return time;
93 }
94
95 /**
96 * Comparaison operator <=
97 *
98 * @param comparedTime The time we want to compare with this one
99 * @return boolean true if the compared time is smaller or equal, false otherwise
100 */
101 public boolean isGivenTimeSmallerOrEqual(JniTime comparedTime) {
102
103 // NOTE : We check <= instead of just <
104 // This mean the RIGHT OPERAND (comparedTime) always prevails
105 if (comparedTime.getTime() < this.getTime()) {
106 return true;
107 } else {
108 return false;
109 }
110 }
111
112 /**
113 * Integer Comparaison operator
114 *
115 * @param comparedTime The time we want to compare with this one
116 * @return int Integer of value -1, 0 or 1, as the pased argument is bigger, equal or smaller than this time
117 */
118 public int compare(JniTime comparedTime) {
119 if ( comparedTime.getTime() < this.getTime() ) {
120 return 1;
121 }
122 else if ( comparedTime.getTime() > this.getTime() ) {
123 return -1;
124 }
125 else {
126 return 0;
127 }
128 }
129
130 /*
131 * Populate this time object
132 *
133 * Note: This function is called from C side.
134 *
135 * @param newTime The time we want to populate
136 */
137 @SuppressWarnings("unused")
138 private void setTimeFromC(long newTime) {
139 time = newTime;
140 }
141
142 /**
143 * toString() method. <u>Intended to debug</u><br>
144 * <br>
145 * NOTE : we output the time in the same format as LTT (seconds and nanosecond separatly)
146 *
147 * @return String Attributes of the object concatenated in String
148 */
149 public String toString() {
150 String returnData = "";
151
152 returnData += "seconds : " + this.getSeconds() + "\n";
153 returnData += "nanoSeconds : " + this.getNanoSeconds() + "\n";
154
155 return returnData;
156 }
157 }
This page took 0.038093 seconds and 5 git commands to generate.