1 /*******************************************************************************
2 * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
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
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.ctf
.core
.event
;
15 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
16 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.StreamInputReader
;
17 import org
.eclipse
.linuxtools
.internal
.ctf
.core
.trace
.Stream
;
20 * <b><u>EventDeclaration</u></b>
22 * Represents one type of event.
24 public class EventDeclaration
{
26 // ------------------------------------------------------------------------
28 // ------------------------------------------------------------------------
36 * Event context structure declaration
38 private StructDeclaration context
= null;
41 * Event fields structure declaration
43 private StructDeclaration fields
= null;
46 * Event id (can be null if only event in the stream).
48 private Long id
= null;
51 * Stream to which belongs this event.
53 private Stream stream
= null;
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
60 * Creates an instance of EventDefinition corresponding to this declaration.
62 * @param streamInputReader
63 * The StreamInputReader for which this definition is created.
64 * @return A new EventDefinition.
66 public EventDefinition
createDefinition(StreamInputReader streamInputReader
) {
67 EventDefinition event
= new EventDefinition(this, streamInputReader
);
69 if (context
!= null) {
70 event
.context
= context
.createDefinition(event
, "context"); //$NON-NLS-1$
73 if (this.fields
!= null) {
74 event
.fields
= this.fields
.createDefinition(event
, "fields"); //$NON-NLS-1$
80 // ------------------------------------------------------------------------
81 // Getters/Setters/Predicates
82 // ------------------------------------------------------------------------
84 public void setName(String name
) {
88 public String
getName() {
92 public void setContext(StructDeclaration context
) {
93 this.context
= context
;
96 public void setFields(StructDeclaration fields
) {
100 public StructDeclaration
getFields() {
104 public StructDeclaration
getContext() {
108 public void setId(long id
) {
112 public Long
getId() {
116 public void setStream(Stream stream
) {
117 this.stream
= stream
;
120 public Stream
getStream() {
124 public boolean nameIsSet() {
128 public boolean contextIsSet() {
129 return context
!= null;
132 public boolean fieldsIsSet() {
133 return fields
!= null;
136 public boolean idIsSet() {
140 public boolean streamIsSet() {
141 return stream
!= null;
144 // ------------------------------------------------------------------------
146 // ------------------------------------------------------------------------
149 public boolean equals(Object obj
) {
156 if (!(obj
instanceof EventDeclaration
)) {
159 EventDeclaration other
= (EventDeclaration
) obj
;
160 if (context
== null) {
161 if (other
.context
!= null) {
164 } else if (!context
.equals(other
.context
)) {
167 if (fields
== null) {
168 if (other
.fields
!= null) {
171 } else if (!fields
.equals(other
.fields
)) {
175 if (other
.id
!= null) {
178 } else if (!id
.equals(other
.id
)) {
182 if (other
.name
!= null) {
185 } else if (!name
.equals(other
.name
)) {
188 if (stream
== null) {
189 if (other
.stream
!= null) {
192 } else if (!stream
.equals(other
.stream
)) {
199 public int hashCode() {
200 final int prime
= 31;
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());