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
CommitLineData
132a02b0 1/*******************************************************************************
61759503 2 * Copyright (c) 2012, 2013 Ericsson
132a02b0
MK
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 *******************************************************************************/
11package org.eclipse.linuxtools.tmf.core.ctfadaptor;
12
032ecd45
MAL
13import java.nio.ByteBuffer;
14
132a02b0 15/**
f5df94f8 16 * The data object to go in a {@link CtfLocation}.
132a02b0
MK
17 *
18 * @author Matthew Khouzam
19 * @since 2.0
20 */
f5df94f8 21public class CtfLocationInfo implements Comparable<CtfLocationInfo> {
132a02b0 22
b1443279
MK
23 private final long fTimestamp;
24 private final long fIndex;
132a02b0
MK
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 */
f5df94f8 33 public CtfLocationInfo(long ts, long index) {
b1443279
MK
34 fTimestamp = ts;
35 fIndex = index;
132a02b0
MK
36 }
37
032ecd45
MAL
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) {
b1443279
MK
47 fTimestamp = bufferIn.getLong();
48 fIndex = bufferIn.getLong();
032ecd45
MAL
49 }
50
132a02b0
MK
51 /**
52 * @return The timestamp
53 */
54 public long getTimestamp() {
b1443279 55 return fTimestamp;
132a02b0
MK
56 }
57
58 /**
59 * @return The index of the element
60 */
61 public long getIndex() {
b1443279 62 return fIndex;
132a02b0
MK
63 }
64
f5df94f8
AM
65 // ------------------------------------------------------------------------
66 // Object
67 // ------------------------------------------------------------------------
68
132a02b0
MK
69 @Override
70 public int hashCode() {
71 final int prime = 31;
72 int result = 1;
b1443279
MK
73 result = (prime * result) + (int) (fIndex ^ (fIndex >>> 32));
74 result = (prime * result) + (int) (fTimestamp ^ (fTimestamp >>> 32));
132a02b0
MK
75 return result;
76 }
77
132a02b0
MK
78 @Override
79 public boolean equals(Object obj) {
80 if (this == obj) {
81 return true;
82 }
83 if (obj == null) {
84 return false;
85 }
f5df94f8 86 if (!(obj instanceof CtfLocationInfo)) {
132a02b0
MK
87 return false;
88 }
f5df94f8 89 CtfLocationInfo other = (CtfLocationInfo) obj;
b1443279 90 if (fIndex != other.fIndex) {
132a02b0
MK
91 return false;
92 }
b1443279 93 if (fTimestamp != other.fTimestamp) {
132a02b0
MK
94 return false;
95 }
96 return true;
97 }
98
132a02b0
MK
99 @Override
100 public String toString() {
b1443279 101 return "Element [" + fTimestamp + '/' + fIndex + ']'; //$NON-NLS-1$
132a02b0
MK
102 }
103
f5df94f8
AM
104 // ------------------------------------------------------------------------
105 // Comparable
106 // ------------------------------------------------------------------------
107
132a02b0 108 @Override
f5df94f8 109 public int compareTo(CtfLocationInfo other) {
b1443279 110 if (fTimestamp > other.getTimestamp()) {
132a02b0
MK
111 return 1;
112 }
b1443279 113 if (fTimestamp < other.getTimestamp()) {
132a02b0
MK
114 return -1;
115 }
b1443279 116 if (fIndex > other.getIndex()) {
132a02b0
MK
117 return 1;
118 }
b1443279 119 if (fIndex < other.getIndex()) {
132a02b0
MK
120 return -1;
121 }
122 return 0;
123 }
124
032ecd45
MAL
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) {
b1443279
MK
134 bufferOut.putLong(fTimestamp);
135 bufferOut.putLong(fIndex);
032ecd45 136 }
132a02b0 137}
This page took 0.048945 seconds and 5 git commands to generate.