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