Commit | Line | Data |
---|---|---|
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 | ||
13 | package org.eclipse.linuxtools.ctf.core.event; | |
14 | ||
15 | import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; | |
866e5b51 | 16 | import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; |
ce2388e0 | 17 | import 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 | */ | |
24 | public 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 | ||
55 | // ------------------------------------------------------------------------ | |
56 | // Constructors | |
57 | // ------------------------------------------------------------------------ | |
58 | ||
59 | /** | |
60 | * Creates an instance of EventDefinition corresponding to this declaration. | |
61 | * | |
62 | * @param streamInputReader | |
63 | * The StreamInputReader for which this definition is created. | |
64 | * @return A new EventDefinition. | |
65 | */ | |
66 | public EventDefinition createDefinition(StreamInputReader streamInputReader) { | |
67 | EventDefinition event = new EventDefinition(this, streamInputReader); | |
68 | ||
69 | if (context != null) { | |
70 | event.context = context.createDefinition(event, "context"); //$NON-NLS-1$ | |
71 | } | |
72 | ||
73 | if (this.fields != null) { | |
74 | event.fields = this.fields.createDefinition(event, "fields"); //$NON-NLS-1$ | |
75 | } | |
76 | ||
77 | return event; | |
78 | } | |
79 | ||
80 | // ------------------------------------------------------------------------ | |
81 | // Getters/Setters/Predicates | |
82 | // ------------------------------------------------------------------------ | |
83 | ||
84 | public void setName(String name) { | |
85 | this.name = name; | |
86 | } | |
87 | ||
88 | public String getName() { | |
89 | return name; | |
90 | } | |
91 | ||
92 | public void setContext(StructDeclaration context) { | |
93 | this.context = context; | |
94 | } | |
95 | ||
96 | public void setFields(StructDeclaration fields) { | |
97 | this.fields = fields; | |
98 | } | |
99 | ||
100 | public StructDeclaration getFields() { | |
101 | return fields; | |
102 | } | |
103 | ||
104 | public StructDeclaration getContext() { | |
105 | return context; | |
106 | } | |
107 | ||
108 | public void setId(long id) { | |
109 | this.id = id; | |
110 | } | |
111 | ||
112 | public Long getId() { | |
113 | return id; | |
114 | } | |
115 | ||
116 | public void setStream(Stream stream) { | |
117 | this.stream = stream; | |
118 | } | |
119 | ||
120 | public Stream getStream() { | |
121 | return stream; | |
122 | } | |
123 | ||
124 | public boolean nameIsSet() { | |
125 | return name != null; | |
126 | } | |
127 | ||
128 | public boolean contextIsSet() { | |
129 | return context != null; | |
130 | } | |
131 | ||
132 | public boolean fieldsIsSet() { | |
133 | return fields != null; | |
134 | } | |
135 | ||
136 | public boolean idIsSet() { | |
137 | return id != null; | |
138 | } | |
139 | ||
140 | public boolean streamIsSet() { | |
141 | return stream != null; | |
142 | } | |
143 | ||
144 | // ------------------------------------------------------------------------ | |
145 | // Operations | |
146 | // ------------------------------------------------------------------------ | |
147 | ||
148 | @Override | |
149 | public boolean equals(Object obj) { | |
150 | if (this == obj) { | |
151 | return true; | |
152 | } | |
153 | if (obj == null) { | |
154 | return false; | |
155 | } | |
156 | if (!(obj instanceof EventDeclaration)) { | |
157 | return false; | |
158 | } | |
159 | EventDeclaration other = (EventDeclaration) obj; | |
160 | if (context == null) { | |
161 | if (other.context != null) { | |
162 | return false; | |
163 | } | |
164 | } else if (!context.equals(other.context)) { | |
165 | return false; | |
166 | } | |
167 | if (fields == null) { | |
168 | if (other.fields != null) { | |
169 | return false; | |
170 | } | |
171 | } else if (!fields.equals(other.fields)) { | |
172 | return false; | |
173 | } | |
174 | if (id == null) { | |
175 | if (other.id != null) { | |
176 | return false; | |
177 | } | |
178 | } else if (!id.equals(other.id)) { | |
179 | return false; | |
180 | } | |
181 | if (name == null) { | |
182 | if (other.name != null) { | |
183 | return false; | |
184 | } | |
185 | } else if (!name.equals(other.name)) { | |
186 | return false; | |
187 | } | |
188 | if (stream == null) { | |
189 | if (other.stream != null) { | |
190 | return false; | |
191 | } | |
192 | } else if (!stream.equals(other.stream)) { | |
193 | return false; | |
194 | } | |
195 | return true; | |
196 | } | |
197 | ||
198 | @Override | |
199 | public int hashCode() { | |
200 | final int prime = 31; | |
201 | int result = 1; | |
202 | result = (prime * result) | |
203 | + ((context == null) ? 0 : context.hashCode()); | |
204 | result = (prime * result) + ((fields == null) ? 0 : fields.hashCode()); | |
205 | result = (prime * result) + ((id == null) ? 0 : id.hashCode()); | |
206 | result = (prime * result) + ((name == null) ? 0 : name.hashCode()); | |
207 | result = (prime * result) + ((stream == null) ? 0 : stream.hashCode()); | |
208 | return result; | |
209 | } | |
210 | ||
211 | } |