1 /*******************************************************************************
2 * Copyright (c) 2009, 2012 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Updated as per TMF Event Model 1.0
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.event
;
16 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
19 * <b><u>TmfEvent</u></b>
21 * A basic implementation of ITmfEvent.
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)
27 public class TmfEvent
implements ITmfEvent
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 private ITmfTrace
<?
extends ITmfEvent
> fTrace
;
35 private ITmfTimestamp fTimestamp
;
36 private String fSource
;
37 private ITmfEventType fType
;
38 private ITmfEventField fContent
;
39 private String fReference
;
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
49 this(null, -1, null, null, null, null, null);
53 * Constructor - no rank
55 public TmfEvent(ITmfTrace
<?
extends ITmfEvent
> trace
, ITmfTimestamp timestamp
, String source
,
56 ITmfEventType type
, ITmfEventField content
, String reference
)
58 this(trace
, -1, timestamp
, source
, type
, content
, reference
);
62 * Constructor - no rank, no content
64 public TmfEvent(ITmfTrace
<?
extends ITmfEvent
> trace
, ITmfTimestamp timestamp
, String source
,
65 ITmfEventType type
, String reference
)
67 this(trace
, -1, timestamp
, source
, type
, null, reference
);
71 * Constructor - no rank, no content, no trace
73 public TmfEvent(ITmfTimestamp timestamp
, String source
, ITmfEventType type
, String reference
)
75 this(null, -1, timestamp
, source
, type
, null, reference
);
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
89 public TmfEvent(ITmfTrace
<?
extends ITmfEvent
> trace
, long rank
, ITmfTimestamp timestamp
, String source
,
90 ITmfEventType type
, ITmfEventField content
, String reference
)
94 fTimestamp
= timestamp
;
98 fReference
= reference
;
104 * @param event the original event
106 public TmfEvent(ITmfEvent event
) {
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();
118 // ------------------------------------------------------------------------
120 // ------------------------------------------------------------------------
123 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getTrace()
126 public ITmfTrace
<?
extends ITmfEvent
> getTrace() {
131 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getRank()
134 public long getRank() {
139 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getTimestamp()
142 public ITmfTimestamp
getTimestamp() {
147 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getSource()
150 public String
getSource() {
155 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getType()
158 public ITmfEventType
getType() {
163 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getContent()
166 public ITmfEventField
getContent() {
171 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getReference()
174 public String
getReference() {
178 // ------------------------------------------------------------------------
179 // Convenience setters
180 // ------------------------------------------------------------------------
183 * @param trace the new event trace
185 protected void setTrace(ITmfTrace
<?
extends ITmfEvent
> trace
) {
190 * @param rank the new event rank
192 protected void setRank(long rank
) {
197 * @param timestamp the new event timestamp
199 protected void setTimestamp(ITmfTimestamp timestamp
) {
200 fTimestamp
= timestamp
;
204 * @param source the new event source
206 protected void setSource(String source
) {
211 * @param type the new event type
213 protected void setType(ITmfEventType type
) {
218 * @param content the event new content
220 protected void setContent(ITmfEventField content
) {
225 * @param reference the new event reference
227 protected void setReference(String reference
) {
228 fReference
= reference
;
231 // ------------------------------------------------------------------------
233 // ------------------------------------------------------------------------
236 * @see java.lang.Object#clone()
239 public TmfEvent
clone() {
240 TmfEvent clone
= null;
242 clone
= (TmfEvent
) super.clone();
243 clone
.fTrace
= fTrace
;
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
) {
255 // ------------------------------------------------------------------------
257 // ------------------------------------------------------------------------
260 * @see java.lang.Object#hashCode()
263 public int hashCode() {
264 final int prime
= 31;
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());
277 * @see java.lang.Object#equals(java.lang.Object)
280 public boolean equals(Object obj
) {
285 if (!(obj
instanceof TmfEvent
))
287 TmfEvent other
= (TmfEvent
) obj
;
288 if (fTrace
== null) {
289 if (other
.fTrace
!= null)
291 } else if (!fTrace
.equals(other
.fTrace
))
293 if (fRank
!= other
.fRank
)
295 if (fTimestamp
== null) {
296 if (other
.fTimestamp
!= null)
298 } else if (!fTimestamp
.equals(other
.fTimestamp
))
300 if (fSource
== null) {
301 if (other
.fSource
!= null)
303 } else if (!fSource
.equals(other
.fSource
))
306 if (other
.fType
!= null)
308 } else if (!fType
.equals(other
.fType
))
310 if (fContent
== null) {
311 if (other
.fContent
!= null)
313 } else if (!fContent
.equals(other
.fContent
))
315 if (fReference
== null) {
316 if (other
.fReference
!= null)
318 } else if (!fReference
.equals(other
.fReference
))
324 * @see java.lang.Object#toString()
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
+ "]";