1 /*******************************************************************************
2 * Copyright (c) 2009, 2012 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made 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>TmfDataEvent</u></b>
21 * A basic implementation of ITmfDataEvent.
23 * Notice that for performance reasons TmfDataEvent is NOT immutable. If a copy
24 * of an event is needed, use the copy constructor (shallow copy) or the clone()
27 public class TmfDataEvent
implements Cloneable
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 protected ITmfTrace
<?
extends TmfDataEvent
> fTrace
;
35 protected String fSource
;
36 protected TmfEventType fType
;
37 protected TmfEventContent fContent
;
38 protected String fReference
;
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
47 public TmfDataEvent() {
53 * @param trace the parent trace
54 * @param rank the vent rank (in the trace)
55 * @param source the event source
56 * @param type the event type
57 * @param reference the event reference
59 public TmfDataEvent(ITmfTrace
<?
extends TmfDataEvent
> trace
, long rank
,
60 String source
, TmfEventType type
, TmfEventContent content
,
68 fReference
= reference
;
74 * @param event the original event
76 public TmfDataEvent(TmfDataEvent event
) {
78 throw new IllegalArgumentException();
79 fTrace
= event
.fTrace
;
81 fSource
= event
.fSource
;
83 fContent
= event
.fContent
;
84 fReference
= event
.fReference
;
87 // ------------------------------------------------------------------------
88 // ITmfDataEvent + Setters
89 // ------------------------------------------------------------------------
92 * @return the parent trace
94 public ITmfTrace
<?
extends TmfDataEvent
> getTrace() {
99 * @return the event rank
101 public long getRank() {
106 * @param source the event source
108 public void setSource(String source
) {
113 * @return the event source
115 public String
getSource() {
120 * @return the event type
122 public TmfEventType
getType() {
127 * @param content the event new content
129 public void setContent(TmfEventContent content
) {
134 * @return the event content
136 public TmfEventContent
getContent() {
141 * @return the event reference
143 public String
getReference() {
147 // ------------------------------------------------------------------------
149 // ------------------------------------------------------------------------
152 public TmfDataEvent
clone() {
153 TmfDataEvent clone
= null;
155 clone
= (TmfDataEvent
) super.clone();
156 clone
.fTrace
= fTrace
;
158 clone
.fSource
= fSource
;
159 clone
.fType
= fType
!= null ? fType
.clone() : null;
160 clone
.fContent
= fContent
!= null ? fContent
.clone() : null;
161 clone
.fReference
= fReference
;
162 } catch (CloneNotSupportedException e
) {
167 // ------------------------------------------------------------------------
169 // ------------------------------------------------------------------------
172 public int hashCode() {
173 final int prime
= 31;
175 result
= prime
* result
+ ((fContent
== null) ?
0 : fContent
.hashCode());
176 result
= prime
* result
+ (int) (fRank ^
(fRank
>>> 32));
177 result
= prime
* result
+ ((fReference
== null) ?
0 : fReference
.hashCode());
178 result
= prime
* result
+ ((fSource
== null) ?
0 : fSource
.hashCode());
179 result
= prime
* result
+ ((fTrace
== null) ?
0 : fTrace
.hashCode());
180 result
= prime
* result
+ ((fType
== null) ?
0 : fType
.hashCode());
185 public boolean equals(Object obj
) {
190 if (getClass() != obj
.getClass())
192 TmfDataEvent other
= (TmfDataEvent
) obj
;
193 if (fContent
== null) {
194 if (other
.fContent
!= null)
196 } else if (!fContent
.equals(other
.fContent
))
198 if (fRank
!= other
.fRank
)
200 if (fReference
== null) {
201 if (other
.fReference
!= null)
203 } else if (!fReference
.equals(other
.fReference
))
205 if (fSource
== null) {
206 if (other
.fSource
!= null)
208 } else if (!fSource
.equals(other
.fSource
))
210 if (fTrace
== null) {
211 if (other
.fTrace
!= null)
213 } else if (!fTrace
.equals(other
.fTrace
))
216 if (other
.fType
!= null)
218 } else if (!fType
.equals(other
.fType
))
224 @SuppressWarnings("nls")
225 public String
toString() {
226 return "TmfDataEvent [fTrace=" + fTrace
+ ", fRank=" + fRank
227 + ", fSource=" + fSource
+ ", fType=" + fType
+ ", fContent="
228 + fContent
+ ", fReference=" + fReference
+ "]";