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 protected TmfTimestamp fEffectiveTimestamp
;
39 protected TmfTimestamp fOriginalTimestamp
;
40 protected TmfEventSource fSource
;
41 protected TmfEventType fType
;
42 protected TmfEventReference fReference
;
44 // Content requires a reference to the parent event so it is initialized
46 protected TmfEventContent fContent
;
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
53 * @param originalTS the original timestamp
54 * @param effectiveTS the effective timestamp
55 * @param source the event source (generator)
56 * @param type the event type
57 * @param reference a free-form reference field
59 public TmfEvent(TmfTimestamp originalTS
, TmfTimestamp effectiveTS
,
60 TmfEventSource source
, TmfEventType type
, TmfEventReference reference
)
62 if (source
== null || type
== null || effectiveTS
== null) {
63 throw new IllegalArgumentException();
65 fOriginalTimestamp
= originalTS
;
66 fEffectiveTimestamp
= effectiveTS
;
69 fReference
= reference
;
73 * @param timestamp the effective timestamp
74 * @param source the event source (generator)
75 * @param type the event type
76 * @param reference a free-form reference field
78 public TmfEvent(TmfTimestamp timestamp
, TmfEventSource source
,
79 TmfEventType type
, TmfEventReference reference
)
81 this(timestamp
, timestamp
, source
, type
, reference
);
87 * @param other the original event
89 public TmfEvent(TmfEvent other
) {
91 throw new IllegalArgumentException();
92 fOriginalTimestamp
= new TmfTimestamp(other
.fOriginalTimestamp
);
93 fEffectiveTimestamp
= new TmfTimestamp(other
.fEffectiveTimestamp
);
94 fSource
= new TmfEventSource(other
.fSource
);
95 fType
= new TmfEventType(other
.fType
);
96 fContent
= new TmfEventContent(other
.fContent
);
97 fReference
= new TmfEventReference(other
.fReference
);
100 @SuppressWarnings("unused")
102 throw new AssertionError();
105 // ------------------------------------------------------------------------
107 // ------------------------------------------------------------------------
110 * @return the effective event timestamp
112 public TmfTimestamp
getTimestamp() {
113 return fEffectiveTimestamp
;
117 * @return the original event timestamp
119 public TmfTimestamp
getOriginalTimestamp() {
120 return fOriginalTimestamp
;
124 * @return the event source
126 public TmfEventSource
getSource() {
131 * @return the event type
133 public TmfEventType
getType() {
138 * @return the event content
140 public TmfEventContent
getContent() {
145 * @return the event reference
147 public TmfEventReference
getReference() {
152 * @param content the new event content
154 public void setContent(TmfEventContent content
) {
158 // ------------------------------------------------------------------------
160 // ------------------------------------------------------------------------
163 public int hashCode() {
165 result
= 37 * result
+ fSource
.hashCode();
166 result
= 37 * result
+ fType
.hashCode();
167 result
= 37 * result
+ fEffectiveTimestamp
.hashCode();
172 public boolean equals(Object other
) {
173 if (!(other
instanceof TmfEvent
))
175 TmfEvent o
= (TmfEvent
) other
;
176 return fEffectiveTimestamp
.equals(o
.fEffectiveTimestamp
) &&
177 fSource
.equals(o
.fSource
) &&
178 fType
.equals(o
.fType
) &&
179 fContent
.equals(o
.fContent
);
183 public String
toString() {
184 return "[TmfEvent(" + fEffectiveTimestamp
+ "," + fSource
+ "," + fType
+ "," + fContent
+ ")]";