tmf: Make CtfTmfEvent extend TmfEvent
[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 */
d62bb185 24public final class CtfLocation implements ITmfLocation {
132a02b0 25
d62bb185 26 private final 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 */
d62bb185
FC
39 public CtfLocation(final ITmfTimestamp timestamp) {
40 this(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 */
d62bb185
FC
52 public CtfLocation(final ITmfTimestamp timestamp, long index) {
53 this(timestamp.getValue(), index);
132a02b0
MK
54 }
55
56 /**
d62bb185 57 * Change this location's timestamp and index values.
132a02b0 58 *
d62bb185
FC
59 * @param timestampValue
60 * The new timestamp
61 * @param index
62 * The new index
f0f3a065 63 * @since 2.0
b1baa808 64 */
d62bb185
FC
65 public CtfLocation(final long timestampValue, final long index) {
66 this(new CtfLocationData(timestampValue, index));
a3fc8213
AM
67 }
68
132a02b0 69 /**
d62bb185 70 * Copy constructor
132a02b0
MK
71 *
72 * @param location
d62bb185 73 * Other location to copy
132a02b0 74 * @since 2.0
b1baa808 75 */
d62bb185
FC
76 public CtfLocation(final CtfLocationData location) {
77 fLocation = location;
a3fc8213
AM
78 }
79
b1baa808 80 /**
132a02b0
MK
81 * Get the Location Data of this location
82 *
83 * @return The CtfLocationData
5976d44a 84 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfLocation#getLocationInfo()
132a02b0 85 * @since 2.0
b1baa808 86 */
a3fc8213 87 @Override
5976d44a 88 public CtfLocationData getLocationInfo() {
132a02b0 89 return fLocation;
a3fc8213
AM
90 }
91
92 @Override
93 public CtfLocation clone() {
132a02b0 94 return new CtfLocation(new CtfLocationData(fLocation.getTimestamp(), fLocation.getIndex()));
a3fc8213
AM
95 }
96
132a02b0 97
81c8e6f7
MK
98 /* (non-Javadoc)
99 * @see java.lang.Object#hashCode()
100 */
101 @Override
102 public int hashCode() {
103 final int prime = 31;
104 int result = 1;
105 result = (prime * result)
132a02b0 106 + ((fLocation == null) ? 0 : fLocation.hashCode());
81c8e6f7
MK
107 return result;
108 }
109
110 /* (non-Javadoc)
111 * @see java.lang.Object#equals(java.lang.Object)
112 */
113 @Override
114 public boolean equals(Object obj) {
115 if (this == obj) {
116 return true;
117 }
118 if (obj == null) {
119 return false;
120 }
121 if (!(obj instanceof CtfLocation)) {
122 return false;
123 }
124 CtfLocation other = (CtfLocation) obj;
132a02b0
MK
125 if (fLocation == null) {
126 if (other.fLocation != null) {
81c8e6f7
MK
127 return false;
128 }
132a02b0 129 } else if (!fLocation.equals(other.fLocation)) {
81c8e6f7
MK
130 return false;
131 }
132 return true;
133 }
134
eea58fe7
MK
135 /* (non-Javadoc)
136 * @see java.lang.Object#toString()
137 */
138 @Override
139 public String toString() {
5976d44a 140 if( this.getLocationInfo().equals(CtfLocation.INVALID_LOCATION )) {
eea58fe7
MK
141 return "CtfLocation: INVALID"; //$NON-NLS-1$
142 }
5976d44a 143 return "CtfLocation: " + getLocationInfo().toString(); //$NON-NLS-1$
eea58fe7
MK
144 }
145
a3fc8213 146}
This page took 0.042183 seconds and 5 git commands to generate.