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