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