ctf/tmf: Make CtfLocation more inline with code style.
[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
MK
22
23 private final long timestamp;
24 private final long index;
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) {
132a02b0
MK
34 this.timestamp = ts;
35 this.index = index;
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) {
47 timestamp = bufferIn.getLong();
48 index = bufferIn.getLong();
49 }
50
132a02b0
MK
51 /**
52 * @return The timestamp
53 */
54 public long getTimestamp() {
55 return timestamp;
56 }
57
58 /**
59 * @return The index of the element
60 */
61 public long getIndex() {
62 return index;
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;
73 result = (prime * result) + (int) (index ^ (index >>> 32));
74 result = (prime * result) + (int) (timestamp ^ (timestamp >>> 32));
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;
132a02b0
MK
90 if (index != other.index) {
91 return false;
92 }
93 if (timestamp != other.timestamp) {
94 return false;
95 }
96 return true;
97 }
98
132a02b0
MK
99 @Override
100 public String toString() {
101 return "Element [" + timestamp + '/' + index + ']'; //$NON-NLS-1$
102 }
103
f5df94f8
AM
104 // ------------------------------------------------------------------------
105 // Comparable
106 // ------------------------------------------------------------------------
107
132a02b0 108 @Override
f5df94f8 109 public int compareTo(CtfLocationInfo other) {
132a02b0
MK
110 if (this.timestamp > other.getTimestamp()) {
111 return 1;
112 }
113 if (this.timestamp < other.getTimestamp()) {
114 return -1;
115 }
116 if (this.index > other.getIndex()) {
117 return 1;
118 }
119 if (this.index < other.getIndex()) {
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) {
134 bufferOut.putLong(timestamp);
135 bufferOut.putLong(index);
032ecd45 136 }
132a02b0 137}
This page took 0.054136 seconds and 5 git commands to generate.