Merge branch 'master' into lttng-kepler
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / event / TmfEvent.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 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:
10 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Updated as per TMF Event Model 1.0
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.event;
15
16 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
17 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
18
19 /**
20 * A basic implementation of ITmfEvent.
21 * <p>
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().
25 *
26 * @version 1.0
27 * @author Francois Chouinard
28 *
29 * @see ITmfTimestamp
30 * @see ITmfEventType
31 * @see ITmfEventField
32 * @see ITmfTrace
33 */
34 public class TmfEvent implements ITmfEvent, Cloneable {
35
36 // ------------------------------------------------------------------------
37 // Attributes
38 // ------------------------------------------------------------------------
39
40 private ITmfTrace fTrace;
41 private long fRank;
42 private ITmfTimestamp fTimestamp;
43 private String fSource;
44 private ITmfEventType fType;
45 private ITmfEventField fContent;
46 private String fReference;
47
48 // ------------------------------------------------------------------------
49 // Constructors
50 // ------------------------------------------------------------------------
51
52 /**
53 * Default constructor. All fields have their default value (null) and the
54 * event rank is set to TmfContext.UNKNOWN_RANK.
55 */
56 public TmfEvent() {
57 this(null, ITmfContext.UNKNOWN_RANK, null, null, null, null, null);
58 }
59
60 /**
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
69
70 */
71 public TmfEvent(final ITmfTrace trace, final ITmfTimestamp timestamp, final String source,
72 final ITmfEventType type, final ITmfEventField content, final String reference)
73 {
74 this(trace, ITmfContext.UNKNOWN_RANK, timestamp, source, type, content, reference);
75 }
76
77 /**
78 * Full constructor
79 *
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
85 * @param content the event content (payload)
86 * @param reference the event reference
87 */
88 public TmfEvent(final ITmfTrace trace, final long rank, final ITmfTimestamp timestamp, final String source,
89 final ITmfEventType type, final ITmfEventField content, final String reference)
90 {
91 fTrace = trace;
92 fRank = rank;
93 fTimestamp = timestamp;
94 fSource = source;
95 fType = type;
96 fContent = content;
97 fReference = reference;
98 }
99
100 /**
101 * Copy constructor
102 *
103 * @param event the original event
104 */
105 public TmfEvent(final ITmfEvent event) {
106 if (event == null) {
107 throw new IllegalArgumentException();
108 }
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();
116 }
117
118 // ------------------------------------------------------------------------
119 // ITmfEvent
120 // ------------------------------------------------------------------------
121
122 /* (non-Javadoc)
123 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getTrace()
124 */
125 @Override
126 public ITmfTrace getTrace() {
127 return fTrace;
128 }
129
130 /* (non-Javadoc)
131 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getRank()
132 */
133 @Override
134 public long getRank() {
135 return fRank;
136 }
137
138 /* (non-Javadoc)
139 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getTimestamp()
140 */
141 @Override
142 public ITmfTimestamp getTimestamp() {
143 return fTimestamp;
144 }
145
146 /* (non-Javadoc)
147 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getSource()
148 */
149 @Override
150 public String getSource() {
151 return fSource;
152 }
153
154 /* (non-Javadoc)
155 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getType()
156 */
157 @Override
158 public ITmfEventType getType() {
159 return fType;
160 }
161
162 /* (non-Javadoc)
163 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getContent()
164 */
165 @Override
166 public ITmfEventField getContent() {
167 return fContent;
168 }
169
170 /* (non-Javadoc)
171 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getReference()
172 */
173 @Override
174 public String getReference() {
175 return fReference;
176 }
177
178 // ------------------------------------------------------------------------
179 // Convenience setters
180 // ------------------------------------------------------------------------
181
182 /**
183 * @param trace the new event trace
184 */
185 protected void setTrace(final ITmfTrace trace) {
186 fTrace = trace;
187 }
188
189 /**
190 * @param rank the new event rank
191 */
192 protected void setRank(final long rank) {
193 fRank = rank;
194 }
195
196 /**
197 * @param timestamp the new event timestamp
198 */
199 protected void setTimestamp(final ITmfTimestamp timestamp) {
200 fTimestamp = timestamp;
201 }
202
203 /**
204 * @param source the new event source
205 */
206 protected void setSource(final String source) {
207 fSource = source;
208 }
209
210 /**
211 * @param type the new event type
212 */
213 protected void setType(final ITmfEventType type) {
214 fType = type;
215 }
216
217 /**
218 * @param content the event new content
219 */
220 protected void setContent(final ITmfEventField content) {
221 fContent = content;
222 }
223
224 /**
225 * @param reference the new event reference
226 */
227 protected void setReference(final String reference) {
228 fReference = reference;
229 }
230
231 // ------------------------------------------------------------------------
232 // Cloneable
233 // ------------------------------------------------------------------------
234
235 /* (non-Javadoc)
236 * @see java.lang.Object#clone()
237 */
238 @Override
239 public TmfEvent clone() {
240 TmfEvent clone = null;
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;
250 } catch (final CloneNotSupportedException e) {
251 }
252 return clone;
253 }
254
255 // ------------------------------------------------------------------------
256 // Object
257 // ------------------------------------------------------------------------
258
259 /* (non-Javadoc)
260 * @see java.lang.Object#hashCode()
261 */
262 @Override
263 public int hashCode() {
264 final int prime = 31;
265 int result = 1;
266 result = prime * result + ((fTrace == null) ? 0 : fTrace.hashCode());
267 result = prime * result + (int) (fRank ^ (fRank >>> 32));
268 result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
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());
273 return result;
274 }
275
276 /* (non-Javadoc)
277 * @see java.lang.Object#equals(java.lang.Object)
278 */
279 @Override
280 public boolean equals(final Object obj) {
281 if (this == obj) {
282 return true;
283 }
284 if (obj == null) {
285 return false;
286 }
287 if (!(obj instanceof TmfEvent)) {
288 return false;
289 }
290 final TmfEvent other = (TmfEvent) obj;
291 if (fTrace == null) {
292 if (other.fTrace != null) {
293 return false;
294 }
295 } else if (!fTrace.equals(other.fTrace)) {
296 return false;
297 }
298 if (fRank != other.fRank) {
299 return false;
300 }
301 if (fTimestamp == null) {
302 if (other.fTimestamp != null) {
303 return false;
304 }
305 } else if (!fTimestamp.equals(other.fTimestamp)) {
306 return false;
307 }
308 if (fSource == null) {
309 if (other.fSource != null) {
310 return false;
311 }
312 } else if (!fSource.equals(other.fSource)) {
313 return false;
314 }
315 if (fType == null) {
316 if (other.fType != null) {
317 return false;
318 }
319 } else if (!fType.equals(other.fType)) {
320 return false;
321 }
322 if (fContent == null) {
323 if (other.fContent != null) {
324 return false;
325 }
326 } else if (!fContent.equals(other.fContent)) {
327 return false;
328 }
329 if (fReference == null) {
330 if (other.fReference != null) {
331 return false;
332 }
333 } else if (!fReference.equals(other.fReference)) {
334 return false;
335 }
336 return true;
337 }
338
339 /* (non-Javadoc)
340 * @see java.lang.Object#toString()
341 */
342 @Override
343 @SuppressWarnings("nls")
344 public String toString() {
345 return "TmfEvent [fTimestamp=" + fTimestamp + ", fTrace=" + fTrace + ", fRank=" + fRank
346 + ", fSource=" + fSource + ", fType=" + fType + ", fContent=" + fContent
347 + ", fReference=" + fReference + "]";
348 }
349
350 }
This page took 0.056942 seconds and 6 git commands to generate.