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
.ITmfContext
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
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)
27 * @author Francois Chouinard
34 public class TmfEvent
implements ITmfEvent
, Cloneable
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
40 private ITmfTrace fTrace
;
42 private ITmfTimestamp fTimestamp
;
43 private String fSource
;
44 private ITmfEventType fType
;
45 private ITmfEventField fContent
;
46 private String fReference
;
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
53 * Default constructor. All fields have their default value (null) and the
54 * event rank is set to TmfContext.UNKNOWN_RANK.
57 this(null, ITmfContext
.UNKNOWN_RANK
, null, null, null, null, null);
61 * Standard constructor. The event rank will be set to TmfContext.UNKNOWN_RANK.
63 * @param trace the parent trace
64 * @param timestamp the event timestamp
65 * @param source the event source
66 * @param type the event type
67 * @param content the event content (payload)
68 * @param reference the event reference
71 public TmfEvent(final ITmfTrace trace
, final ITmfTimestamp timestamp
, final String source
,
72 final ITmfEventType type
, final ITmfEventField content
, final String reference
)
74 this(trace
, ITmfContext
.UNKNOWN_RANK
, timestamp
, source
, type
, content
, reference
);
80 * @param trace the parent trace
81 * @param rank the event rank (in the trace)
82 * @param timestamp the event timestamp
83 * @param source the event source
84 * @param type the event type
85 * @param content the event content (payload)
86 * @param reference the event reference
88 public TmfEvent(final ITmfTrace trace
, final long rank
, final ITmfTimestamp timestamp
, final String source
,
89 final ITmfEventType type
, final ITmfEventField content
, final String reference
)
93 fTimestamp
= timestamp
;
97 fReference
= reference
;
103 * @param event the original event
105 public TmfEvent(final ITmfEvent event
) {
107 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
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(final ITmfTrace trace
) {
190 * @param rank the new event rank
192 protected void setRank(final long rank
) {
197 * @param timestamp the new event timestamp
199 protected void setTimestamp(final ITmfTimestamp timestamp
) {
200 fTimestamp
= timestamp
;
204 * @param source the new event source
206 protected void setSource(final String source
) {
211 * @param type the new event type
213 protected void setType(final ITmfEventType type
) {
218 * @param content the event new content
220 protected void setContent(final ITmfEventField content
) {
225 * @param reference the new event reference
227 protected void setReference(final 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 (final 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(final Object obj
) {
287 if (!(obj
instanceof TmfEvent
)) {
290 final TmfEvent other
= (TmfEvent
) obj
;
291 if (fTrace
== null) {
292 if (other
.fTrace
!= null) {
295 } else if (!fTrace
.equals(other
.fTrace
)) {
298 if (fRank
!= other
.fRank
) {
301 if (fTimestamp
== null) {
302 if (other
.fTimestamp
!= null) {
305 } else if (!fTimestamp
.equals(other
.fTimestamp
)) {
308 if (fSource
== null) {
309 if (other
.fSource
!= null) {
312 } else if (!fSource
.equals(other
.fSource
)) {
316 if (other
.fType
!= null) {
319 } else if (!fType
.equals(other
.fType
)) {
322 if (fContent
== null) {
323 if (other
.fContent
!= null) {
326 } else if (!fContent
.equals(other
.fContent
)) {
329 if (fReference
== null) {
330 if (other
.fReference
!= null) {
333 } else if (!fReference
.equals(other
.fReference
)) {
340 * @see java.lang.Object#toString()
343 @SuppressWarnings("nls")
344 public String
toString() {
345 return "TmfEvent [fTimestamp=" + fTimestamp
+ ", fTrace=" + fTrace
+ ", fRank=" + fRank
346 + ", fSource=" + fSource
+ ", fType=" + fType
+ ", fContent=" + fContent
347 + ", fReference=" + fReference
+ "]";