ctf: Fix lost events in a more elegant way
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfLocationData.java
1 /*******************************************************************************
2 * Copyright (c) 2012 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 /**
14 * CtfLocationData, the data in a CTF location.
15 *
16 * @author Matthew Khouzam
17 * @since 2.0
18 */
19 public class CtfLocationData implements Comparable<CtfLocationData> {
20
21 private final long timestamp;
22 private final long index;
23
24 /**
25 * @param ts
26 * Timestamp
27 * @param index
28 * Index of this event (if there are N elements with the same
29 * timestamp, which one is it.)
30 */
31 public CtfLocationData(long ts, long index) {
32 this.timestamp = ts;
33 this.index = index;
34 }
35
36 /**
37 * @return The timestamp
38 */
39 public long getTimestamp() {
40 return timestamp;
41 }
42
43 /**
44 * @return The index of the element
45 */
46 public long getIndex() {
47 return index;
48 }
49
50 /*
51 * (non-Javadoc)
52 *
53 * @see java.lang.Object#hashCode()
54 */
55 @Override
56 public int hashCode() {
57 final int prime = 31;
58 int result = 1;
59 result = (prime * result) + (int) (index ^ (index >>> 32));
60 result = (prime * result) + (int) (timestamp ^ (timestamp >>> 32));
61 return result;
62 }
63
64 /*
65 * (non-Javadoc)
66 *
67 * @see java.lang.Object#equals(java.lang.Object)
68 */
69 @Override
70 public boolean equals(Object obj) {
71 if (this == obj) {
72 return true;
73 }
74 if (obj == null) {
75 return false;
76 }
77 if (!(obj instanceof CtfLocationData)) {
78 return false;
79 }
80 CtfLocationData other = (CtfLocationData) obj;
81 if (index != other.index) {
82 return false;
83 }
84 if (timestamp != other.timestamp) {
85 return false;
86 }
87 return true;
88 }
89
90 /*
91 * (non-Javadoc)
92 *
93 * @see java.lang.Object#toString()
94 */
95 @Override
96 public String toString() {
97 return "Element [" + timestamp + '/' + index + ']'; //$NON-NLS-1$
98 }
99
100 @Override
101 public int compareTo(CtfLocationData other) {
102 if (this.timestamp > other.getTimestamp()) {
103 return 1;
104 }
105 if (this.timestamp < other.getTimestamp()) {
106 return -1;
107 }
108 if (this.index > other.getIndex()) {
109 return 1;
110 }
111 if (this.index < other.getIndex()) {
112 return -1;
113 }
114 return 0;
115 }
116
117 }
This page took 0.034044 seconds and 5 git commands to generate.