Merge branch 'master' into lttng-kepler
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfLocation.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 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
14 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
15
16 /**
17 * The nugget of information that is unique to a location in a CTF trace.
18 *
19 * It can be copied and used to restore a position in a given trace.
20 *
21 * @version 1.0
22 * @author Matthew Khouzam
23 */
24 public class CtfLocation implements ITmfLocation<CtfLocationData>, Cloneable {
25
26 private CtfLocationData fLocation;
27
28 /**
29 * An invalid location
30 */
31 public static final CtfLocationData INVALID_LOCATION = new CtfLocationData(-1, -1);
32
33 /**
34 * Copy constructor
35 *
36 * @param location
37 * Other location to copy
38 * @since 2.0
39 */
40 public CtfLocation(CtfLocationData location) {
41 setLocation(location);
42 }
43
44 /**
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
62 */
63 @Deprecated
64 public CtfLocation(ITmfTimestamp timestamp) {
65 setLocation(new CtfLocationData(timestamp.getValue(), 0));
66 }
67
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 }
78
79 /**
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
87 */
88 public void setLocation(long timestampValue, long index) {
89 this.fLocation = new CtfLocationData(timestampValue, index);
90 }
91
92
93 /**
94 * Get the Location Data of this location
95 *
96 * @return The CtfLocationData
97 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfLocation#getLocation()
98 * @since 2.0
99 */
100 @Override
101 public CtfLocationData getLocation() {
102 return fLocation;
103 }
104
105 @Override
106 public CtfLocation clone() {
107 return new CtfLocation(new CtfLocationData(fLocation.getTimestamp(), fLocation.getIndex()));
108 }
109
110
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)
119 + ((fLocation == null) ? 0 : fLocation.hashCode());
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;
138 if (fLocation == null) {
139 if (other.fLocation != null) {
140 return false;
141 }
142 } else if (!fLocation.equals(other.fLocation)) {
143 return false;
144 }
145 return true;
146 }
147
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
159
160 }
This page took 0.041425 seconds and 6 git commands to generate.