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>TmfDataItem</u></b>
21 * A basic implementation of ITmfDataItem.
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 TmfDataItem
implements ITmfDataItem
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 protected ITmfTrace
<?
extends TmfDataItem
> fTrace
;
35 protected String fSource
;
36 protected ITmfEventType fType
;
37 protected ITmfEventContent fContent
;
38 protected String fReference
;
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
47 public TmfDataItem() {
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 TmfDataItem(ITmfTrace
<?
extends TmfDataItem
> trace
, long rank
,
60 String source
, TmfEventType type
, TmfEventContent content
,
68 fReference
= reference
;
74 * @param event the original event
76 public TmfDataItem(TmfDataItem event
) {
78 throw new IllegalArgumentException();
79 fTrace
= event
.fTrace
;
81 fSource
= event
.fSource
;
83 fContent
= event
.fContent
;
84 fReference
= event
.fReference
;
87 // ------------------------------------------------------------------------
89 // ------------------------------------------------------------------------
92 * @return the parent trace
94 public ITmfTrace
<?
extends TmfDataItem
> getTrace() {
99 * @return the event rank
101 public long getRank() {
106 * @return the event source
108 public String
getSource() {
113 * @return the event type
115 public ITmfEventType
getType() {
120 * @return the event content
122 public ITmfEventContent
getContent() {
127 * @return the event reference
129 public String
getReference() {
133 // ------------------------------------------------------------------------
134 // Convenience setters
135 // ------------------------------------------------------------------------
138 * @param source the new event source
140 public void setSource(String source
) {
145 * @param type the new event type
147 public void setType(TmfEventType type
) {
152 * @param content the event new content
154 public void setContent(TmfEventContent content
) {
159 * @param reference the new event reference
161 public void setReference(String reference
) {
162 fReference
= reference
;
165 // ------------------------------------------------------------------------
167 // ------------------------------------------------------------------------
170 public TmfDataItem
clone() {
171 TmfDataItem clone
= null;
173 clone
= (TmfDataItem
) super.clone();
174 clone
.fTrace
= fTrace
;
176 clone
.fSource
= fSource
;
177 clone
.fType
= fType
!= null ? fType
.clone() : null;
178 clone
.fContent
= fContent
!= null ? fContent
.clone() : null;
179 clone
.fReference
= fReference
;
180 } catch (CloneNotSupportedException e
) {
185 // ------------------------------------------------------------------------
187 // ------------------------------------------------------------------------
190 public int hashCode() {
191 final int prime
= 31;
193 result
= prime
* result
+ ((fContent
== null) ?
0 : fContent
.hashCode());
194 result
= prime
* result
+ (int) (fRank ^
(fRank
>>> 32));
195 result
= prime
* result
+ ((fReference
== null) ?
0 : fReference
.hashCode());
196 result
= prime
* result
+ ((fSource
== null) ?
0 : fSource
.hashCode());
197 result
= prime
* result
+ ((fTrace
== null) ?
0 : fTrace
.hashCode());
198 result
= prime
* result
+ ((fType
== null) ?
0 : fType
.hashCode());
203 public boolean equals(Object obj
) {
208 if (getClass() != obj
.getClass())
210 TmfDataItem other
= (TmfDataItem
) obj
;
211 if (fContent
== null) {
212 if (other
.fContent
!= null)
214 } else if (!fContent
.equals(other
.fContent
))
216 if (fRank
!= other
.fRank
)
218 if (fReference
== null) {
219 if (other
.fReference
!= null)
221 } else if (!fReference
.equals(other
.fReference
))
223 if (fSource
== null) {
224 if (other
.fSource
!= null)
226 } else if (!fSource
.equals(other
.fSource
))
228 if (fTrace
== null) {
229 if (other
.fTrace
!= null)
231 } else if (!fTrace
.equals(other
.fTrace
))
234 if (other
.fType
!= null)
236 } else if (!fType
.equals(other
.fType
))
242 @SuppressWarnings("nls")
243 public String
toString() {
244 return "TmfDataEvent [fTrace=" + fTrace
+ ", fRank=" + fRank
245 + ", fSource=" + fSource
+ ", fType=" + fType
+ ", fContent="
246 + fContent
+ ", fReference=" + fReference
+ "]";