1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
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
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11 package org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
;
13 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
14 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
17 * The nugget of information that is unique to a location in a CTF trace.
19 * It can be copied and used to restore a position in a given trace.
22 * @author Matthew Khouzam
24 public class CtfLocation
implements ITmfLocation
<CtfLocationData
>, Cloneable
{
26 private CtfLocationData fLocation
;
31 public static final CtfLocationData INVALID_LOCATION
= new CtfLocationData(-1, -1);
37 * Other location to copy
40 public CtfLocation(CtfLocationData location
) {
41 setLocation(location
);
45 * Standard constructor
48 * The timestamp of this location
50 * The index of this location for this timestamp
53 public CtfLocation(ITmfTimestamp timestamp
, long index
) {
54 setLocation(new CtfLocationData(timestamp
.getValue(), index
));
58 * Constructor for CtfLocation. Uses a default index of 0.
61 * The timestamp of this location
64 public CtfLocation(ITmfTimestamp timestamp
) {
65 setLocation(new CtfLocationData(timestamp
.getValue(), 0));
69 * Move this location to another location's position.
72 * The location to seek to
75 public void setLocation(CtfLocationData location
) {
76 this.fLocation
= location
;
80 * Change this location's timestamp and index values.
82 * @param timestampValue
88 public void setLocation(long timestampValue
, long index
) {
89 this.fLocation
= new CtfLocationData(timestampValue
, index
);
94 * Get the Location Data of this location
96 * @return The CtfLocationData
97 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfLocation#getLocation()
101 public CtfLocationData
getLocation() {
106 public CtfLocation
clone() {
107 return new CtfLocation(new CtfLocationData(fLocation
.getTimestamp(), fLocation
.getIndex()));
112 * @see java.lang.Object#hashCode()
115 public int hashCode() {
116 final int prime
= 31;
118 result
= (prime
* result
)
119 + ((fLocation
== null) ?
0 : fLocation
.hashCode());
124 * @see java.lang.Object#equals(java.lang.Object)
127 public boolean equals(Object obj
) {
134 if (!(obj
instanceof CtfLocation
)) {
137 CtfLocation other
= (CtfLocation
) obj
;
138 if (fLocation
== null) {
139 if (other
.fLocation
!= null) {
142 } else if (!fLocation
.equals(other
.fLocation
)) {
149 * @see java.lang.Object#toString()
152 public String
toString() {
153 if( this.getLocation().equals(CtfLocation
.INVALID_LOCATION
)) {
154 return "CtfLocation: INVALID"; //$NON-NLS-1$
156 return "CtfLocation: " + getLocation().toString(); //$NON-NLS-1$