Commit | Line | Data |
---|---|---|
8c8bf09f | 1 | /******************************************************************************* |
ce970a71 | 2 | * Copyright (c) 2009, 2012 Ericsson |
6256d8ad | 3 | * |
ce970a71 | 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 | |
8c8bf09f ASL |
6 | * accompanies this distribution, and is available at |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
6256d8ad | 8 | * |
bbc1c411 | 9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
ce970a71 | 11 | * Francois Chouinard - Updated as per TMF Event Model 1.0 |
8c8bf09f ASL |
12 | *******************************************************************************/ |
13 | ||
6c13869b | 14 | package org.eclipse.linuxtools.tmf.core.event; |
8c8bf09f | 15 | |
9b749023 | 16 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
6c13869b | 17 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
2c8610f7 | 18 | |
8c8bf09f | 19 | /** |
4c564a2d | 20 | * A basic implementation of ITmfEvent. |
b9e37ffd | 21 | * <p> |
d7dbf09a FC |
22 | * Note that for performance reasons TmfEvent is NOT immutable. If a shallow |
23 | * copy of the event is needed, use the copy constructor. Otherwise (deep copy) | |
24 | * use clone(). | |
6256d8ad | 25 | * |
b9e37ffd FC |
26 | * @version 1.0 |
27 | * @author Francois Chouinard | |
6256d8ad | 28 | * |
b9e37ffd FC |
29 | * @see ITmfTimestamp |
30 | * @see ITmfEventType | |
31 | * @see ITmfEventField | |
32 | * @see ITmfTrace | |
33 | */ | |
0316808c | 34 | public class TmfEvent implements ITmfEvent, Cloneable { |
12c155f5 | 35 | |
cbd4ad82 | 36 | // ------------------------------------------------------------------------ |
8c8bf09f | 37 | // Attributes |
cbd4ad82 | 38 | // ------------------------------------------------------------------------ |
8c8bf09f | 39 | |
6256d8ad | 40 | private ITmfTrace fTrace; |
7b477cc3 FC |
41 | private long fRank; |
42 | private ITmfTimestamp fTimestamp; | |
43 | private String fSource; | |
44 | private ITmfEventType fType; | |
45 | private ITmfEventField fContent; | |
46 | private String fReference; | |
28b94d61 | 47 | |
cbd4ad82 | 48 | // ------------------------------------------------------------------------ |
8c8bf09f | 49 | // Constructors |
cbd4ad82 | 50 | // ------------------------------------------------------------------------ |
8c8bf09f | 51 | |
2c8610f7 | 52 | /** |
f7703ed6 FC |
53 | * Default constructor. All fields have their default value (null) and the |
54 | * event rank is set to TmfContext.UNKNOWN_RANK. | |
2c8610f7 | 55 | */ |
ce970a71 | 56 | public TmfEvent() { |
9b749023 | 57 | this(null, ITmfContext.UNKNOWN_RANK, null, null, null, null, null); |
12c155f5 | 58 | } |
1f506a43 | 59 | |
12c155f5 | 60 | /** |
f7703ed6 FC |
61 | * Standard constructor. The event rank will be set to TmfContext.UNKNOWN_RANK. |
62 | * | |
63 | * @param trace the parent trace | |
64 | * @param timestamp the event timestamp | |
65 | * @param source the event source | |
66 | * @param type the event type | |
67 | * @param content the event content (payload) | |
68 | * @param reference the event reference | |
8c8bf09f | 69 | |
12c155f5 | 70 | */ |
6256d8ad | 71 | public TmfEvent(final ITmfTrace trace, final ITmfTimestamp timestamp, final String source, |
f7703ed6 | 72 | final ITmfEventType type, final ITmfEventField content, final String reference) |
4c564a2d | 73 | { |
9b749023 | 74 | this(trace, ITmfContext.UNKNOWN_RANK, timestamp, source, type, content, reference); |
12c155f5 | 75 | } |
8c8bf09f | 76 | |
b4d534a0 FC |
77 | /** |
78 | * Full constructor | |
6256d8ad | 79 | * |
b4d534a0 FC |
80 | * @param trace the parent trace |
81 | * @param rank the event rank (in the trace) | |
82 | * @param timestamp the event timestamp | |
83 | * @param source the event source | |
84 | * @param type the event type | |
0d9a6d76 | 85 | * @param content the event content (payload) |
b4d534a0 FC |
86 | * @param reference the event reference |
87 | */ | |
6256d8ad | 88 | public TmfEvent(final ITmfTrace trace, final long rank, final ITmfTimestamp timestamp, final String source, |
085d898f | 89 | final ITmfEventType type, final ITmfEventField content, final String reference) |
b4d534a0 FC |
90 | { |
91 | fTrace = trace; | |
92 | fRank = rank; | |
93 | fTimestamp = timestamp; | |
94 | fSource = source; | |
95 | fType = type; | |
96 | fContent = content; | |
97 | fReference = reference; | |
98 | } | |
99 | ||
12c155f5 | 100 | /** |
ce970a71 | 101 | * Copy constructor |
6256d8ad | 102 | * |
ce970a71 | 103 | * @param event the original event |
12c155f5 | 104 | */ |
085d898f | 105 | public TmfEvent(final ITmfEvent event) { |
b9e37ffd | 106 | if (event == null) { |
4c564a2d | 107 | throw new IllegalArgumentException(); |
b9e37ffd | 108 | } |
72f1e62a FC |
109 | fTrace = event.getTrace(); |
110 | fRank = event.getRank(); | |
111 | fTimestamp = event.getTimestamp(); | |
112 | fSource = event.getSource(); | |
113 | fType = event.getType(); | |
114 | fContent = event.getContent(); | |
115 | fReference = event.getReference(); | |
12c155f5 | 116 | } |
8c8bf09f | 117 | |
ce970a71 | 118 | // ------------------------------------------------------------------------ |
119 | // ITmfEvent | |
120 | // ------------------------------------------------------------------------ | |
8c8bf09f | 121 | |
d7dbf09a FC |
122 | /* (non-Javadoc) |
123 | * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getTrace() | |
124 | */ | |
125 | @Override | |
6256d8ad | 126 | public ITmfTrace getTrace() { |
4c564a2d FC |
127 | return fTrace; |
128 | } | |
129 | ||
d7dbf09a FC |
130 | /* (non-Javadoc) |
131 | * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getRank() | |
132 | */ | |
133 | @Override | |
4c564a2d FC |
134 | public long getRank() { |
135 | return fRank; | |
136 | } | |
137 | ||
d7dbf09a FC |
138 | /* (non-Javadoc) |
139 | * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getTimestamp() | |
140 | */ | |
141 | @Override | |
4df4581d | 142 | public ITmfTimestamp getTimestamp() { |
ce970a71 | 143 | return fTimestamp; |
12c155f5 | 144 | } |
1f506a43 | 145 | |
d7dbf09a FC |
146 | /* (non-Javadoc) |
147 | * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getSource() | |
148 | */ | |
149 | @Override | |
4c564a2d FC |
150 | public String getSource() { |
151 | return fSource; | |
152 | } | |
153 | ||
d7dbf09a FC |
154 | /* (non-Javadoc) |
155 | * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getType() | |
156 | */ | |
157 | @Override | |
4c564a2d FC |
158 | public ITmfEventType getType() { |
159 | return fType; | |
160 | } | |
161 | ||
d7dbf09a FC |
162 | /* (non-Javadoc) |
163 | * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getContent() | |
164 | */ | |
165 | @Override | |
4c564a2d FC |
166 | public ITmfEventField getContent() { |
167 | return fContent; | |
168 | } | |
169 | ||
d7dbf09a FC |
170 | /* (non-Javadoc) |
171 | * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getReference() | |
172 | */ | |
173 | @Override | |
4c564a2d FC |
174 | public String getReference() { |
175 | return fReference; | |
176 | } | |
177 | ||
178 | // ------------------------------------------------------------------------ | |
179 | // Convenience setters | |
180 | // ------------------------------------------------------------------------ | |
181 | ||
7b477cc3 | 182 | /** |
0d9a6d76 | 183 | * @param trace the new event trace |
7b477cc3 | 184 | */ |
6256d8ad | 185 | protected void setTrace(final ITmfTrace trace) { |
7b477cc3 FC |
186 | fTrace = trace; |
187 | } | |
188 | ||
4c564a2d | 189 | /** |
0d9a6d76 | 190 | * @param rank the new event rank |
4c564a2d | 191 | */ |
085d898f | 192 | protected void setRank(final long rank) { |
7b477cc3 | 193 | fRank = rank; |
4c564a2d FC |
194 | } |
195 | ||
196 | /** | |
197 | * @param timestamp the new event timestamp | |
198 | */ | |
085d898f | 199 | protected void setTimestamp(final ITmfTimestamp timestamp) { |
4c564a2d FC |
200 | fTimestamp = timestamp; |
201 | } | |
202 | ||
7b477cc3 FC |
203 | /** |
204 | * @param source the new event source | |
205 | */ | |
085d898f | 206 | protected void setSource(final String source) { |
7b477cc3 FC |
207 | fSource = source; |
208 | } | |
209 | ||
4c564a2d FC |
210 | /** |
211 | * @param type the new event type | |
212 | */ | |
085d898f | 213 | protected void setType(final ITmfEventType type) { |
4c564a2d FC |
214 | fType = type; |
215 | } | |
216 | ||
217 | /** | |
218 | * @param content the event new content | |
219 | */ | |
085d898f | 220 | protected void setContent(final ITmfEventField content) { |
4c564a2d FC |
221 | fContent = content; |
222 | } | |
223 | ||
224 | /** | |
225 | * @param reference the new event reference | |
226 | */ | |
085d898f | 227 | protected void setReference(final String reference) { |
4c564a2d FC |
228 | fReference = reference; |
229 | } | |
230 | ||
ce970a71 | 231 | // ------------------------------------------------------------------------ |
232 | // Cloneable | |
233 | // ------------------------------------------------------------------------ | |
cbd4ad82 | 234 | |
d7dbf09a FC |
235 | /* (non-Javadoc) |
236 | * @see java.lang.Object#clone() | |
237 | */ | |
ce970a71 | 238 | @Override |
239 | public TmfEvent clone() { | |
240 | TmfEvent clone = null; | |
4c564a2d FC |
241 | try { |
242 | clone = (TmfEvent) super.clone(); | |
243 | clone.fTrace = fTrace; | |
244 | clone.fRank = fRank; | |
245 | clone.fTimestamp = fTimestamp != null ? fTimestamp.clone() : null; | |
246 | clone.fSource = fSource; | |
247 | clone.fType = fType != null ? fType.clone() : null; | |
248 | clone.fContent = fContent != null ? fContent.clone() : null; | |
249 | clone.fReference = fReference; | |
085d898f | 250 | } catch (final CloneNotSupportedException e) { |
4c564a2d | 251 | } |
ce970a71 | 252 | return clone; |
12c155f5 | 253 | } |
c76c54bb | 254 | |
12c155f5 | 255 | // ------------------------------------------------------------------------ |
cbd4ad82 FC |
256 | // Object |
257 | // ------------------------------------------------------------------------ | |
28b94d61 | 258 | |
d7dbf09a FC |
259 | /* (non-Javadoc) |
260 | * @see java.lang.Object#hashCode() | |
261 | */ | |
12c155f5 | 262 | @Override |
cbd4ad82 | 263 | public int hashCode() { |
ce970a71 | 264 | final int prime = 31; |
4c564a2d FC |
265 | int result = 1; |
266 | result = prime * result + ((fTrace == null) ? 0 : fTrace.hashCode()); | |
267 | result = prime * result + (int) (fRank ^ (fRank >>> 32)); | |
ce970a71 | 268 | result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode()); |
4c564a2d FC |
269 | result = prime * result + ((fSource == null) ? 0 : fSource.hashCode()); |
270 | result = prime * result + ((fType == null) ? 0 : fType.hashCode()); | |
271 | result = prime * result + ((fContent == null) ? 0 : fContent.hashCode()); | |
272 | result = prime * result + ((fReference == null) ? 0 : fReference.hashCode()); | |
cbd4ad82 FC |
273 | return result; |
274 | } | |
275 | ||
d7dbf09a FC |
276 | /* (non-Javadoc) |
277 | * @see java.lang.Object#equals(java.lang.Object) | |
278 | */ | |
cbd4ad82 | 279 | @Override |
085d898f | 280 | public boolean equals(final Object obj) { |
b9e37ffd | 281 | if (this == obj) { |
ce970a71 | 282 | return true; |
b9e37ffd FC |
283 | } |
284 | if (obj == null) { | |
12c155f5 | 285 | return false; |
b9e37ffd FC |
286 | } |
287 | if (!(obj instanceof TmfEvent)) { | |
ce970a71 | 288 | return false; |
b9e37ffd | 289 | } |
085d898f | 290 | final TmfEvent other = (TmfEvent) obj; |
4c564a2d | 291 | if (fTrace == null) { |
b9e37ffd | 292 | if (other.fTrace != null) { |
4c564a2d | 293 | return false; |
b9e37ffd FC |
294 | } |
295 | } else if (!fTrace.equals(other.fTrace)) { | |
4c564a2d | 296 | return false; |
b9e37ffd FC |
297 | } |
298 | if (fRank != other.fRank) { | |
4c564a2d | 299 | return false; |
b9e37ffd | 300 | } |
ce970a71 | 301 | if (fTimestamp == null) { |
b9e37ffd | 302 | if (other.fTimestamp != null) { |
0c841e0f | 303 | return false; |
b9e37ffd FC |
304 | } |
305 | } else if (!fTimestamp.equals(other.fTimestamp)) { | |
ce970a71 | 306 | return false; |
b9e37ffd | 307 | } |
4c564a2d | 308 | if (fSource == null) { |
b9e37ffd | 309 | if (other.fSource != null) { |
4c564a2d | 310 | return false; |
b9e37ffd FC |
311 | } |
312 | } else if (!fSource.equals(other.fSource)) { | |
4c564a2d | 313 | return false; |
b9e37ffd | 314 | } |
4c564a2d | 315 | if (fType == null) { |
b9e37ffd | 316 | if (other.fType != null) { |
4c564a2d | 317 | return false; |
b9e37ffd FC |
318 | } |
319 | } else if (!fType.equals(other.fType)) { | |
4c564a2d | 320 | return false; |
b9e37ffd | 321 | } |
4c564a2d | 322 | if (fContent == null) { |
b9e37ffd | 323 | if (other.fContent != null) { |
4c564a2d | 324 | return false; |
b9e37ffd FC |
325 | } |
326 | } else if (!fContent.equals(other.fContent)) { | |
4c564a2d | 327 | return false; |
b9e37ffd | 328 | } |
4c564a2d | 329 | if (fReference == null) { |
b9e37ffd | 330 | if (other.fReference != null) { |
4c564a2d | 331 | return false; |
b9e37ffd FC |
332 | } |
333 | } else if (!fReference.equals(other.fReference)) { | |
4c564a2d | 334 | return false; |
b9e37ffd | 335 | } |
0c841e0f | 336 | return true; |
cbd4ad82 | 337 | } |
28b94d61 | 338 | |
d7dbf09a FC |
339 | /* (non-Javadoc) |
340 | * @see java.lang.Object#toString() | |
341 | */ | |
12c155f5 | 342 | @Override |
3b38ea61 | 343 | @SuppressWarnings("nls") |
12c155f5 | 344 | public String toString() { |
ce970a71 | 345 | return "TmfEvent [fTimestamp=" + fTimestamp + ", fTrace=" + fTrace + ", fRank=" + fRank |
085d898f FC |
346 | + ", fSource=" + fSource + ", fType=" + fType + ", fContent=" + fContent |
347 | + ", fReference=" + fReference + "]"; | |
12c155f5 | 348 | } |
f9673903 | 349 | |
8c8bf09f | 350 | } |