Contribute CNF based TMF project handling
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf / src / org / eclipse / linuxtools / tmf / event / TmfEvent.java
1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.event;
14
15 import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
16
17 /**
18 * <b><u>TmfEvent</u></b>
19 * <p>
20 * The basic event structure in the TMF. In its canonical form, an event has:
21 * <ul>
22 * <li> a normalized timestamp
23 * <li> a source (reporter)
24 * <li> a type
25 * <li> a content
26 * </ul>
27 * For convenience, a free-form reference field is also provided. It could be
28 * used as e.g. a location marker in the event stream to distinguish between
29 * otherwise identical events.
30 *
31 * Notice that for performance reasons TmfEvent is NOT immutable. If a copy
32 * of the event is needed, use the copy constructor.
33 */
34 public class TmfEvent extends TmfData implements Cloneable {
35
36 // ------------------------------------------------------------------------
37 // Constants
38 // ------------------------------------------------------------------------
39
40 public static final TmfEvent NullEvent = new TmfEvent();
41
42 // ------------------------------------------------------------------------
43 // Attributes
44 // ------------------------------------------------------------------------
45
46 protected ITmfTrace fParentTrace;
47 protected long fEventRank;
48 protected TmfTimestamp fEffectiveTimestamp;
49 protected TmfTimestamp fOriginalTimestamp;
50 protected TmfEventSource fSource;
51 protected TmfEventType fType;
52 protected TmfEventReference fReference;
53
54 // Content requires a reference to the parent event so it is initialized
55 // using setContent()
56 protected TmfEventContent fContent;
57
58 // ------------------------------------------------------------------------
59 // Constructors
60 // ------------------------------------------------------------------------
61
62 /**
63 * @param originalTS the original timestamp
64 * @param effectiveTS the effective timestamp
65 * @param source the event source (generator)
66 * @param type the event type
67 * @param reference a free-form reference field
68 */
69 public TmfEvent(ITmfTrace trace, long rank, TmfTimestamp originalTS, TmfTimestamp effectiveTS,
70 TmfEventSource source, TmfEventType type, TmfEventReference reference)
71 {
72 fParentTrace = trace;
73 fEventRank = rank;
74 fOriginalTimestamp = originalTS;
75 fEffectiveTimestamp = effectiveTS;
76 fSource = source;
77 fType = type;
78 fReference = reference;
79 }
80
81 /**
82 * @param originalTS the original timestamp
83 * @param effectiveTS the effective timestamp
84 * @param source the event source (generator)
85 * @param type the event type
86 * @param reference a free-form reference field
87 */
88 public TmfEvent(TmfTimestamp originalTS, TmfTimestamp effectiveTS,
89 TmfEventSource source, TmfEventType type, TmfEventReference reference)
90 {
91 this(null, -1, originalTS, effectiveTS, source, type, reference);
92 }
93
94 /**
95 * @param timestamp the effective timestamp
96 * @param source the event source (generator)
97 * @param type the event type
98 * @param reference a free-form reference field
99 */
100 public TmfEvent(TmfTimestamp timestamp, TmfEventSource source,
101 TmfEventType type, TmfEventReference reference)
102 {
103 this(null, -1, timestamp, timestamp, source, type, reference);
104 }
105
106 /**
107 * Copy constructor
108 *
109 * @param other the original event
110 */
111 public TmfEvent(TmfEvent other) {
112 if (other == null)
113 throw new IllegalArgumentException();
114 fParentTrace = other.fParentTrace;
115 fEventRank = other.fEventRank;
116 fOriginalTimestamp = new TmfTimestamp(other.fOriginalTimestamp);
117 fEffectiveTimestamp = new TmfTimestamp(other.fEffectiveTimestamp);
118 fSource = new TmfEventSource(other.fSource);
119 fType = new TmfEventType(other.fType);
120 fContent = new TmfEventContent(other.fContent);
121 fReference = new TmfEventReference(other.fReference);
122 }
123
124 public TmfEvent() {
125 }
126
127 @Override
128 public boolean isNullRef() {
129 return this == NullEvent;
130 }
131
132 // ------------------------------------------------------------------------
133 // Accessors
134 // ------------------------------------------------------------------------
135
136 /**
137 * @return the parent trace
138 */
139 public ITmfTrace getParentTrace() {
140 return fParentTrace;
141 }
142
143 /**
144 * @return the event rank
145 */
146 public long getEventRank() {
147 return fEventRank;
148 }
149
150 /**
151 * @return the effective event timestamp
152 */
153 public TmfTimestamp getTimestamp() {
154 return fEffectiveTimestamp;
155 }
156
157 /**
158 * @return the original event timestamp
159 */
160 public TmfTimestamp getOriginalTimestamp() {
161 return fOriginalTimestamp;
162 }
163
164 /**
165 * @return the event source
166 */
167 public TmfEventSource getSource() {
168 return fSource;
169 }
170
171 /**
172 * @return the event type
173 */
174 public TmfEventType getType() {
175 return fType;
176 }
177
178 /**
179 * @return the event content
180 */
181 public TmfEventContent getContent() {
182 return fContent;
183 }
184
185 /**
186 * @return the event reference
187 */
188 public TmfEventReference getReference() {
189 return fReference;
190 }
191
192 /**
193 * @param content
194 * the new event content
195 */
196 public void setContent(TmfEventContent content) {
197 fContent = content;
198 }
199
200 /**
201 * @return the event raw text
202 */
203 public String getRawText() {
204 if (fContent != null && fContent.getContent() != null) {
205 return fContent.getContent().toString();
206 }
207 return ""; //$NON-NLS-1$
208 }
209
210 // ------------------------------------------------------------------------
211 // Object
212 // ------------------------------------------------------------------------
213
214 @Override
215 public int hashCode() {
216 int result = 17;
217 result = 37 * result + fSource.hashCode();
218 result = 37 * result + fType.hashCode();
219 result = 37 * result + fEffectiveTimestamp.hashCode();
220 return result;
221 }
222
223 @Override
224 public boolean equals(Object other) {
225 if (!(other instanceof TmfEvent))
226 return false;
227 TmfEvent o = (TmfEvent) other;
228 return fEffectiveTimestamp.equals(o.fEffectiveTimestamp) && fSource.equals(o.fSource) && fType.equals(o.fType) && fContent.equals(o.fContent);
229 }
230
231 @Override
232 @SuppressWarnings("nls")
233 public String toString() {
234 return "[TmfEvent(" + fEffectiveTimestamp + "," + fSource + "," + fType + "," + fContent + ")]";
235 }
236
237 @Override
238 public TmfEvent clone() {
239 TmfEvent clone = null;
240 try {
241 clone = (TmfEvent) super.clone();
242 clone.fParentTrace = fParentTrace;
243 clone.fEventRank = fEventRank;
244 clone.fOriginalTimestamp = fOriginalTimestamp.clone();
245 clone.fEffectiveTimestamp = fEffectiveTimestamp.clone();
246 clone.fSource = fSource.clone();
247 clone.fType = fType.clone();
248 clone.fReference = fReference.clone();
249 clone.fContent = fContent.clone();
250 }
251 catch (CloneNotSupportedException e) {
252 e.printStackTrace();
253 }
254
255 return clone;
256 }
257
258 }
This page took 0.036066 seconds and 5 git commands to generate.