Fix for bug382279
[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
MK
16/**
17 * The ctflocation is the nugget of information that is unique to a location in a trace.
18 * it can be copied and used to restore a position in a given trace.
19 */
0879b6b9 20public class CtfLocation implements ITmfLocation<Long>, Cloneable {
a3fc8213 21
9ac2eb62
MK
22 /**
23 * An invalid location
24 */
57c073c5
MK
25 public static final Long INVALID_LOCATION = -1L;
26
b1baa808
MK
27 /**
28 * Constructor for CtfLocation.
29 * @param location Long
30 */
a3fc8213
AM
31 public CtfLocation(Long location) {
32 setLocation(location);
33 }
ce2388e0 34
b1baa808
MK
35 /**
36 * Constructor for CtfLocation.
37 * @param timestamp ITmfTimestamp
38 */
a3fc8213
AM
39 public CtfLocation(ITmfTimestamp timestamp) {
40 setLocation(timestamp.getValue());
41 }
42
43 private Long fTimestamp;
44
b1baa808
MK
45 /**
46 * Method setLocation.
47 * @param location Long
48 */
a3fc8213
AM
49 public void setLocation(Long location) {
50 this.fTimestamp = location;
51 }
52
b1baa808
MK
53 /**
54 * Method getLocation.
55 * @return Long
56 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfLocation#getLocation()
57 */
a3fc8213
AM
58 @Override
59 public Long getLocation() {
60 return this.fTimestamp;
61 }
62
b1baa808
MK
63 /**
64 * Method clone.
65 * @return CtfLocation
66 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfLocation#clone()
67 */
a3fc8213
AM
68 @Override
69 public CtfLocation clone() {
408e65d2 70 return new CtfLocation(getLocation().longValue());
a3fc8213
AM
71 }
72
81c8e6f7
MK
73 /* (non-Javadoc)
74 * @see java.lang.Object#hashCode()
75 */
76 @Override
77 public int hashCode() {
78 final int prime = 31;
79 int result = 1;
80 result = (prime * result)
81 + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
82 return result;
83 }
84
85 /* (non-Javadoc)
86 * @see java.lang.Object#equals(java.lang.Object)
87 */
88 @Override
89 public boolean equals(Object obj) {
90 if (this == obj) {
91 return true;
92 }
93 if (obj == null) {
94 return false;
95 }
96 if (!(obj instanceof CtfLocation)) {
97 return false;
98 }
99 CtfLocation other = (CtfLocation) obj;
100 if (fTimestamp == null) {
101 if (other.fTimestamp != null) {
102 return false;
103 }
104 } else if (!fTimestamp.equals(other.fTimestamp)) {
105 return false;
106 }
107 return true;
108 }
109
eea58fe7
MK
110 /* (non-Javadoc)
111 * @see java.lang.Object#toString()
112 */
113 @Override
114 public String toString() {
115 if( this.getLocation().equals(CtfLocation.INVALID_LOCATION )) {
116 return "CtfLocation: INVALID"; //$NON-NLS-1$
117 }
118 return "CtfLocation: " + getLocation().toString(); //$NON-NLS-1$
119 }
120
a3fc8213 121}
This page took 0.033155 seconds and 5 git commands to generate.