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