1 /*******************************************************************************
2 * Copyright (c) 2009 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 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.event
;
16 * <b><u>TmfEvent</u></b>
18 * The basic event structure in the TMF. In its canonical form, an event has:
20 * <li> a normalized timestamp
21 * <li> a source (reporter)
25 * For convenience, a free-form reference field is also provided. It could be
26 * used as e.g. a location marker in the event stream to distinguish between
27 * otherwise identical events.
29 * Notice that for performance reasons TmfEvent is NOT immutable. If a copy
30 * of the event is needed, use the copy constructor.
32 public class TmfEvent
extends TmfData
{
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
38 public static final TmfEvent NullEvent
= new TmfEvent();
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
44 protected TmfTimestamp fEffectiveTimestamp
;
45 protected TmfTimestamp fOriginalTimestamp
;
46 protected TmfEventSource fSource
;
47 protected TmfEventType fType
;
48 protected TmfEventReference fReference
;
50 // Content requires a reference to the parent event so it is initialized
52 protected TmfEventContent fContent
;
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
59 * @param originalTS the original timestamp
60 * @param effectiveTS the effective timestamp
61 * @param source the event source (generator)
62 * @param type the event type
63 * @param reference a free-form reference field
65 public TmfEvent(TmfTimestamp originalTS
, TmfTimestamp effectiveTS
,
66 TmfEventSource source
, TmfEventType type
, TmfEventReference reference
)
68 fOriginalTimestamp
= originalTS
;
69 fEffectiveTimestamp
= effectiveTS
;
72 fReference
= reference
;
76 * @param timestamp the effective timestamp
77 * @param source the event source (generator)
78 * @param type the event type
79 * @param reference a free-form reference field
81 public TmfEvent(TmfTimestamp timestamp
, TmfEventSource source
,
82 TmfEventType type
, TmfEventReference reference
)
84 this(timestamp
, timestamp
, source
, type
, reference
);
90 * @param other the original event
92 public TmfEvent(TmfEvent other
) {
94 throw new IllegalArgumentException();
95 fOriginalTimestamp
= new TmfTimestamp(other
.fOriginalTimestamp
);
96 fEffectiveTimestamp
= new TmfTimestamp(other
.fEffectiveTimestamp
);
97 fSource
= new TmfEventSource(other
.fSource
);
98 fType
= new TmfEventType(other
.fType
);
99 fContent
= new TmfEventContent(other
.fContent
);
100 fReference
= new TmfEventReference(other
.fReference
);
107 public boolean isNullRef() {
108 return this == NullEvent
;
111 // ------------------------------------------------------------------------
113 // ------------------------------------------------------------------------
116 * @return the effective event timestamp
118 public TmfTimestamp
getTimestamp() {
119 return fEffectiveTimestamp
;
123 * @return the original event timestamp
125 public TmfTimestamp
getOriginalTimestamp() {
126 return fOriginalTimestamp
;
130 * @return the event source
132 public TmfEventSource
getSource() {
137 * @return the event type
139 public TmfEventType
getType() {
144 * @return the event content
146 public TmfEventContent
getContent() {
151 * @return the event reference
153 public TmfEventReference
getReference() {
158 * @param content the new event content
160 public void setContent(TmfEventContent content
) {
164 // ------------------------------------------------------------------------
166 // ------------------------------------------------------------------------
169 public int hashCode() {
171 result
= 37 * result
+ fSource
.hashCode();
172 result
= 37 * result
+ fType
.hashCode();
173 result
= 37 * result
+ fEffectiveTimestamp
.hashCode();
178 public boolean equals(Object other
) {
179 if (!(other
instanceof TmfEvent
))
181 TmfEvent o
= (TmfEvent
) other
;
182 return fEffectiveTimestamp
.equals(o
.fEffectiveTimestamp
) &&
183 fSource
.equals(o
.fSource
) &&
184 fType
.equals(o
.fType
) &&
185 fContent
.equals(o
.fContent
);
189 public String
toString() {
190 return "[TmfEvent(" + fEffectiveTimestamp
+ "," + fSource
+ "," + fType
+ "," + fContent
+ ")]";