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
.core
.runtime
.IAdaptable
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
19 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
22 * A basic implementation of ITmfEvent.
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)
29 * @author Francois Chouinard
36 public class TmfEvent
implements ITmfEvent
, IAdaptable
, Cloneable
{
38 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
42 private ITmfTrace fTrace
;
44 private ITmfTimestamp fTimestamp
;
45 private String fSource
;
46 private ITmfEventType fType
;
47 private ITmfEventField fContent
;
48 private String fReference
;
50 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
55 * Default constructor. All fields have their default value (null) and the
56 * event rank is set to TmfContext.UNKNOWN_RANK.
59 this(null, ITmfContext
.UNKNOWN_RANK
, null, null, null, null, null);
63 * Standard constructor. The event rank will be set to TmfContext.UNKNOWN_RANK.
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
73 public TmfEvent(final ITmfTrace trace
, final ITmfTimestamp timestamp
, final String source
,
74 final ITmfEventType type
, final ITmfEventField content
, final String reference
)
76 this(trace
, ITmfContext
.UNKNOWN_RANK
, timestamp
, source
, type
, content
, reference
);
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
87 * @param content the event content (payload)
88 * @param reference the event reference
90 public TmfEvent(final ITmfTrace trace
, final long rank
, final ITmfTimestamp timestamp
, final String source
,
91 final ITmfEventType type
, final ITmfEventField content
, final String reference
)
95 fTimestamp
= timestamp
;
99 fReference
= reference
;
105 * @param event the original event
107 public TmfEvent(final ITmfEvent event
) {
109 throw new IllegalArgumentException();
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();
120 // ------------------------------------------------------------------------
122 // ------------------------------------------------------------------------
125 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getTrace()
128 public ITmfTrace
getTrace() {
133 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getRank()
136 public long getRank() {
141 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getTimestamp()
144 public ITmfTimestamp
getTimestamp() {
149 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getSource()
152 public String
getSource() {
157 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getType()
160 public ITmfEventType
getType() {
165 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getContent()
168 public ITmfEventField
getContent() {
173 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getReference()
176 public String
getReference() {
180 // ------------------------------------------------------------------------
181 // Convenience setters
182 // ------------------------------------------------------------------------
185 * @param trace the new event trace
187 protected void setTrace(final ITmfTrace trace
) {
192 * @param rank the new event rank
194 protected void setRank(final long rank
) {
199 * @param timestamp the new event timestamp
201 protected void setTimestamp(final ITmfTimestamp timestamp
) {
202 fTimestamp
= timestamp
;
206 * @param source the new event source
208 protected void setSource(final String source
) {
213 * @param type the new event type
215 protected void setType(final ITmfEventType type
) {
220 * @param content the event new content
222 protected void setContent(final ITmfEventField content
) {
227 * @param reference the new event reference
229 protected void setReference(final String reference
) {
230 fReference
= reference
;
233 // ------------------------------------------------------------------------
235 // ------------------------------------------------------------------------
238 * @see java.lang.Object#clone()
241 public TmfEvent
clone() {
242 TmfEvent clone
= null;
244 clone
= (TmfEvent
) super.clone();
245 clone
.fTrace
= fTrace
;
247 clone
.fTimestamp
= fTimestamp
!= null ? fTimestamp
.clone() : null;
248 clone
.fSource
= fSource
;
249 clone
.fType
= fType
!= null ? fType
.clone() : null;
250 clone
.fContent
= fContent
!= null ? fContent
.clone() : null;
251 clone
.fReference
= fReference
;
252 } catch (final CloneNotSupportedException e
) {
257 // ------------------------------------------------------------------------
259 // ------------------------------------------------------------------------
262 * @see java.lang.Object#hashCode()
265 public int hashCode() {
266 final int prime
= 31;
268 result
= prime
* result
+ ((fTrace
== null) ?
0 : fTrace
.hashCode());
269 result
= prime
* result
+ (int) (fRank ^
(fRank
>>> 32));
270 result
= prime
* result
+ ((fTimestamp
== null) ?
0 : fTimestamp
.hashCode());
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());
279 * @see java.lang.Object#equals(java.lang.Object)
282 public boolean equals(final Object obj
) {
289 if (!(obj
instanceof TmfEvent
)) {
292 final TmfEvent other
= (TmfEvent
) obj
;
293 if (fTrace
== null) {
294 if (other
.fTrace
!= null) {
297 } else if (!fTrace
.equals(other
.fTrace
)) {
300 if (fRank
!= other
.fRank
) {
303 if (fTimestamp
== null) {
304 if (other
.fTimestamp
!= null) {
307 } else if (!fTimestamp
.equals(other
.fTimestamp
)) {
310 if (fSource
== null) {
311 if (other
.fSource
!= null) {
314 } else if (!fSource
.equals(other
.fSource
)) {
318 if (other
.fType
!= null) {
321 } else if (!fType
.equals(other
.fType
)) {
324 if (fContent
== null) {
325 if (other
.fContent
!= null) {
328 } else if (!fContent
.equals(other
.fContent
)) {
331 if (fReference
== null) {
332 if (other
.fReference
!= null) {
335 } else if (!fReference
.equals(other
.fReference
)) {
342 * @see java.lang.Object#toString()
345 @SuppressWarnings("nls")
346 public String
toString() {
347 return "TmfEvent [fTimestamp=" + fTimestamp
+ ", fTrace=" + fTrace
+ ", fRank=" + fRank
348 + ", fSource=" + fSource
+ ", fType=" + fType
+ ", fContent=" + fContent
349 + ", fReference=" + fReference
+ "]";
353 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
359 public Object
getAdapter(Class adapter
) {
360 if (adapter
== IPropertySource
.class) {
361 return new TmfEventPropertySource(this);