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