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 | */ | |
4c564a2d | 36 | protected ITmfTrace<? extends TmfEvent> 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() { |
2c8610f7 FC |
76 | } |
77 | ||
4bf17f4a | 78 | /** |
ce970a71 | 79 | * Full constructor |
80 | * | |
4bf17f4a | 81 | * @param trace the parent trace |
4c564a2d | 82 | * @param rank the event rank (in the trace) |
ce970a71 | 83 | * @param timestamp the event timestamp |
84 | * @param source the event source | |
4bf17f4a | 85 | * @param type the event type |
4c564a2d | 86 | * @param type the event content (payload) |
ce970a71 | 87 | * @param reference the event reference |
12c155f5 | 88 | */ |
4c564a2d | 89 | public TmfEvent(ITmfTrace<? extends TmfEvent> trace, long rank, ITmfTimestamp timestamp, String source, |
d7dbf09a | 90 | ITmfEventType type, ITmfEventField content, String reference) |
5179fc01 | 91 | { |
4c564a2d FC |
92 | fTrace = trace; |
93 | fRank = rank; | |
ce970a71 | 94 | fTimestamp = timestamp; |
4c564a2d FC |
95 | fSource = source; |
96 | fType = type; | |
97 | fContent = content; | |
98 | fReference = reference; | |
12c155f5 | 99 | } |
1f506a43 | 100 | |
12c155f5 | 101 | /** |
ce970a71 | 102 | * Constructor - no rank |
12c155f5 | 103 | */ |
4c564a2d | 104 | public TmfEvent(ITmfTrace<? extends TmfEvent> trace, ITmfTimestamp timestamp, String source, |
d7dbf09a | 105 | ITmfEventType type, ITmfEventField content, String reference) |
5179fc01 | 106 | { |
4c564a2d | 107 | this(trace, -1, timestamp, source, type, content, reference); |
12c155f5 | 108 | } |
8c8bf09f | 109 | |
12c155f5 | 110 | /** |
4c564a2d | 111 | * Constructor - no rank, no content |
12c155f5 | 112 | */ |
4c564a2d | 113 | public TmfEvent(ITmfTrace<? extends TmfEvent> trace, ITmfTimestamp timestamp, String source, |
d7dbf09a | 114 | ITmfEventType type, String reference) |
4c564a2d FC |
115 | { |
116 | this(trace, -1, timestamp, source, type, null, reference); | |
117 | } | |
118 | ||
119 | /** | |
120 | * Constructor - no rank, no content, no trace | |
121 | */ | |
d7dbf09a | 122 | public TmfEvent(TmfTimestamp timestamp, String source, ITmfEventType type, String reference) |
4c564a2d FC |
123 | { |
124 | this(null, -1, timestamp, source, type, null, reference); | |
12c155f5 | 125 | } |
8c8bf09f | 126 | |
12c155f5 | 127 | /** |
ce970a71 | 128 | * Copy constructor |
129 | * | |
130 | * @param event the original event | |
12c155f5 | 131 | */ |
ce970a71 | 132 | public TmfEvent(TmfEvent event) { |
4c564a2d FC |
133 | if (event == null) |
134 | throw new IllegalArgumentException(); | |
135 | fTrace = event.fTrace; | |
136 | fRank = event.fRank; | |
137 | fTimestamp = event.fTimestamp; | |
138 | fSource = event.fSource; | |
139 | fType = event.fType; | |
140 | fContent = event.fContent; | |
141 | fReference = event.fReference; | |
12c155f5 | 142 | } |
8c8bf09f | 143 | |
ce970a71 | 144 | // ------------------------------------------------------------------------ |
145 | // ITmfEvent | |
146 | // ------------------------------------------------------------------------ | |
8c8bf09f | 147 | |
d7dbf09a FC |
148 | /* (non-Javadoc) |
149 | * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getTrace() | |
150 | */ | |
151 | @Override | |
4c564a2d FC |
152 | public ITmfTrace<? extends TmfEvent> getTrace() { |
153 | return fTrace; | |
154 | } | |
155 | ||
d7dbf09a FC |
156 | /* (non-Javadoc) |
157 | * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getRank() | |
158 | */ | |
159 | @Override | |
4c564a2d FC |
160 | public long getRank() { |
161 | return fRank; | |
162 | } | |
163 | ||
d7dbf09a FC |
164 | /* (non-Javadoc) |
165 | * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getTimestamp() | |
166 | */ | |
167 | @Override | |
4df4581d | 168 | public ITmfTimestamp getTimestamp() { |
ce970a71 | 169 | return fTimestamp; |
12c155f5 | 170 | } |
1f506a43 | 171 | |
d7dbf09a FC |
172 | /* (non-Javadoc) |
173 | * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getSource() | |
174 | */ | |
175 | @Override | |
4c564a2d FC |
176 | public String getSource() { |
177 | return fSource; | |
178 | } | |
179 | ||
d7dbf09a FC |
180 | /* (non-Javadoc) |
181 | * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getType() | |
182 | */ | |
183 | @Override | |
4c564a2d FC |
184 | public ITmfEventType getType() { |
185 | return fType; | |
186 | } | |
187 | ||
d7dbf09a FC |
188 | /* (non-Javadoc) |
189 | * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getContent() | |
190 | */ | |
191 | @Override | |
4c564a2d FC |
192 | public ITmfEventField getContent() { |
193 | return fContent; | |
194 | } | |
195 | ||
d7dbf09a FC |
196 | /* (non-Javadoc) |
197 | * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getReference() | |
198 | */ | |
199 | @Override | |
4c564a2d FC |
200 | public String getReference() { |
201 | return fReference; | |
202 | } | |
203 | ||
204 | // ------------------------------------------------------------------------ | |
205 | // Convenience setters | |
206 | // ------------------------------------------------------------------------ | |
207 | ||
208 | /** | |
209 | * @param source the new event source | |
210 | */ | |
211 | public void setSource(String source) { | |
212 | fSource = source; | |
213 | } | |
214 | ||
215 | /** | |
216 | * @param timestamp the new event timestamp | |
217 | */ | |
218 | public void setTimestamp(ITmfTimestamp timestamp) { | |
219 | fTimestamp = timestamp; | |
220 | } | |
221 | ||
222 | /** | |
223 | * @param type the new event type | |
224 | */ | |
d7dbf09a | 225 | public void setType(ITmfEventType type) { |
4c564a2d FC |
226 | fType = type; |
227 | } | |
228 | ||
229 | /** | |
230 | * @param content the event new content | |
231 | */ | |
232 | public void setContent(ITmfEventField content) { | |
233 | fContent = content; | |
234 | } | |
235 | ||
236 | /** | |
237 | * @param reference the new event reference | |
238 | */ | |
239 | public void setReference(String reference) { | |
240 | fReference = reference; | |
241 | } | |
242 | ||
ce970a71 | 243 | // ------------------------------------------------------------------------ |
244 | // Cloneable | |
245 | // ------------------------------------------------------------------------ | |
cbd4ad82 | 246 | |
d7dbf09a FC |
247 | /* (non-Javadoc) |
248 | * @see java.lang.Object#clone() | |
249 | */ | |
ce970a71 | 250 | @Override |
251 | public TmfEvent clone() { | |
252 | TmfEvent clone = null; | |
4c564a2d FC |
253 | try { |
254 | clone = (TmfEvent) super.clone(); | |
255 | clone.fTrace = fTrace; | |
256 | clone.fRank = fRank; | |
257 | clone.fTimestamp = fTimestamp != null ? fTimestamp.clone() : null; | |
258 | clone.fSource = fSource; | |
259 | clone.fType = fType != null ? fType.clone() : null; | |
260 | clone.fContent = fContent != null ? fContent.clone() : null; | |
261 | clone.fReference = fReference; | |
262 | } catch (CloneNotSupportedException e) { | |
263 | } | |
ce970a71 | 264 | return clone; |
12c155f5 | 265 | } |
c76c54bb | 266 | |
12c155f5 | 267 | // ------------------------------------------------------------------------ |
cbd4ad82 FC |
268 | // Object |
269 | // ------------------------------------------------------------------------ | |
28b94d61 | 270 | |
d7dbf09a FC |
271 | /* (non-Javadoc) |
272 | * @see java.lang.Object#hashCode() | |
273 | */ | |
12c155f5 | 274 | @Override |
cbd4ad82 | 275 | public int hashCode() { |
ce970a71 | 276 | final int prime = 31; |
4c564a2d FC |
277 | int result = 1; |
278 | result = prime * result + ((fTrace == null) ? 0 : fTrace.hashCode()); | |
279 | result = prime * result + (int) (fRank ^ (fRank >>> 32)); | |
ce970a71 | 280 | result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode()); |
4c564a2d FC |
281 | result = prime * result + ((fSource == null) ? 0 : fSource.hashCode()); |
282 | result = prime * result + ((fType == null) ? 0 : fType.hashCode()); | |
283 | result = prime * result + ((fContent == null) ? 0 : fContent.hashCode()); | |
284 | result = prime * result + ((fReference == null) ? 0 : fReference.hashCode()); | |
cbd4ad82 FC |
285 | return result; |
286 | } | |
287 | ||
d7dbf09a FC |
288 | /* (non-Javadoc) |
289 | * @see java.lang.Object#equals(java.lang.Object) | |
290 | */ | |
cbd4ad82 | 291 | @Override |
ce970a71 | 292 | public boolean equals(Object obj) { |
293 | if (this == obj) | |
294 | return true; | |
4c564a2d | 295 | if (obj == null) |
12c155f5 | 296 | return false; |
ce970a71 | 297 | if (getClass() != obj.getClass()) |
298 | return false; | |
299 | TmfEvent other = (TmfEvent) obj; | |
4c564a2d FC |
300 | if (fTrace == null) { |
301 | if (other.fTrace != null) | |
302 | return false; | |
303 | } else if (!fTrace.equals(other.fTrace)) | |
304 | return false; | |
305 | if (fRank != other.fRank) | |
306 | return false; | |
ce970a71 | 307 | if (fTimestamp == null) { |
308 | if (other.fTimestamp != null) | |
0c841e0f | 309 | return false; |
ce970a71 | 310 | } else if (!fTimestamp.equals(other.fTimestamp)) |
311 | return false; | |
4c564a2d FC |
312 | if (fSource == null) { |
313 | if (other.fSource != null) | |
314 | return false; | |
315 | } else if (!fSource.equals(other.fSource)) | |
316 | return false; | |
317 | if (fType == null) { | |
318 | if (other.fType != null) | |
319 | return false; | |
320 | } else if (!fType.equals(other.fType)) | |
321 | return false; | |
322 | if (fContent == null) { | |
323 | if (other.fContent != null) | |
324 | return false; | |
325 | } else if (!fContent.equals(other.fContent)) | |
326 | return false; | |
327 | if (fReference == null) { | |
328 | if (other.fReference != null) | |
329 | return false; | |
330 | } else if (!fReference.equals(other.fReference)) | |
331 | return false; | |
0c841e0f | 332 | return true; |
cbd4ad82 | 333 | } |
28b94d61 | 334 | |
d7dbf09a FC |
335 | /* (non-Javadoc) |
336 | * @see java.lang.Object#toString() | |
337 | */ | |
12c155f5 | 338 | @Override |
3b38ea61 | 339 | @SuppressWarnings("nls") |
12c155f5 | 340 | public String toString() { |
ce970a71 | 341 | return "TmfEvent [fTimestamp=" + fTimestamp + ", fTrace=" + fTrace + ", fRank=" + fRank |
342 | + ", fSource=" + fSource + ", fType=" + fType + ", fContent=" + fContent | |
343 | + ", fReference=" + fReference + "]"; | |
12c155f5 | 344 | } |
f9673903 | 345 | |
8c8bf09f | 346 | } |