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