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
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
20 * A basic implementation of ITmfEvent.
22 * Note that for performance reasons TmfEvent is NOT immutable. If a shallow
23 * copy of the event is needed, use the copy constructor. Otherwise (deep copy)
28 * @author Francois Chouinard
35 public class TmfEvent
implements ITmfEvent
{
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
41 private ITmfTrace
<?
extends ITmfEvent
> fTrace
;
43 private ITmfTimestamp fTimestamp
;
44 private String fSource
;
45 private ITmfEventType fType
;
46 private ITmfEventField fContent
;
47 private String fReference
;
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
54 * Default constructor. All fields have their default value (null) and the
55 * event rank is set to TmfContext.UNKNOWN_RANK.
58 this(null, TmfContext
.UNKNOWN_RANK
, null, null, null, null, null);
62 * Standard constructor. The event rank will be set to TmfContext.UNKNOWN_RANK.
64 * @param trace the parent trace
65 * @param timestamp the event timestamp
66 * @param source the event source
67 * @param type the event type
68 * @param content the event content (payload)
69 * @param reference the event reference
72 public TmfEvent(final ITmfTrace
<?
extends ITmfEvent
> trace
, final ITmfTimestamp timestamp
, final String source
,
73 final ITmfEventType type
, final ITmfEventField content
, final String reference
)
75 this(trace
, TmfContext
.UNKNOWN_RANK
, timestamp
, source
, type
, content
, 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(final ITmfTrace
<?
extends ITmfEvent
> trace
, final long rank
, final ITmfTimestamp timestamp
, final String source
,
90 final ITmfEventType type
, final ITmfEventField content
, final String reference
)
94 fTimestamp
= timestamp
;
98 fReference
= reference
;
104 * @param event the original event
106 public TmfEvent(final ITmfEvent event
) {
108 throw new IllegalArgumentException();
110 fTrace
= event
.getTrace();
111 fRank
= event
.getRank();
112 fTimestamp
= event
.getTimestamp();
113 fSource
= event
.getSource();
114 fType
= event
.getType();
115 fContent
= event
.getContent();
116 fReference
= event
.getReference();
119 // ------------------------------------------------------------------------
121 // ------------------------------------------------------------------------
124 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getTrace()
127 public ITmfTrace
<?
extends ITmfEvent
> getTrace() {
132 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getRank()
135 public long getRank() {
140 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getTimestamp()
143 public ITmfTimestamp
getTimestamp() {
148 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getSource()
151 public String
getSource() {
156 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getType()
159 public ITmfEventType
getType() {
164 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getContent()
167 public ITmfEventField
getContent() {
172 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getReference()
175 public String
getReference() {
179 // ------------------------------------------------------------------------
180 // Convenience setters
181 // ------------------------------------------------------------------------
184 * @param trace the new event trace
186 protected void setTrace(final ITmfTrace
<?
extends ITmfEvent
> trace
) {
191 * @param rank the new event rank
193 protected void setRank(final long rank
) {
198 * @param timestamp the new event timestamp
200 protected void setTimestamp(final ITmfTimestamp timestamp
) {
201 fTimestamp
= timestamp
;
205 * @param source the new event source
207 protected void setSource(final String source
) {
212 * @param type the new event type
214 protected void setType(final ITmfEventType type
) {
219 * @param content the event new content
221 protected void setContent(final ITmfEventField content
) {
226 * @param reference the new event reference
228 protected void setReference(final String reference
) {
229 fReference
= reference
;
232 // ------------------------------------------------------------------------
234 // ------------------------------------------------------------------------
237 * @see java.lang.Object#clone()
240 public TmfEvent
clone() {
241 TmfEvent clone
= null;
243 clone
= (TmfEvent
) super.clone();
244 clone
.fTrace
= fTrace
;
246 clone
.fTimestamp
= fTimestamp
!= null ? fTimestamp
.clone() : null;
247 clone
.fSource
= fSource
;
248 clone
.fType
= fType
!= null ? fType
.clone() : null;
249 clone
.fContent
= fContent
!= null ? fContent
.clone() : null;
250 clone
.fReference
= fReference
;
251 } catch (final CloneNotSupportedException e
) {
256 // ------------------------------------------------------------------------
258 // ------------------------------------------------------------------------
261 * @see java.lang.Object#hashCode()
264 public int hashCode() {
265 final int prime
= 31;
267 result
= prime
* result
+ ((fTrace
== null) ?
0 : fTrace
.hashCode());
268 result
= prime
* result
+ (int) (fRank ^
(fRank
>>> 32));
269 result
= prime
* result
+ ((fTimestamp
== null) ?
0 : fTimestamp
.hashCode());
270 result
= prime
* result
+ ((fSource
== null) ?
0 : fSource
.hashCode());
271 result
= prime
* result
+ ((fType
== null) ?
0 : fType
.hashCode());
272 result
= prime
* result
+ ((fContent
== null) ?
0 : fContent
.hashCode());
273 result
= prime
* result
+ ((fReference
== null) ?
0 : fReference
.hashCode());
278 * @see java.lang.Object#equals(java.lang.Object)
281 public boolean equals(final Object obj
) {
288 if (!(obj
instanceof TmfEvent
)) {
291 final TmfEvent other
= (TmfEvent
) obj
;
292 if (fTrace
== null) {
293 if (other
.fTrace
!= null) {
296 } else if (!fTrace
.equals(other
.fTrace
)) {
299 if (fRank
!= other
.fRank
) {
302 if (fTimestamp
== null) {
303 if (other
.fTimestamp
!= null) {
306 } else if (!fTimestamp
.equals(other
.fTimestamp
)) {
309 if (fSource
== null) {
310 if (other
.fSource
!= null) {
313 } else if (!fSource
.equals(other
.fSource
)) {
317 if (other
.fType
!= null) {
320 } else if (!fType
.equals(other
.fType
)) {
323 if (fContent
== null) {
324 if (other
.fContent
!= null) {
327 } else if (!fContent
.equals(other
.fContent
)) {
330 if (fReference
== null) {
331 if (other
.fReference
!= null) {
334 } else if (!fReference
.equals(other
.fReference
)) {
341 * @see java.lang.Object#toString()
344 @SuppressWarnings("nls")
345 public String
toString() {
346 return "TmfEvent [fTimestamp=" + fTimestamp
+ ", fTrace=" + fTrace
+ ", fRank=" + fRank
347 + ", fSource=" + fSource
+ ", fType=" + fType
+ ", fContent=" + fContent
348 + ", fReference=" + fReference
+ "]";