LTTng: CPU usage analysis from the LTTng kernel trace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfLocationInfo.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * 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: Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.linuxtools.tmf.core.ctfadaptor;
12
13 import java.nio.ByteBuffer;
14
15 /**
16 * The data object to go in a {@link CtfLocation}.
17 *
18 * @author Matthew Khouzam
19 * @since 2.0
20 */
21 public class CtfLocationInfo implements Comparable<CtfLocationInfo> {
22
23 private final long fTimestamp;
24 private final long fIndex;
25
26 /**
27 * @param ts
28 * Timestamp
29 * @param index
30 * Index of this event (if there are N elements with the same
31 * timestamp, which one is it.)
32 */
33 public CtfLocationInfo(long ts, long index) {
34 fTimestamp = ts;
35 fIndex = index;
36 }
37
38 /**
39 * Construct the location from the ByteBuffer.
40 *
41 * @param bufferIn
42 * the buffer to read from
43 *
44 * @since 3.0
45 */
46 public CtfLocationInfo(ByteBuffer bufferIn) {
47 fTimestamp = bufferIn.getLong();
48 fIndex = bufferIn.getLong();
49 }
50
51 /**
52 * @return The timestamp
53 */
54 public long getTimestamp() {
55 return fTimestamp;
56 }
57
58 /**
59 * @return The index of the element
60 */
61 public long getIndex() {
62 return fIndex;
63 }
64
65 // ------------------------------------------------------------------------
66 // Object
67 // ------------------------------------------------------------------------
68
69 @Override
70 public int hashCode() {
71 final int prime = 31;
72 int result = 1;
73 result = (prime * result) + (int) (fIndex ^ (fIndex >>> 32));
74 result = (prime * result) + (int) (fTimestamp ^ (fTimestamp >>> 32));
75 return result;
76 }
77
78 @Override
79 public boolean equals(Object obj) {
80 if (this == obj) {
81 return true;
82 }
83 if (obj == null) {
84 return false;
85 }
86 if (!(obj instanceof CtfLocationInfo)) {
87 return false;
88 }
89 CtfLocationInfo other = (CtfLocationInfo) obj;
90 if (fIndex != other.fIndex) {
91 return false;
92 }
93 if (fTimestamp != other.fTimestamp) {
94 return false;
95 }
96 return true;
97 }
98
99 @Override
100 public String toString() {
101 return "Element [" + fTimestamp + '/' + fIndex + ']'; //$NON-NLS-1$
102 }
103
104 // ------------------------------------------------------------------------
105 // Comparable
106 // ------------------------------------------------------------------------
107
108 @Override
109 public int compareTo(CtfLocationInfo other) {
110 if (fTimestamp > other.getTimestamp()) {
111 return 1;
112 }
113 if (fTimestamp < other.getTimestamp()) {
114 return -1;
115 }
116 if (fIndex > other.getIndex()) {
117 return 1;
118 }
119 if (fIndex < other.getIndex()) {
120 return -1;
121 }
122 return 0;
123 }
124
125 /**
126 * Write the location to the ByteBuffer so that it can be saved to disk.
127 *
128 * @param bufferOut
129 * the buffer to write to
130 *
131 * @since 3.0
132 */
133 public void serialize(ByteBuffer bufferOut) {
134 bufferOut.putLong(fTimestamp);
135 bufferOut.putLong(fIndex);
136 }
137 }
This page took 0.066508 seconds and 5 git commands to generate.