Clean up code.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / EventDeclaration.java
CommitLineData
866e5b51
FC
1/*******************************************************************************
2 * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
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
13package org.eclipse.linuxtools.ctf.core.event;
14
15import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
866e5b51 16import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
ce2388e0 17import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
866e5b51
FC
18
19/**
20 * <b><u>EventDeclaration</u></b>
21 * <p>
22 * Represents one type of event.
23 */
24public class EventDeclaration {
25
26 // ------------------------------------------------------------------------
27 // Attributes
28 // ------------------------------------------------------------------------
29
30 /**
31 * Name of the event
32 */
33 private String name;
34
35 /**
36 * Event context structure declaration
37 */
38 private StructDeclaration context = null;
39
40 /**
41 * Event fields structure declaration
42 */
43 private StructDeclaration fields = null;
44
45 /**
46 * Event id (can be null if only event in the stream).
47 */
48 private Long id = null;
49
50 /**
51 * Stream to which belongs this event.
52 */
53 private Stream stream = null;
54
53047a66
MK
55 /**
56 * Loglevel of an event
57 */
58 private long logLevel;
59
866e5b51
FC
60 // ------------------------------------------------------------------------
61 // Constructors
62 // ------------------------------------------------------------------------
63
64 /**
65 * Creates an instance of EventDefinition corresponding to this declaration.
66 *
67 * @param streamInputReader
68 * The StreamInputReader for which this definition is created.
69 * @return A new EventDefinition.
70 */
71 public EventDefinition createDefinition(StreamInputReader streamInputReader) {
72 EventDefinition event = new EventDefinition(this, streamInputReader);
73
74 if (context != null) {
aa572e22 75 event.setContext( context.createDefinition(event, "context")); //$NON-NLS-1$
866e5b51
FC
76 }
77
78 if (this.fields != null) {
aa572e22 79 event.setFields(this.fields.createDefinition(event, "fields")); //$NON-NLS-1$
866e5b51
FC
80 }
81
82 return event;
83 }
84
33656d8e
MK
85 /**
86 * Creates a "lost" event. This is a synthetic event that is there to show
87 * that there should be something there.
88 * @return
89 */
debcffff
MK
90 public synchronized static EventDeclaration getLostEventDeclaration(){
91 EventDeclaration lostEvent = new EventDeclaration();
92 lostEvent.fields = new StructDeclaration(1);
07002e0a 93 lostEvent.id = -1L;
debcffff 94 lostEvent.name = "Lost event"; //$NON-NLS-1$
33656d8e
MK
95 return lostEvent;
96 }
97
866e5b51
FC
98 // ------------------------------------------------------------------------
99 // Getters/Setters/Predicates
100 // ------------------------------------------------------------------------
101
102 public void setName(String name) {
103 this.name = name;
104 }
105
106 public String getName() {
107 return name;
108 }
109
110 public void setContext(StructDeclaration context) {
111 this.context = context;
112 }
113
114 public void setFields(StructDeclaration fields) {
115 this.fields = fields;
116 }
117
118 public StructDeclaration getFields() {
119 return fields;
120 }
121
122 public StructDeclaration getContext() {
123 return context;
124 }
125
126 public void setId(long id) {
127 this.id = id;
128 }
129
130 public Long getId() {
131 return id;
132 }
133
134 public void setStream(Stream stream) {
135 this.stream = stream;
136 }
137
138 public Stream getStream() {
139 return stream;
140 }
141
142 public boolean nameIsSet() {
143 return name != null;
144 }
145
146 public boolean contextIsSet() {
147 return context != null;
148 }
149
150 public boolean fieldsIsSet() {
151 return fields != null;
152 }
153
154 public boolean idIsSet() {
155 return id != null;
156 }
157
158 public boolean streamIsSet() {
159 return stream != null;
160 }
161
53047a66
MK
162 public long getLogLevel() {
163 return logLevel;
164 }
165
166 public void setLogLevel( long level){
167 logLevel = level;
168 }
169
866e5b51
FC
170 // ------------------------------------------------------------------------
171 // Operations
172 // ------------------------------------------------------------------------
173
174 @Override
175 public boolean equals(Object obj) {
176 if (this == obj) {
177 return true;
178 }
179 if (obj == null) {
180 return false;
181 }
182 if (!(obj instanceof EventDeclaration)) {
183 return false;
184 }
185 EventDeclaration other = (EventDeclaration) obj;
186 if (context == null) {
187 if (other.context != null) {
188 return false;
189 }
190 } else if (!context.equals(other.context)) {
191 return false;
192 }
193 if (fields == null) {
194 if (other.fields != null) {
195 return false;
196 }
197 } else if (!fields.equals(other.fields)) {
198 return false;
199 }
200 if (id == null) {
201 if (other.id != null) {
202 return false;
203 }
204 } else if (!id.equals(other.id)) {
205 return false;
206 }
207 if (name == null) {
208 if (other.name != null) {
209 return false;
210 }
211 } else if (!name.equals(other.name)) {
212 return false;
213 }
214 if (stream == null) {
215 if (other.stream != null) {
216 return false;
217 }
218 } else if (!stream.equals(other.stream)) {
219 return false;
220 }
221 return true;
222 }
223
224 @Override
225 public int hashCode() {
226 final int prime = 31;
227 int result = 1;
228 result = (prime * result)
229 + ((context == null) ? 0 : context.hashCode());
230 result = (prime * result) + ((fields == null) ? 0 : fields.hashCode());
231 result = (prime * result) + ((id == null) ? 0 : id.hashCode());
232 result = (prime * result) + ((name == null) ? 0 : name.hashCode());
233 result = (prime * result) + ((stream == null) ? 0 : stream.hashCode());
234 return result;
235 }
236
237}
This page took 0.03452 seconds and 5 git commands to generate.