Fix tabs/spaces for ITmfEvent
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfContext.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 2012 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made 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:
10 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Updated as per TMF Trace Model 1.0
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.trace;
15
16 /**
17 * <b><u>TmfContext</u></b>
18 * <p>
19 * Trace context structure. It ties a trace location to an event rank. The
20 * context should be enough to restore the trace state so the corresponding
21 * event can be read.
22 */
23 public class TmfContext implements ITmfContext, Cloneable {
24
25 // ------------------------------------------------------------------------
26 // Attributes
27 // ------------------------------------------------------------------------
28
29 // The trace location
30 private ITmfLocation<? extends Comparable<?>> fLocation;
31
32 // The event rank
33 private long fRank;
34
35 // ------------------------------------------------------------------------
36 // Constructors
37 // ------------------------------------------------------------------------
38
39 /**
40 * Default constructor
41 */
42 public TmfContext() {
43 this(null, UNKNOWN_RANK);
44 }
45
46 /**
47 * Simple constructor (unknown rank)
48 *
49 * @param location the event location
50 */
51 public TmfContext(ITmfLocation<? extends Comparable<?>> location) {
52 this(location, UNKNOWN_RANK);
53 }
54
55 /**
56 * Full constructor
57 *
58 * @param location the event location
59 * @param rank the event rank
60 */
61 public TmfContext(ITmfLocation<? extends Comparable<?>> location, long rank) {
62 fLocation = location;
63 fRank = rank;
64 }
65
66 /**
67 * Copy constructor
68 *
69 * @param context the other context
70 */
71 public TmfContext(TmfContext context) {
72 this(context.fLocation, context.fRank);
73 }
74
75 // ------------------------------------------------------------------------
76 // Cloneable
77 // ------------------------------------------------------------------------
78
79 /* (non-Javadoc)
80 * @see java.lang.Object#clone()
81 */
82 @Override
83 public TmfContext clone() {
84 TmfContext clone = null;
85 try {
86 clone = (TmfContext) super.clone();
87 clone.fLocation = fLocation.clone();
88 clone.fRank = fRank;
89 } catch (CloneNotSupportedException e) {
90 }
91 return clone;
92 }
93
94 // ------------------------------------------------------------------------
95 // ITmfContext
96 // ------------------------------------------------------------------------
97
98 /* (non-Javadoc)
99 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getLocation()
100 */
101 @Override
102 public ITmfLocation<? extends Comparable<?>> getLocation() {
103 return fLocation;
104 }
105
106 /* (non-Javadoc)
107 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setLocation(org.eclipse.linuxtools.tmf.core.trace.ITmfLocation)
108 */
109 @Override
110 public void setLocation(ITmfLocation<? extends Comparable<?>> location) {
111 fLocation = location;
112 }
113
114 /* (non-Javadoc)
115 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getRank()
116 */
117 @Override
118 public long getRank() {
119 return fRank;
120 }
121
122 /* (non-Javadoc)
123 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setRank(long)
124 */
125 @Override
126 public void setRank(long rank) {
127 fRank = rank;
128 }
129
130 /* (non-Javadoc)
131 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#increaseRank()
132 */
133 @Override
134 public void increaseRank() {
135 if (hasValidRank())
136 fRank++;
137 }
138
139 /* (non-Javadoc)
140 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#hasValidRank()
141 */
142 @Override
143 public boolean hasValidRank() {
144 return fRank != UNKNOWN_RANK;
145 }
146
147 /* (non-Javadoc)
148 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#dispose()
149 */
150 @Override
151 public void dispose() {
152 }
153
154 // ------------------------------------------------------------------------
155 // Object
156 // ------------------------------------------------------------------------
157
158 /* (non-Javadoc)
159 * @see java.lang.Object#hashCode()
160 */
161 @Override
162 public int hashCode() {
163 final int prime = 31;
164 int result = 1;
165 result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode());
166 result = prime * result + (int) (fRank ^ (fRank >>> 32));
167 return result;
168 }
169
170 /* (non-Javadoc)
171 * @see java.lang.Object#equals(java.lang.Object)
172 */
173 @Override
174 public boolean equals(Object obj) {
175 if (this == obj)
176 return true;
177 if (obj == null)
178 return false;
179 if (getClass() != obj.getClass())
180 return false;
181 TmfContext other = (TmfContext) obj;
182 if (fLocation == null) {
183 if (other.fLocation != null)
184 return false;
185 } else if (!fLocation.equals(other.fLocation))
186 return false;
187 if (fRank != other.fRank)
188 return false;
189 return true;
190 }
191
192 /* (non-Javadoc)
193 * @see java.lang.Object#toString()
194 */
195 @Override
196 @SuppressWarnings("nls")
197 public String toString() {
198 return "TmfContext [fLocation=" + fLocation + ", fRank=" + fRank + "]";
199 }
200
201 }
This page took 0.035027 seconds and 6 git commands to generate.