ctf: Fix some Sonar warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / internal / ctf / core / event / EventDeclaration.java
CommitLineData
866e5b51 1/*******************************************************************************
8e964be1 2 * Copyright (c) 2011-2013 Ericsson, Ecole Polytechnique de Montreal and others
866e5b51
FC
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * 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: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
12
8e964be1 13package org.eclipse.linuxtools.internal.ctf.core.event;
866e5b51 14
8e964be1
MK
15import java.util.HashMap;
16import java.util.Map;
17import java.util.Set;
18
19import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
20import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
866e5b51 21import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
486efb2e 22import org.eclipse.linuxtools.ctf.core.trace.Stream;
866e5b51
FC
23import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
24
25/**
be6df2d8
AM
26 * Representation of one type of event. A bit like "int" or "long" but for trace
27 * events.
866e5b51 28 */
8e964be1 29public class EventDeclaration implements IEventDeclaration {
866e5b51
FC
30
31 // ------------------------------------------------------------------------
32 // Attributes
33 // ------------------------------------------------------------------------
34
35 /**
36 * Name of the event
37 */
38 private String name;
39
40 /**
41 * Event context structure declaration
42 */
43 private StructDeclaration context = null;
44
45 /**
46 * Event fields structure declaration
47 */
48 private StructDeclaration fields = null;
49
50 /**
51 * Event id (can be null if only event in the stream).
52 */
53 private Long id = null;
54
55 /**
56 * Stream to which belongs this event.
57 */
58 private Stream stream = null;
59
53047a66
MK
60 /**
61 * Loglevel of an event
62 */
63 private long logLevel;
64
8e964be1
MK
65 /** Map of this event type's custom CTF attributes */
66 private final Map<String, String> customAttributes = new HashMap<String, String>();
67
866e5b51
FC
68 // ------------------------------------------------------------------------
69 // Constructors
70 // ------------------------------------------------------------------------
71
be6df2d8
AM
72 /**
73 * Default constructor. Use the setters afterwards to set the fields
74 * accordingly.
75 */
8e964be1
MK
76 public EventDeclaration() {
77 }
be6df2d8 78
8e964be1 79 @Override
866e5b51
FC
80 public EventDefinition createDefinition(StreamInputReader streamInputReader) {
81 EventDefinition event = new EventDefinition(this, streamInputReader);
82
83 if (context != null) {
8e964be1 84 event.setContext(context.createDefinition(event, "context")); //$NON-NLS-1$
866e5b51
FC
85 }
86
87 if (this.fields != null) {
aa572e22 88 event.setFields(this.fields.createDefinition(event, "fields")); //$NON-NLS-1$
866e5b51
FC
89 }
90
91 return event;
92 }
93
33656d8e
MK
94 /**
95 * Creates a "lost" event. This is a synthetic event that is there to show
96 * that there should be something there.
8e964be1 97 *
9ac2eb62 98 * @return the lost event
33656d8e 99 */
0594c61c 100 public static synchronized EventDeclaration getLostEventDeclaration() {
debcffff
MK
101 EventDeclaration lostEvent = new EventDeclaration();
102 lostEvent.fields = new StructDeclaration(1);
07002e0a 103 lostEvent.id = -1L;
debcffff 104 lostEvent.name = "Lost event"; //$NON-NLS-1$
33656d8e
MK
105 return lostEvent;
106 }
107
866e5b51
FC
108 // ------------------------------------------------------------------------
109 // Getters/Setters/Predicates
110 // ------------------------------------------------------------------------
111
9ac2eb62
MK
112 /**
113 * Sets a name for an event Declaration
8e964be1
MK
114 *
115 * @param name
116 * the name
9ac2eb62 117 */
866e5b51
FC
118 public void setName(String name) {
119 this.name = name;
120 }
121
8e964be1 122 @Override
866e5b51
FC
123 public String getName() {
124 return name;
125 }
126
9ac2eb62
MK
127 /**
128 * Sets the context for an event declaration (see CTF specification)
8e964be1
MK
129 *
130 * @param context
131 * the context in structdeclaration format
9ac2eb62 132 */
866e5b51
FC
133 public void setContext(StructDeclaration context) {
134 this.context = context;
135 }
136
9ac2eb62
MK
137 /**
138 * Sets the fields of an event declaration
8e964be1
MK
139 *
140 * @param fields
141 * the fields in structdeclaration format
9ac2eb62 142 */
866e5b51
FC
143 public void setFields(StructDeclaration fields) {
144 this.fields = fields;
145 }
146
8e964be1 147 @Override
866e5b51
FC
148 public StructDeclaration getFields() {
149 return fields;
150 }
151
8e964be1 152 @Override
866e5b51
FC
153 public StructDeclaration getContext() {
154 return context;
155 }
156
9ac2eb62
MK
157 /**
158 * Sets the id of am event declaration
8e964be1
MK
159 *
160 * @param id
161 * the id
9ac2eb62 162 */
866e5b51
FC
163 public void setId(long id) {
164 this.id = id;
165 }
166
8e964be1 167 @Override
866e5b51
FC
168 public Long getId() {
169 return id;
170 }
171
9ac2eb62
MK
172 /**
173 * Sets the stream of am event declaration
8e964be1
MK
174 *
175 * @param stream
176 * the stream
486efb2e 177 * @since 2.0
9ac2eb62 178 */
866e5b51
FC
179 public void setStream(Stream stream) {
180 this.stream = stream;
181 }
182
8e964be1 183 @Override
866e5b51
FC
184 public Stream getStream() {
185 return stream;
186 }
187
9ac2eb62
MK
188 /**
189 * Is the name of the event declaration set
8e964be1 190 *
9ac2eb62
MK
191 * @return is the name set?
192 */
866e5b51
FC
193 public boolean nameIsSet() {
194 return name != null;
195 }
196
9ac2eb62
MK
197 /**
198 * Is the context set
8e964be1 199 *
9ac2eb62
MK
200 * @return is the context set
201 */
866e5b51
FC
202 public boolean contextIsSet() {
203 return context != null;
204 }
205
9ac2eb62
MK
206 /**
207 * Is a field set?
8e964be1 208 *
9ac2eb62
MK
209 * @return Is the field set?
210 */
866e5b51
FC
211 public boolean fieldsIsSet() {
212 return fields != null;
213 }
214
9ac2eb62
MK
215 /**
216 * Is the id set?
8e964be1 217 *
9ac2eb62
MK
218 * @return is the id set?
219 */
866e5b51
FC
220 public boolean idIsSet() {
221 return id != null;
222 }
223
9ac2eb62
MK
224 /**
225 * Is the stream set?
8e964be1 226 *
9ac2eb62
MK
227 * @return is the stream set?
228 */
866e5b51
FC
229 public boolean streamIsSet() {
230 return stream != null;
231 }
232
8e964be1 233 @Override
53047a66
MK
234 public long getLogLevel() {
235 return logLevel;
236 }
237
9ac2eb62
MK
238 /**
239 * Sets the log level
8e964be1
MK
240 *
241 * @param level
242 * the log level
9ac2eb62 243 */
8e964be1 244 public void setLogLevel(long level) {
53047a66
MK
245 logLevel = level;
246 }
247
8e964be1
MK
248 @Override
249 public Set<String> getCustomAttributes() {
250 return customAttributes.keySet();
251 }
252
253 @Override
254 public String getCustomAttribute(String key) {
255 return customAttributes.get(key);
256 }
257
258 /**
259 * Sets a custom attribute value.
260 *
261 * @param key
262 * the key of the attribute
263 * @param value
264 * the value of the attribute
265 * @since 2.0
266 */
267 public void setCustomAttribute(String key, String value) {
268 customAttributes.put(key, value);
269 }
270
866e5b51
FC
271 // ------------------------------------------------------------------------
272 // Operations
273 // ------------------------------------------------------------------------
274
275 @Override
276 public boolean equals(Object obj) {
277 if (this == obj) {
278 return true;
279 }
280 if (obj == null) {
281 return false;
282 }
283 if (!(obj instanceof EventDeclaration)) {
284 return false;
285 }
286 EventDeclaration other = (EventDeclaration) obj;
287 if (context == null) {
288 if (other.context != null) {
289 return false;
290 }
291 } else if (!context.equals(other.context)) {
292 return false;
293 }
294 if (fields == null) {
295 if (other.fields != null) {
296 return false;
297 }
298 } else if (!fields.equals(other.fields)) {
299 return false;
300 }
301 if (id == null) {
302 if (other.id != null) {
303 return false;
304 }
305 } else if (!id.equals(other.id)) {
306 return false;
307 }
308 if (name == null) {
309 if (other.name != null) {
310 return false;
311 }
312 } else if (!name.equals(other.name)) {
313 return false;
314 }
315 if (stream == null) {
316 if (other.stream != null) {
317 return false;
318 }
319 } else if (!stream.equals(other.stream)) {
320 return false;
321 }
8e964be1
MK
322 if (!customAttributes.equals(other.customAttributes)) {
323 return false;
324 }
866e5b51
FC
325 return true;
326 }
327
328 @Override
329 public int hashCode() {
330 final int prime = 31;
331 int result = 1;
332 result = (prime * result)
333 + ((context == null) ? 0 : context.hashCode());
334 result = (prime * result) + ((fields == null) ? 0 : fields.hashCode());
335 result = (prime * result) + ((id == null) ? 0 : id.hashCode());
336 result = (prime * result) + ((name == null) ? 0 : name.hashCode());
337 result = (prime * result) + ((stream == null) ? 0 : stream.hashCode());
77fdc5df 338 result = (prime * result) + customAttributes.hashCode();
866e5b51
FC
339 return result;
340 }
341
342}
This page took 0.046302 seconds and 5 git commands to generate.