ctf: Fix race condition in ctfiterator
[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
13/**
f5df94f8 14 * The data object to go in a {@link CtfLocation}.
132a02b0
MK
15 *
16 * @author Matthew Khouzam
17 * @since 2.0
18 */
f5df94f8 19public class CtfLocationInfo implements Comparable<CtfLocationInfo> {
132a02b0
MK
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 */
f5df94f8 31 public CtfLocationInfo(long ts, long index) {
132a02b0
MK
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
f5df94f8
AM
50 // ------------------------------------------------------------------------
51 // Object
52 // ------------------------------------------------------------------------
53
132a02b0
MK
54 @Override
55 public int hashCode() {
56 final int prime = 31;
57 int result = 1;
58 result = (prime * result) + (int) (index ^ (index >>> 32));
59 result = (prime * result) + (int) (timestamp ^ (timestamp >>> 32));
60 return result;
61 }
62
132a02b0
MK
63 @Override
64 public boolean equals(Object obj) {
65 if (this == obj) {
66 return true;
67 }
68 if (obj == null) {
69 return false;
70 }
f5df94f8 71 if (!(obj instanceof CtfLocationInfo)) {
132a02b0
MK
72 return false;
73 }
f5df94f8 74 CtfLocationInfo other = (CtfLocationInfo) obj;
132a02b0
MK
75 if (index != other.index) {
76 return false;
77 }
78 if (timestamp != other.timestamp) {
79 return false;
80 }
81 return true;
82 }
83
132a02b0
MK
84 @Override
85 public String toString() {
86 return "Element [" + timestamp + '/' + index + ']'; //$NON-NLS-1$
87 }
88
f5df94f8
AM
89 // ------------------------------------------------------------------------
90 // Comparable
91 // ------------------------------------------------------------------------
92
132a02b0 93 @Override
f5df94f8 94 public int compareTo(CtfLocationInfo other) {
132a02b0
MK
95 if (this.timestamp > other.getTimestamp()) {
96 return 1;
97 }
98 if (this.timestamp < other.getTimestamp()) {
99 return -1;
100 }
101 if (this.index > other.getIndex()) {
102 return 1;
103 }
104 if (this.index < other.getIndex()) {
105 return -1;
106 }
107 return 0;
108 }
109
110}
This page took 0.033753 seconds and 5 git commands to generate.