analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / event / TmfEvent.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2015 Ericsson
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:
10 * Francois Chouinard - Initial API and implementation, updated as per TMF Event Model 1.0
11 * Alexandre Montplaisir - Made immutable, consolidated constructors
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.tmf.core.event;
15
16 import org.eclipse.core.runtime.PlatformObject;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
19 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
20 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
21 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
22
23 /**
24 * A basic implementation of ITmfEvent.
25 *
26 * @author Francois Chouinard
27 *
28 * @see ITmfTimestamp
29 * @see ITmfEventType
30 * @see ITmfEventField
31 * @see ITmfTrace
32 */
33 public class TmfEvent extends PlatformObject implements ITmfEvent {
34
35 // ------------------------------------------------------------------------
36 // Attributes
37 // ------------------------------------------------------------------------
38
39 private final ITmfTrace fTrace;
40 private final long fRank;
41 private final @NonNull ITmfTimestamp fTimestamp;
42 private final ITmfEventType fType;
43 private final ITmfEventField fContent;
44
45 // ------------------------------------------------------------------------
46 // Constructors
47 // ------------------------------------------------------------------------
48
49 /**
50 * Default constructor. Is required for extension points, but should not be
51 * used normally.
52 *
53 * @deprecated Do not use, extension-point use only. Use
54 * {@link #TmfEvent(ITmfTrace, long, ITmfTimestamp, ITmfEventType, ITmfEventField)}
55 * instead.
56 */
57 @Deprecated
58 public TmfEvent() {
59 this(null, ITmfContext.UNKNOWN_RANK, null, null, null);
60 }
61
62 /**
63 * Full constructor
64 *
65 * @param trace
66 * the parent trace
67 * @param rank
68 * the event rank (in the trace). You can use
69 * {@link ITmfContext#UNKNOWN_RANK} as default value
70 * @param timestamp
71 * the event timestamp
72 * @param type
73 * the event type
74 * @param content
75 * the event content (payload)
76 */
77 public TmfEvent(final ITmfTrace trace,
78 final long rank,
79 final ITmfTimestamp timestamp,
80 final ITmfEventType type,
81 final ITmfEventField content) {
82 fTrace = trace;
83 fRank = rank;
84 if (timestamp != null) {
85 fTimestamp = timestamp;
86 } else {
87 fTimestamp = TmfTimestamp.ZERO;
88 }
89 fType = type;
90 fContent = content;
91 }
92
93 /**
94 * Copy constructor
95 *
96 * @param event the original event
97 */
98 public TmfEvent(final @NonNull ITmfEvent event) {
99 fTrace = event.getTrace();
100 fRank = event.getRank();
101 fTimestamp = event.getTimestamp();
102 fType = event.getType();
103 fContent = event.getContent();
104 }
105
106 // ------------------------------------------------------------------------
107 // ITmfEvent
108 // ------------------------------------------------------------------------
109
110 @Override
111 public ITmfTrace getTrace() {
112 ITmfTrace trace = fTrace;
113 if (trace == null) {
114 throw new IllegalStateException("Null traces are only allowed on special kind of events and getTrace() should not be called on them"); //$NON-NLS-1$
115 }
116 return trace;
117 }
118
119 @Override
120 public long getRank() {
121 return fRank;
122 }
123
124 @Override
125 public ITmfTimestamp getTimestamp() {
126 return fTimestamp;
127 }
128
129 @Override
130 public ITmfEventType getType() {
131 return fType;
132 }
133
134 @Override
135 public ITmfEventField getContent() {
136 return fContent;
137 }
138
139 /**
140 * @since 1.0
141 */
142 @Override
143 public String getName() {
144 ITmfEventType type = getType();
145 if (type != null) {
146 return type.getName();
147 }
148 return ""; //$NON-NLS-1$
149 }
150
151 // ------------------------------------------------------------------------
152 // Object
153 // ------------------------------------------------------------------------
154
155 @Override
156 public int hashCode() {
157 final int prime = 31;
158 int result = 1;
159 result = prime * result + ((fTrace == null) ? 0 : fTrace.hashCode());
160 result = prime * result + (int) (fRank ^ (fRank >>> 32));
161 result = prime * result + fTimestamp.hashCode();
162 result = prime * result + ((fType == null) ? 0 : fType.hashCode());
163 result = prime * result + ((fContent == null) ? 0 : fContent.hashCode());
164 return result;
165 }
166
167 @Override
168 public boolean equals(final Object obj) {
169 if (this == obj) {
170 return true;
171 }
172 if (obj == null) {
173 return false;
174 }
175 if (!(obj instanceof TmfEvent)) {
176 return false;
177 }
178 final TmfEvent other = (TmfEvent) obj;
179 if (fTrace == null) {
180 if (other.fTrace != null) {
181 return false;
182 }
183 } else if (!fTrace.equals(other.fTrace)) {
184 return false;
185 }
186 if (fRank != other.fRank) {
187 return false;
188 }
189 if (!fTimestamp.equals(other.fTimestamp)) {
190 return false;
191 }
192 if (fType == null) {
193 if (other.fType != null) {
194 return false;
195 }
196 } else if (!fType.equals(other.fType)) {
197 return false;
198 }
199 if (fContent == null) {
200 if (other.fContent != null) {
201 return false;
202 }
203 } else if (!fContent.equals(other.fContent)) {
204 return false;
205 }
206 return true;
207 }
208
209 @Override
210 @SuppressWarnings("nls")
211 public String toString() {
212 return getClass().getSimpleName() + " [fTimestamp=" + getTimestamp()
213 + ", fTrace=" + getTrace() + ", fRank=" + getRank()
214 + ", fType=" + getType() + ", fContent=" + getContent()
215 + "]";
216 }
217
218 }
This page took 0.03624 seconds and 5 git commands to generate.