Commit | Line | Data |
---|---|---|
8c8bf09f | 1 | /******************************************************************************* |
0c7471fb | 2 | * Copyright (c) 2009, 2014 Ericsson |
6256d8ad | 3 | * |
ce970a71 | 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 | |
8c8bf09f ASL |
6 | * accompanies this distribution, and is available at |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
6256d8ad | 8 | * |
bbc1c411 | 9 | * Contributors: |
0c7471fb AM |
10 | * Francois Chouinard - Initial API and implementation, updated as per TMF Event Model 1.0 |
11 | * Alexandre Montplaisir - Made immutable, consolidated constructors | |
8c8bf09f ASL |
12 | *******************************************************************************/ |
13 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.tmf.core.event; |
8c8bf09f | 15 | |
080600d9 | 16 | import org.eclipse.core.runtime.PlatformObject; |
ca5b04ad | 17 | import org.eclipse.jdt.annotation.NonNull; |
2bdf0193 AM |
18 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; |
19 | import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; | |
20 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
2c8610f7 | 21 | |
8c8bf09f | 22 | /** |
4c564a2d | 23 | * A basic implementation of ITmfEvent. |
6256d8ad | 24 | * |
b9e37ffd FC |
25 | * @version 1.0 |
26 | * @author Francois Chouinard | |
6256d8ad | 27 | * |
b9e37ffd FC |
28 | * @see ITmfTimestamp |
29 | * @see ITmfEventType | |
30 | * @see ITmfEventField | |
31 | * @see ITmfTrace | |
080600d9 MAL |
32 | */ |
33 | public class TmfEvent extends PlatformObject implements ITmfEvent { | |
12c155f5 | 34 | |
cbd4ad82 | 35 | // ------------------------------------------------------------------------ |
8c8bf09f | 36 | // Attributes |
cbd4ad82 | 37 | // ------------------------------------------------------------------------ |
8c8bf09f | 38 | |
bd54d363 AM |
39 | private final ITmfTrace fTrace; |
40 | private final long fRank; | |
41 | private final ITmfTimestamp fTimestamp; | |
42 | private final String fSource; | |
43 | private final ITmfEventType fType; | |
44 | private final ITmfEventField fContent; | |
45 | private final String fReference; | |
28b94d61 | 46 | |
cbd4ad82 | 47 | // ------------------------------------------------------------------------ |
8c8bf09f | 48 | // Constructors |
cbd4ad82 | 49 | // ------------------------------------------------------------------------ |
8c8bf09f | 50 | |
2c8610f7 | 51 | /** |
0c7471fb AM |
52 | * Default constructor. Is required for extension points, but should not be |
53 | * used normally. | |
ca5b04ad | 54 | * |
0c7471fb AM |
55 | * @deprecated Do not use, extension-point use only. Use |
56 | * {@link #TmfEvent(ITmfTrace, long, ITmfTimestamp, String, ITmfEventType, ITmfEventField, String)} | |
57 | * instead. | |
2c8610f7 | 58 | */ |
0c7471fb | 59 | @Deprecated |
ce970a71 | 60 | public TmfEvent() { |
9b749023 | 61 | this(null, ITmfContext.UNKNOWN_RANK, null, null, null, null, null); |
12c155f5 | 62 | } |
1f506a43 | 63 | |
b4d534a0 FC |
64 | /** |
65 | * Full constructor | |
6256d8ad | 66 | * |
ca5b04ad GB |
67 | * @param trace |
68 | * the parent trace | |
69 | * @param rank | |
0c7471fb AM |
70 | * the event rank (in the trace). You can use |
71 | * {@link ITmfContext#UNKNOWN_RANK} as default value | |
ca5b04ad GB |
72 | * @param timestamp |
73 | * the event timestamp | |
74 | * @param source | |
75 | * the event source | |
76 | * @param type | |
77 | * the event type | |
78 | * @param content | |
79 | * the event content (payload) | |
80 | * @param reference | |
81 | * the event reference | |
3bd46eef | 82 | * @since 2.0 |
b4d534a0 | 83 | */ |
0c7471fb AM |
84 | public TmfEvent(final ITmfTrace trace, |
85 | final long rank, | |
86 | final ITmfTimestamp timestamp, | |
87 | final String source, | |
88 | final ITmfEventType type, | |
89 | final ITmfEventField content, | |
90 | final String reference) { | |
b4d534a0 FC |
91 | fTrace = trace; |
92 | fRank = rank; | |
93 | fTimestamp = timestamp; | |
94 | fSource = source; | |
95 | fType = type; | |
96 | fContent = content; | |
97 | fReference = reference; | |
98 | } | |
99 | ||
12c155f5 | 100 | /** |
ce970a71 | 101 | * Copy constructor |
6256d8ad | 102 | * |
ce970a71 | 103 | * @param event the original event |
12c155f5 | 104 | */ |
ca5b04ad | 105 | public TmfEvent(final @NonNull ITmfEvent event) { |
72f1e62a FC |
106 | fTrace = event.getTrace(); |
107 | fRank = event.getRank(); | |
108 | fTimestamp = event.getTimestamp(); | |
109 | fSource = event.getSource(); | |
110 | fType = event.getType(); | |
111 | fContent = event.getContent(); | |
112 | fReference = event.getReference(); | |
12c155f5 | 113 | } |
8c8bf09f | 114 | |
ce970a71 | 115 | // ------------------------------------------------------------------------ |
116 | // ITmfEvent | |
117 | // ------------------------------------------------------------------------ | |
8c8bf09f | 118 | |
d7dbf09a | 119 | @Override |
6256d8ad | 120 | public ITmfTrace getTrace() { |
ca5b04ad GB |
121 | ITmfTrace trace = fTrace; |
122 | if (trace == null) { | |
123 | throw new IllegalStateException("Null traces are only allowed on special kind of events and getTrace() should not be called on them"); //$NON-NLS-1$ | |
124 | } | |
125 | return trace; | |
4c564a2d FC |
126 | } |
127 | ||
d7dbf09a | 128 | @Override |
4c564a2d FC |
129 | public long getRank() { |
130 | return fRank; | |
131 | } | |
132 | ||
3bd46eef AM |
133 | /** |
134 | * @since 2.0 | |
135 | */ | |
d7dbf09a | 136 | @Override |
4df4581d | 137 | public ITmfTimestamp getTimestamp() { |
ce970a71 | 138 | return fTimestamp; |
12c155f5 | 139 | } |
1f506a43 | 140 | |
d7dbf09a | 141 | @Override |
4c564a2d FC |
142 | public String getSource() { |
143 | return fSource; | |
144 | } | |
145 | ||
d7dbf09a | 146 | @Override |
4c564a2d FC |
147 | public ITmfEventType getType() { |
148 | return fType; | |
149 | } | |
150 | ||
d7dbf09a | 151 | @Override |
4c564a2d FC |
152 | public ITmfEventField getContent() { |
153 | return fContent; | |
154 | } | |
155 | ||
d7dbf09a | 156 | @Override |
4c564a2d FC |
157 | public String getReference() { |
158 | return fReference; | |
159 | } | |
160 | ||
12c155f5 | 161 | // ------------------------------------------------------------------------ |
cbd4ad82 FC |
162 | // Object |
163 | // ------------------------------------------------------------------------ | |
28b94d61 | 164 | |
12c155f5 | 165 | @Override |
cbd4ad82 | 166 | public int hashCode() { |
ce970a71 | 167 | final int prime = 31; |
4c564a2d FC |
168 | int result = 1; |
169 | result = prime * result + ((fTrace == null) ? 0 : fTrace.hashCode()); | |
170 | result = prime * result + (int) (fRank ^ (fRank >>> 32)); | |
ce970a71 | 171 | result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode()); |
4c564a2d FC |
172 | result = prime * result + ((fSource == null) ? 0 : fSource.hashCode()); |
173 | result = prime * result + ((fType == null) ? 0 : fType.hashCode()); | |
174 | result = prime * result + ((fContent == null) ? 0 : fContent.hashCode()); | |
175 | result = prime * result + ((fReference == null) ? 0 : fReference.hashCode()); | |
cbd4ad82 FC |
176 | return result; |
177 | } | |
178 | ||
179 | @Override | |
085d898f | 180 | public boolean equals(final Object obj) { |
b9e37ffd | 181 | if (this == obj) { |
ce970a71 | 182 | return true; |
b9e37ffd FC |
183 | } |
184 | if (obj == null) { | |
12c155f5 | 185 | return false; |
b9e37ffd FC |
186 | } |
187 | if (!(obj instanceof TmfEvent)) { | |
ce970a71 | 188 | return false; |
b9e37ffd | 189 | } |
085d898f | 190 | final TmfEvent other = (TmfEvent) obj; |
4c564a2d | 191 | if (fTrace == null) { |
b9e37ffd | 192 | if (other.fTrace != null) { |
4c564a2d | 193 | return false; |
b9e37ffd FC |
194 | } |
195 | } else if (!fTrace.equals(other.fTrace)) { | |
4c564a2d | 196 | return false; |
b9e37ffd FC |
197 | } |
198 | if (fRank != other.fRank) { | |
4c564a2d | 199 | return false; |
b9e37ffd | 200 | } |
ce970a71 | 201 | if (fTimestamp == null) { |
b9e37ffd | 202 | if (other.fTimestamp != null) { |
0c841e0f | 203 | return false; |
b9e37ffd FC |
204 | } |
205 | } else if (!fTimestamp.equals(other.fTimestamp)) { | |
ce970a71 | 206 | return false; |
b9e37ffd | 207 | } |
4c564a2d | 208 | if (fSource == null) { |
b9e37ffd | 209 | if (other.fSource != null) { |
4c564a2d | 210 | return false; |
b9e37ffd FC |
211 | } |
212 | } else if (!fSource.equals(other.fSource)) { | |
4c564a2d | 213 | return false; |
b9e37ffd | 214 | } |
4c564a2d | 215 | if (fType == null) { |
b9e37ffd | 216 | if (other.fType != null) { |
4c564a2d | 217 | return false; |
b9e37ffd FC |
218 | } |
219 | } else if (!fType.equals(other.fType)) { | |
4c564a2d | 220 | return false; |
b9e37ffd | 221 | } |
4c564a2d | 222 | if (fContent == null) { |
b9e37ffd | 223 | if (other.fContent != null) { |
4c564a2d | 224 | return false; |
b9e37ffd FC |
225 | } |
226 | } else if (!fContent.equals(other.fContent)) { | |
4c564a2d | 227 | return false; |
b9e37ffd | 228 | } |
4c564a2d | 229 | if (fReference == null) { |
b9e37ffd | 230 | if (other.fReference != null) { |
4c564a2d | 231 | return false; |
b9e37ffd FC |
232 | } |
233 | } else if (!fReference.equals(other.fReference)) { | |
4c564a2d | 234 | return false; |
b9e37ffd | 235 | } |
0c841e0f | 236 | return true; |
cbd4ad82 | 237 | } |
28b94d61 | 238 | |
12c155f5 | 239 | @Override |
3b38ea61 | 240 | @SuppressWarnings("nls") |
12c155f5 | 241 | public String toString() { |
bd54d363 AM |
242 | return getClass().getSimpleName() + " [fTimestamp=" + getTimestamp() |
243 | + ", fTrace=" + getTrace() + ", fRank=" + getRank() | |
244 | + ", fSource=" + getSource() + ", fType=" + getType() | |
245 | + ", fContent=" + getContent() + ", fReference=" + getReference() | |
246 | + "]"; | |
12c155f5 | 247 | } |
f9673903 | 248 | |
8c8bf09f | 249 | } |