Contribute CNF based TMF project handling
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf / src / org / eclipse / linuxtools / tmf / event / TmfEvent.java
CommitLineData
8c8bf09f
ASL
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:
1f506a43 10 * Francois Chouinard - Initial API and implementation
8c8bf09f
ASL
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf.event;
14
2c8610f7
FC
15import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
16
8c8bf09f
ASL
17/**
18 * <b><u>TmfEvent</u></b>
19 * <p>
1f506a43 20 * The basic event structure in the TMF. In its canonical form, an event has:
8c8bf09f
ASL
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.
28b94d61
FC
30 *
31 * Notice that for performance reasons TmfEvent is NOT immutable. If a copy
cbd4ad82 32 * of the event is needed, use the copy constructor.
8c8bf09f 33 */
f9673903 34public class TmfEvent extends TmfData implements Cloneable {
8c8bf09f 35
36548af3
FC
36 // ------------------------------------------------------------------------
37 // Constants
38 // ------------------------------------------------------------------------
39
12c155f5
FC
40 public static final TmfEvent NullEvent = new TmfEvent();
41
cbd4ad82 42 // ------------------------------------------------------------------------
8c8bf09f 43 // Attributes
cbd4ad82 44 // ------------------------------------------------------------------------
8c8bf09f 45
2c8610f7
FC
46 protected ITmfTrace fParentTrace;
47 protected long fEventRank;
28b94d61
FC
48 protected TmfTimestamp fEffectiveTimestamp;
49 protected TmfTimestamp fOriginalTimestamp;
50 protected TmfEventSource fSource;
51 protected TmfEventType fType;
52 protected TmfEventReference fReference;
8c8bf09f 53
12c155f5
FC
54 // Content requires a reference to the parent event so it is initialized
55 // using setContent()
56 protected TmfEventContent fContent;
28b94d61 57
cbd4ad82 58 // ------------------------------------------------------------------------
8c8bf09f 59 // Constructors
cbd4ad82 60 // ------------------------------------------------------------------------
8c8bf09f 61
2c8610f7
FC
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
8c8bf09f 81 /**
cbd4ad82
FC
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
8c8bf09f 87 */
28b94d61
FC
88 public TmfEvent(TmfTimestamp originalTS, TmfTimestamp effectiveTS,
89 TmfEventSource source, TmfEventType type, TmfEventReference reference)
8c8bf09f 90 {
2c8610f7 91 this(null, -1, originalTS, effectiveTS, source, type, reference);
1f506a43
FC
92 }
93
94 /**
cbd4ad82
FC
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
1f506a43
FC
99 */
100 public TmfEvent(TmfTimestamp timestamp, TmfEventSource source,
28b94d61 101 TmfEventType type, TmfEventReference reference)
1f506a43 102 {
2c8610f7 103 this(null, -1, timestamp, timestamp, source, type, reference);
4e3aa37d
FC
104 }
105
106 /**
cbd4ad82 107 * Copy constructor
28b94d61 108 *
cbd4ad82 109 * @param other the original event
4e3aa37d 110 */
28b94d61 111 public TmfEvent(TmfEvent other) {
cbd4ad82
FC
112 if (other == null)
113 throw new IllegalArgumentException();
2c8610f7
FC
114 fParentTrace = other.fParentTrace;
115 fEventRank = other.fEventRank;
cbd4ad82
FC
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);
28b94d61
FC
122 }
123
12c155f5
FC
124 public TmfEvent() {
125 }
36548af3 126
12c155f5
FC
127 @Override
128 public boolean isNullRef() {
129 return this == NullEvent;
130 }
8c8bf09f 131
12c155f5 132 // ------------------------------------------------------------------------
8c8bf09f 133 // Accessors
cbd4ad82 134 // ------------------------------------------------------------------------
8c8bf09f 135
2c8610f7
FC
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
12c155f5
FC
150 /**
151 * @return the effective event timestamp
152 */
153 public TmfTimestamp getTimestamp() {
154 return fEffectiveTimestamp;
155 }
1f506a43 156
12c155f5
FC
157 /**
158 * @return the original event timestamp
159 */
160 public TmfTimestamp getOriginalTimestamp() {
161 return fOriginalTimestamp;
162 }
8c8bf09f 163
12c155f5
FC
164 /**
165 * @return the event source
166 */
167 public TmfEventSource getSource() {
168 return fSource;
169 }
8c8bf09f 170
12c155f5
FC
171 /**
172 * @return the event type
173 */
174 public TmfEventType getType() {
175 return fType;
176 }
8c8bf09f 177
12c155f5
FC
178 /**
179 * @return the event content
180 */
181 public TmfEventContent getContent() {
182 return fContent;
183 }
8c8bf09f 184
12c155f5
FC
185 /**
186 * @return the event reference
187 */
188 public TmfEventReference getReference() {
189 return fReference;
190 }
1f506a43 191
12c155f5
FC
192 /**
193 * @param content
194 * the new event content
195 */
196 public void setContent(TmfEventContent content) {
197 fContent = content;
198 }
cbd4ad82 199
12c155f5
FC
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 }
c76c54bb 209
12c155f5 210 // ------------------------------------------------------------------------
cbd4ad82
FC
211 // Object
212 // ------------------------------------------------------------------------
28b94d61 213
12c155f5 214 @Override
cbd4ad82 215 public int hashCode() {
12c155f5
FC
216 int result = 17;
217 result = 37 * result + fSource.hashCode();
218 result = 37 * result + fType.hashCode();
219 result = 37 * result + fEffectiveTimestamp.hashCode();
cbd4ad82
FC
220 return result;
221 }
222
223 @Override
224 public boolean equals(Object other) {
225 if (!(other instanceof TmfEvent))
12c155f5 226 return false;
cbd4ad82 227 TmfEvent o = (TmfEvent) other;
12c155f5 228 return fEffectiveTimestamp.equals(o.fEffectiveTimestamp) && fSource.equals(o.fSource) && fType.equals(o.fType) && fContent.equals(o.fContent);
cbd4ad82 229 }
28b94d61 230
12c155f5 231 @Override
3b38ea61 232 @SuppressWarnings("nls")
12c155f5
FC
233 public String toString() {
234 return "[TmfEvent(" + fEffectiveTimestamp + "," + fSource + "," + fType + "," + fContent + ")]";
235 }
cbd4ad82 236
f9673903
FC
237 @Override
238 public TmfEvent clone() {
1a971e96
FC
239 TmfEvent clone = null;
240 try {
241 clone = (TmfEvent) super.clone();
2c8610f7
FC
242 clone.fParentTrace = fParentTrace;
243 clone.fEventRank = fEventRank;
1a971e96
FC
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
12c155f5
FC
255 return clone;
256 }
f9673903 257
8c8bf09f 258}
This page took 0.045518 seconds and 5 git commands to generate.