Commit | Line | Data |
---|---|---|
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 |
11 | package org.eclipse.linuxtools.tmf.core.ctfadaptor; |
12 | ||
13 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; | |
14 | import 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 | */ |
132a02b0 MK |
24 | public class CtfLocation implements ITmfLocation<CtfLocationData>, Cloneable { |
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 | /** |
132a02b0 MK |
34 | * Copy constructor |
35 | * | |
36 | * @param location | |
37 | * Other location to copy | |
38 | * @since 2.0 | |
b1baa808 | 39 | */ |
132a02b0 | 40 | public CtfLocation(CtfLocationData location) { |
a3fc8213 AM |
41 | setLocation(location); |
42 | } | |
ce2388e0 | 43 | |
b1baa808 | 44 | /** |
132a02b0 MK |
45 | * Standard constructor |
46 | * | |
47 | * @param timestamp | |
48 | * The timestamp of this location | |
49 | * @param index | |
50 | * The index of this location for this timestamp | |
51 | * @since 2.0 | |
52 | */ | |
53 | public CtfLocation(ITmfTimestamp timestamp, long index) { | |
54 | setLocation(new CtfLocationData(timestamp.getValue(), index)); | |
55 | } | |
56 | ||
57 | /** | |
58 | * Constructor for CtfLocation. Uses a default index of 0. | |
59 | * | |
60 | * @param timestamp | |
61 | * The timestamp of this location | |
b1baa808 | 62 | */ |
132a02b0 | 63 | @Deprecated |
a3fc8213 | 64 | public CtfLocation(ITmfTimestamp timestamp) { |
132a02b0 | 65 | setLocation(new CtfLocationData(timestamp.getValue(), 0)); |
a3fc8213 AM |
66 | } |
67 | ||
132a02b0 MK |
68 | /** |
69 | * Move this location to another location's position. | |
70 | * | |
71 | * @param location | |
72 | * The location to seek to | |
73 | * @since 2.0 | |
74 | */ | |
75 | public void setLocation(CtfLocationData location) { | |
76 | this.fLocation = location; | |
77 | } | |
a3fc8213 | 78 | |
b1baa808 | 79 | /** |
132a02b0 MK |
80 | * Change this location's timestamp and index values. |
81 | * | |
82 | * @param timestampValue | |
83 | * The new timestamp | |
84 | * @param index | |
85 | * The new index | |
86 | * @since 2.0 | |
b1baa808 | 87 | */ |
132a02b0 MK |
88 | public void setLocation(long timestampValue, long index) { |
89 | this.fLocation = new CtfLocationData(timestampValue, index); | |
a3fc8213 AM |
90 | } |
91 | ||
132a02b0 | 92 | |
b1baa808 | 93 | /** |
132a02b0 MK |
94 | * Get the Location Data of this location |
95 | * | |
96 | * @return The CtfLocationData | |
b1baa808 | 97 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfLocation#getLocation() |
132a02b0 | 98 | * @since 2.0 |
b1baa808 | 99 | */ |
a3fc8213 | 100 | @Override |
132a02b0 MK |
101 | public CtfLocationData getLocation() { |
102 | return fLocation; | |
a3fc8213 AM |
103 | } |
104 | ||
105 | @Override | |
106 | public CtfLocation clone() { | |
132a02b0 | 107 | return new CtfLocation(new CtfLocationData(fLocation.getTimestamp(), fLocation.getIndex())); |
a3fc8213 AM |
108 | } |
109 | ||
132a02b0 | 110 | |
81c8e6f7 MK |
111 | /* (non-Javadoc) |
112 | * @see java.lang.Object#hashCode() | |
113 | */ | |
114 | @Override | |
115 | public int hashCode() { | |
116 | final int prime = 31; | |
117 | int result = 1; | |
118 | result = (prime * result) | |
132a02b0 | 119 | + ((fLocation == null) ? 0 : fLocation.hashCode()); |
81c8e6f7 MK |
120 | return result; |
121 | } | |
122 | ||
123 | /* (non-Javadoc) | |
124 | * @see java.lang.Object#equals(java.lang.Object) | |
125 | */ | |
126 | @Override | |
127 | public boolean equals(Object obj) { | |
128 | if (this == obj) { | |
129 | return true; | |
130 | } | |
131 | if (obj == null) { | |
132 | return false; | |
133 | } | |
134 | if (!(obj instanceof CtfLocation)) { | |
135 | return false; | |
136 | } | |
137 | CtfLocation other = (CtfLocation) obj; | |
132a02b0 MK |
138 | if (fLocation == null) { |
139 | if (other.fLocation != null) { | |
81c8e6f7 MK |
140 | return false; |
141 | } | |
132a02b0 | 142 | } else if (!fLocation.equals(other.fLocation)) { |
81c8e6f7 MK |
143 | return false; |
144 | } | |
145 | return true; | |
146 | } | |
147 | ||
eea58fe7 MK |
148 | /* (non-Javadoc) |
149 | * @see java.lang.Object#toString() | |
150 | */ | |
151 | @Override | |
152 | public String toString() { | |
153 | if( this.getLocation().equals(CtfLocation.INVALID_LOCATION )) { | |
154 | return "CtfLocation: INVALID"; //$NON-NLS-1$ | |
155 | } | |
156 | return "CtfLocation: " + getLocation().toString(); //$NON-NLS-1$ | |
157 | } | |
158 | ||
132a02b0 | 159 | |
a3fc8213 | 160 | } |