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 * A basic implementation of ITmfEvent.
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)
27 * @author Francois Chouinard
33 public class TmfEvent
implements ITmfEvent
{
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
39 private ITmfTrace
<?
extends ITmfEvent
> fTrace
;
41 private ITmfTimestamp fTimestamp
;
42 private String fSource
;
43 private ITmfEventType fType
;
44 private ITmfEventField fContent
;
45 private String fReference
;
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
55 this(null, -1, null, null, null, null, null);
59 * Constructor - no rank
61 public TmfEvent(final ITmfTrace
<?
extends ITmfEvent
> trace
, final ITmfTimestamp timestamp
, final String source
,
62 final ITmfEventType type
, final ITmfEventField content
, final String reference
)
64 this(trace
, -1, timestamp
, source
, type
, content
, reference
);
68 * Constructor - no rank, no content
70 public TmfEvent(final ITmfTrace
<?
extends ITmfEvent
> trace
, final ITmfTimestamp timestamp
, final String source
,
71 final ITmfEventType type
, final String reference
)
73 this(trace
, -1, timestamp
, source
, type
, null, reference
);
77 * Constructor - no rank, no content, no trace
79 public TmfEvent(final ITmfTimestamp timestamp
, final String source
, final ITmfEventType type
, final String reference
)
81 this(null, -1, timestamp
, source
, type
, null, reference
);
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
92 * @param content the event content (payload)
93 * @param reference the event reference
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
)
100 fTimestamp
= timestamp
;
104 fReference
= reference
;
110 * @param event the original event
112 public TmfEvent(final ITmfEvent event
) {
114 throw new IllegalArgumentException();
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();
125 // ------------------------------------------------------------------------
127 // ------------------------------------------------------------------------
130 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getTrace()
133 public ITmfTrace
<?
extends ITmfEvent
> getTrace() {
138 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getRank()
141 public long getRank() {
146 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getTimestamp()
149 public ITmfTimestamp
getTimestamp() {
154 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getSource()
157 public String
getSource() {
162 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getType()
165 public ITmfEventType
getType() {
170 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getContent()
173 public ITmfEventField
getContent() {
178 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getReference()
181 public String
getReference() {
185 // ------------------------------------------------------------------------
186 // Convenience setters
187 // ------------------------------------------------------------------------
190 * @param trace the new event trace
192 protected void setTrace(final ITmfTrace
<?
extends ITmfEvent
> trace
) {
197 * @param rank the new event rank
199 protected void setRank(final long rank
) {
204 * @param timestamp the new event timestamp
206 protected void setTimestamp(final ITmfTimestamp timestamp
) {
207 fTimestamp
= timestamp
;
211 * @param source the new event source
213 protected void setSource(final String source
) {
218 * @param type the new event type
220 protected void setType(final ITmfEventType type
) {
225 * @param content the event new content
227 protected void setContent(final ITmfEventField content
) {
232 * @param reference the new event reference
234 protected void setReference(final String reference
) {
235 fReference
= reference
;
238 // ------------------------------------------------------------------------
240 // ------------------------------------------------------------------------
243 * @see java.lang.Object#clone()
246 public TmfEvent
clone() {
247 TmfEvent clone
= null;
249 clone
= (TmfEvent
) super.clone();
250 clone
.fTrace
= fTrace
;
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
;
257 } catch (final CloneNotSupportedException e
) {
262 // ------------------------------------------------------------------------
264 // ------------------------------------------------------------------------
267 * @see java.lang.Object#hashCode()
270 public int hashCode() {
271 final int prime
= 31;
273 result
= prime
* result
+ ((fTrace
== null) ?
0 : fTrace
.hashCode());
274 result
= prime
* result
+ (int) (fRank ^
(fRank
>>> 32));
275 result
= prime
* result
+ ((fTimestamp
== null) ?
0 : fTimestamp
.hashCode());
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());
284 * @see java.lang.Object#equals(java.lang.Object)
287 public boolean equals(final Object obj
) {
294 if (!(obj
instanceof TmfEvent
)) {
297 final TmfEvent other
= (TmfEvent
) obj
;
298 if (fTrace
== null) {
299 if (other
.fTrace
!= null) {
302 } else if (!fTrace
.equals(other
.fTrace
)) {
305 if (fRank
!= other
.fRank
) {
308 if (fTimestamp
== null) {
309 if (other
.fTimestamp
!= null) {
312 } else if (!fTimestamp
.equals(other
.fTimestamp
)) {
315 if (fSource
== null) {
316 if (other
.fSource
!= null) {
319 } else if (!fSource
.equals(other
.fSource
)) {
323 if (other
.fType
!= null) {
326 } else if (!fType
.equals(other
.fType
)) {
329 if (fContent
== null) {
330 if (other
.fContent
!= null) {
333 } else if (!fContent
.equals(other
.fContent
)) {
336 if (fReference
== null) {
337 if (other
.fReference
!= null) {
340 } else if (!fReference
.equals(other
.fReference
)) {
347 * @see java.lang.Object#toString()
350 @SuppressWarnings("nls")
351 public String
toString() {
352 return "TmfEvent [fTimestamp=" + fTimestamp
+ ", fTrace=" + fTrace
+ ", fRank=" + fRank
353 + ", fSource=" + fSource
+ ", fType=" + fType
+ ", fContent=" + fContent
354 + ", fReference=" + fReference
+ "]";