Fix javadoc warnings
[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
18 /**
19 * <b><u>TmfEvent</u></b>
20 * <p>
21 * A basic implementation of ITmfEvent.
22 *
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().
26 */
27 public class TmfEvent implements ITmfEvent {
28
29 // ------------------------------------------------------------------------
30 // Attributes
31 // ------------------------------------------------------------------------
32
33 private ITmfTrace<? extends ITmfEvent> fTrace;
34 private long fRank;
35 private ITmfTimestamp fTimestamp;
36 private String fSource;
37 private ITmfEventType fType;
38 private ITmfEventField fContent;
39 private String fReference;
40
41 // ------------------------------------------------------------------------
42 // Constructors
43 // ------------------------------------------------------------------------
44
45 /**
46 * Default constructor
47 */
48 public TmfEvent() {
49 this(null, -1, null, null, null, null, null);
50 }
51
52 /**
53 * Constructor - no rank
54 */
55 public TmfEvent(ITmfTrace<? extends ITmfEvent> trace, ITmfTimestamp timestamp, String source,
56 ITmfEventType type, ITmfEventField content, String reference)
57 {
58 this(trace, -1, timestamp, source, type, content, reference);
59 }
60
61 /**
62 * Constructor - no rank, no content
63 */
64 public TmfEvent(ITmfTrace<? extends ITmfEvent> trace, ITmfTimestamp timestamp, String source,
65 ITmfEventType type, String reference)
66 {
67 this(trace, -1, timestamp, source, type, null, reference);
68 }
69
70 /**
71 * Constructor - no rank, no content, no trace
72 */
73 public TmfEvent(ITmfTimestamp timestamp, String source, ITmfEventType type, String reference)
74 {
75 this(null, -1, timestamp, source, type, null, 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(ITmfTrace<? extends ITmfEvent> trace, long rank, ITmfTimestamp timestamp, String source,
90 ITmfEventType type, ITmfEventField content, 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(ITmfEvent event) {
107 if (event == null)
108 throw new IllegalArgumentException();
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<? extends ITmfEvent> 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(ITmfTrace<? extends ITmfEvent> trace) {
186 fTrace = trace;
187 }
188
189 /**
190 * @param rank the new event rank
191 */
192 protected void setRank(long rank) {
193 fRank = rank;
194 }
195
196 /**
197 * @param timestamp the new event timestamp
198 */
199 protected void setTimestamp(ITmfTimestamp timestamp) {
200 fTimestamp = timestamp;
201 }
202
203 /**
204 * @param source the new event source
205 */
206 protected void setSource(String source) {
207 fSource = source;
208 }
209
210 /**
211 * @param type the new event type
212 */
213 protected void setType(ITmfEventType type) {
214 fType = type;
215 }
216
217 /**
218 * @param content the event new content
219 */
220 protected void setContent(ITmfEventField content) {
221 fContent = content;
222 }
223
224 /**
225 * @param reference the new event reference
226 */
227 protected void setReference(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 (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(Object obj) {
281 if (this == obj)
282 return true;
283 if (obj == null)
284 return false;
285 if (!(obj instanceof TmfEvent))
286 return false;
287 TmfEvent other = (TmfEvent) obj;
288 if (fTrace == null) {
289 if (other.fTrace != null)
290 return false;
291 } else if (!fTrace.equals(other.fTrace))
292 return false;
293 if (fRank != other.fRank)
294 return false;
295 if (fTimestamp == null) {
296 if (other.fTimestamp != null)
297 return false;
298 } else if (!fTimestamp.equals(other.fTimestamp))
299 return false;
300 if (fSource == null) {
301 if (other.fSource != null)
302 return false;
303 } else if (!fSource.equals(other.fSource))
304 return false;
305 if (fType == null) {
306 if (other.fType != null)
307 return false;
308 } else if (!fType.equals(other.fType))
309 return false;
310 if (fContent == null) {
311 if (other.fContent != null)
312 return false;
313 } else if (!fContent.equals(other.fContent))
314 return false;
315 if (fReference == null) {
316 if (other.fReference != null)
317 return false;
318 } else if (!fReference.equals(other.fReference))
319 return false;
320 return true;
321 }
322
323 /* (non-Javadoc)
324 * @see java.lang.Object#toString()
325 */
326 @Override
327 @SuppressWarnings("nls")
328 public String toString() {
329 return "TmfEvent [fTimestamp=" + fTimestamp + ", fTrace=" + fTrace + ", fRank=" + fRank
330 + ", fSource=" + fSource + ", fType=" + fType + ", fContent=" + fContent
331 + ", fReference=" + fReference + "]";
332 }
333
334 }
This page took 0.037755 seconds and 6 git commands to generate.