Remove the generic location (replace by Comparable)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfLocation.java
CommitLineData
b1baa808
MK
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 *******************************************************************************/
a3fc8213
AM
11package org.eclipse.linuxtools.tmf.core.ctfadaptor;
12
13import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
14import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
15
b1baa808 16/**
d09f973b 17 * The nugget of information that is unique to a location in a CTF trace.
132a02b0 18 *
d09f973b 19 * It can be copied and used to restore a position in a given trace.
132a02b0 20 *
d09f973b
FC
21 * @version 1.0
22 * @author Matthew Khouzam
b1baa808 23 */
1e1bef82 24public class CtfLocation implements ITmfLocation, Cloneable {
132a02b0
MK
25
26 private CtfLocationData fLocation;
a3fc8213 27
9ac2eb62
MK
28 /**
29 * An invalid location
30 */
132a02b0 31 public static final CtfLocationData INVALID_LOCATION = new CtfLocationData(-1, -1);
57c073c5 32
b1baa808 33 /**
f0f3a065 34 * Constructor for CtfLocation. Uses a default index of 0.
132a02b0 35 *
f0f3a065
AM
36 * @param timestamp
37 * The timestamp of this location
b1baa808 38 */
f0f3a065
AM
39 public CtfLocation(ITmfTimestamp timestamp) {
40 setLocation(new CtfLocationData(timestamp.getValue(), 0));
a3fc8213 41 }
ce2388e0 42
b1baa808 43 /**
132a02b0
MK
44 * Standard constructor
45 *
46 * @param timestamp
47 * The timestamp of this location
48 * @param index
49 * The index of this location for this timestamp
50 * @since 2.0
51 */
52 public CtfLocation(ITmfTimestamp timestamp, long index) {
53 setLocation(new CtfLocationData(timestamp.getValue(), index));
54 }
55
56 /**
f0f3a065 57 * Copy constructor
132a02b0 58 *
f0f3a065
AM
59 * @param location
60 * Other location to copy
61 * @since 2.0
b1baa808 62 */
f0f3a065
AM
63 public CtfLocation(CtfLocationData location) {
64 setLocation(location);
a3fc8213
AM
65 }
66
132a02b0
MK
67 /**
68 * Move this location to another location's position.
69 *
70 * @param location
71 * The location to seek to
72 * @since 2.0
73 */
74 public void setLocation(CtfLocationData location) {
75 this.fLocation = location;
76 }
a3fc8213 77
b1baa808 78 /**
132a02b0
MK
79 * Change this location's timestamp and index values.
80 *
81 * @param timestampValue
82 * The new timestamp
83 * @param index
84 * The new index
85 * @since 2.0
b1baa808 86 */
132a02b0
MK
87 public void setLocation(long timestampValue, long index) {
88 this.fLocation = new CtfLocationData(timestampValue, index);
a3fc8213
AM
89 }
90
132a02b0 91
b1baa808 92 /**
132a02b0
MK
93 * Get the Location Data of this location
94 *
95 * @return The CtfLocationData
6bab4511 96 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfLocation#getLocationData()
132a02b0 97 * @since 2.0
b1baa808 98 */
a3fc8213 99 @Override
6bab4511 100 public CtfLocationData getLocationData() {
132a02b0 101 return fLocation;
a3fc8213
AM
102 }
103
104 @Override
105 public CtfLocation clone() {
132a02b0 106 return new CtfLocation(new CtfLocationData(fLocation.getTimestamp(), fLocation.getIndex()));
a3fc8213
AM
107 }
108
132a02b0 109
81c8e6f7
MK
110 /* (non-Javadoc)
111 * @see java.lang.Object#hashCode()
112 */
113 @Override
114 public int hashCode() {
115 final int prime = 31;
116 int result = 1;
117 result = (prime * result)
132a02b0 118 + ((fLocation == null) ? 0 : fLocation.hashCode());
81c8e6f7
MK
119 return result;
120 }
121
122 /* (non-Javadoc)
123 * @see java.lang.Object#equals(java.lang.Object)
124 */
125 @Override
126 public boolean equals(Object obj) {
127 if (this == obj) {
128 return true;
129 }
130 if (obj == null) {
131 return false;
132 }
133 if (!(obj instanceof CtfLocation)) {
134 return false;
135 }
136 CtfLocation other = (CtfLocation) obj;
132a02b0
MK
137 if (fLocation == null) {
138 if (other.fLocation != null) {
81c8e6f7
MK
139 return false;
140 }
132a02b0 141 } else if (!fLocation.equals(other.fLocation)) {
81c8e6f7
MK
142 return false;
143 }
144 return true;
145 }
146
eea58fe7
MK
147 /* (non-Javadoc)
148 * @see java.lang.Object#toString()
149 */
150 @Override
151 public String toString() {
6bab4511 152 if( this.getLocationData().equals(CtfLocation.INVALID_LOCATION )) {
eea58fe7
MK
153 return "CtfLocation: INVALID"; //$NON-NLS-1$
154 }
6bab4511 155 return "CtfLocation: " + getLocationData().toString(); //$NON-NLS-1$
eea58fe7
MK
156 }
157
132a02b0 158
a3fc8213 159}
This page took 0.045362 seconds and 5 git commands to generate.