Commit | Line | Data |
---|---|---|
8c8bf09f | 1 | /******************************************************************************* |
bcd97f27 | 2 | * Copyright (c) 2009, 2015 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; |
a5ee9b27 | 18 | import org.eclipse.tracecompass.common.core.NonNullUtils; |
2bdf0193 | 19 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; |
cbf0057c | 20 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp; |
2bdf0193 AM |
21 | import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; |
22 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
2c8610f7 | 23 | |
8c8bf09f | 24 | /** |
4c564a2d | 25 | * A basic implementation of ITmfEvent. |
6256d8ad | 26 | * |
b9e37ffd | 27 | * @author Francois Chouinard |
6256d8ad | 28 | * |
b9e37ffd FC |
29 | * @see ITmfTimestamp |
30 | * @see ITmfEventType | |
31 | * @see ITmfEventField | |
32 | * @see ITmfTrace | |
080600d9 MAL |
33 | */ |
34 | public class TmfEvent extends PlatformObject implements ITmfEvent { | |
12c155f5 | 35 | |
cbd4ad82 | 36 | // ------------------------------------------------------------------------ |
8c8bf09f | 37 | // Attributes |
cbd4ad82 | 38 | // ------------------------------------------------------------------------ |
8c8bf09f | 39 | |
bd54d363 AM |
40 | private final ITmfTrace fTrace; |
41 | private final long fRank; | |
cbf0057c | 42 | private final @NonNull ITmfTimestamp fTimestamp; |
bd54d363 AM |
43 | private final ITmfEventType fType; |
44 | private final ITmfEventField fContent; | |
28b94d61 | 45 | |
cbd4ad82 | 46 | // ------------------------------------------------------------------------ |
8c8bf09f | 47 | // Constructors |
cbd4ad82 | 48 | // ------------------------------------------------------------------------ |
8c8bf09f | 49 | |
2c8610f7 | 50 | /** |
0c7471fb AM |
51 | * Default constructor. Is required for extension points, but should not be |
52 | * used normally. | |
ca5b04ad | 53 | * |
0c7471fb | 54 | * @deprecated Do not use, extension-point use only. Use |
e1de2fd4 | 55 | * {@link #TmfEvent(ITmfTrace, long, ITmfTimestamp, ITmfEventType, ITmfEventField)} |
0c7471fb | 56 | * instead. |
2c8610f7 | 57 | */ |
0c7471fb | 58 | @Deprecated |
ce970a71 | 59 | public TmfEvent() { |
e1de2fd4 | 60 | this(null, ITmfContext.UNKNOWN_RANK, null, null, null); |
12c155f5 | 61 | } |
1f506a43 | 62 | |
b4d534a0 FC |
63 | /** |
64 | * Full constructor | |
6256d8ad | 65 | * |
ca5b04ad GB |
66 | * @param trace |
67 | * the parent trace | |
68 | * @param rank | |
0c7471fb AM |
69 | * the event rank (in the trace). You can use |
70 | * {@link ITmfContext#UNKNOWN_RANK} as default value | |
ca5b04ad GB |
71 | * @param timestamp |
72 | * the event timestamp | |
ca5b04ad GB |
73 | * @param type |
74 | * the event type | |
75 | * @param content | |
76 | * the event content (payload) | |
b4d534a0 | 77 | */ |
0c7471fb AM |
78 | public TmfEvent(final ITmfTrace trace, |
79 | final long rank, | |
80 | final ITmfTimestamp timestamp, | |
0c7471fb | 81 | final ITmfEventType type, |
e1de2fd4 | 82 | final ITmfEventField content) { |
b4d534a0 FC |
83 | fTrace = trace; |
84 | fRank = rank; | |
cbf0057c GB |
85 | if (timestamp != null) { |
86 | fTimestamp = timestamp; | |
87 | } else { | |
88 | fTimestamp = TmfTimestamp.ZERO; | |
89 | } | |
b4d534a0 FC |
90 | fType = type; |
91 | fContent = content; | |
b4d534a0 FC |
92 | } |
93 | ||
12c155f5 | 94 | /** |
ce970a71 | 95 | * Copy constructor |
6256d8ad | 96 | * |
ce970a71 | 97 | * @param event the original event |
12c155f5 | 98 | */ |
ca5b04ad | 99 | public TmfEvent(final @NonNull ITmfEvent event) { |
72f1e62a FC |
100 | fTrace = event.getTrace(); |
101 | fRank = event.getRank(); | |
102 | fTimestamp = event.getTimestamp(); | |
72f1e62a FC |
103 | fType = event.getType(); |
104 | fContent = event.getContent(); | |
12c155f5 | 105 | } |
8c8bf09f | 106 | |
ce970a71 | 107 | // ------------------------------------------------------------------------ |
108 | // ITmfEvent | |
109 | // ------------------------------------------------------------------------ | |
8c8bf09f | 110 | |
d7dbf09a | 111 | @Override |
6256d8ad | 112 | public ITmfTrace getTrace() { |
ca5b04ad GB |
113 | ITmfTrace trace = fTrace; |
114 | if (trace == null) { | |
115 | throw new IllegalStateException("Null traces are only allowed on special kind of events and getTrace() should not be called on them"); //$NON-NLS-1$ | |
116 | } | |
117 | return trace; | |
4c564a2d FC |
118 | } |
119 | ||
d7dbf09a | 120 | @Override |
4c564a2d FC |
121 | public long getRank() { |
122 | return fRank; | |
123 | } | |
124 | ||
d7dbf09a | 125 | @Override |
4df4581d | 126 | public ITmfTimestamp getTimestamp() { |
ce970a71 | 127 | return fTimestamp; |
12c155f5 | 128 | } |
1f506a43 | 129 | |
d7dbf09a | 130 | @Override |
4c564a2d FC |
131 | public ITmfEventType getType() { |
132 | return fType; | |
133 | } | |
134 | ||
d7dbf09a | 135 | @Override |
4c564a2d FC |
136 | public ITmfEventField getContent() { |
137 | return fContent; | |
138 | } | |
139 | ||
5c3d072d MK |
140 | /** |
141 | * @since 1.0 | |
142 | */ | |
143 | @Override | |
144 | public String getName() { | |
bcd97f27 | 145 | ITmfEventType type = getType(); |
5c3d072d MK |
146 | if (type != null) { |
147 | return type.getName(); | |
148 | } | |
149 | return ""; //$NON-NLS-1$ | |
150 | } | |
151 | ||
12c155f5 | 152 | // ------------------------------------------------------------------------ |
cbd4ad82 FC |
153 | // Object |
154 | // ------------------------------------------------------------------------ | |
28b94d61 | 155 | |
12c155f5 | 156 | @Override |
cbd4ad82 | 157 | public int hashCode() { |
ce970a71 | 158 | final int prime = 31; |
4c564a2d | 159 | int result = 1; |
a5ee9b27 AM |
160 | result = prime * result + ((fTrace == null) ? 0 : getTrace().hashCode()); |
161 | result = prime * result + (int) (getRank() ^ (getRank() >>> 32)); | |
162 | result = prime * result + getTimestamp().hashCode(); | |
163 | result = prime * result + ((getType() == null) ? 0 : getType().hashCode()); | |
164 | result = prime * result + ((getContent() == null) ? 0 : getContent().hashCode()); | |
cbd4ad82 FC |
165 | return result; |
166 | } | |
167 | ||
168 | @Override | |
085d898f | 169 | public boolean equals(final Object obj) { |
b9e37ffd | 170 | if (this == obj) { |
ce970a71 | 171 | return true; |
b9e37ffd FC |
172 | } |
173 | if (obj == null) { | |
12c155f5 | 174 | return false; |
b9e37ffd | 175 | } |
a5ee9b27 AM |
176 | |
177 | /* Two events must be of the exact same class to be equal */ | |
178 | if (!(this.getClass().equals(obj.getClass()))) { | |
ce970a71 | 179 | return false; |
b9e37ffd | 180 | } |
085d898f | 181 | final TmfEvent other = (TmfEvent) obj; |
a5ee9b27 | 182 | |
4c564a2d | 183 | if (fTrace == null) { |
b9e37ffd | 184 | if (other.fTrace != null) { |
4c564a2d | 185 | return false; |
b9e37ffd | 186 | } |
a5ee9b27 | 187 | } else if (!getTrace().equals(other.getTrace())) { |
4c564a2d | 188 | return false; |
b9e37ffd | 189 | } |
a5ee9b27 AM |
190 | |
191 | if (getRank() != other.getRank()) { | |
4c564a2d | 192 | return false; |
b9e37ffd | 193 | } |
a5ee9b27 | 194 | if (!getTimestamp().equals(other.getTimestamp())) { |
ce970a71 | 195 | return false; |
b9e37ffd | 196 | } |
a5ee9b27 | 197 | if (!NonNullUtils.equalsNullable(getType(), other.getType())) { |
4c564a2d | 198 | return false; |
b9e37ffd | 199 | } |
a5ee9b27 | 200 | if (!NonNullUtils.equalsNullable(getContent(), other.getContent())) { |
4c564a2d | 201 | return false; |
b9e37ffd | 202 | } |
0c841e0f | 203 | return true; |
cbd4ad82 | 204 | } |
28b94d61 | 205 | |
12c155f5 | 206 | @Override |
3b38ea61 | 207 | @SuppressWarnings("nls") |
12c155f5 | 208 | public String toString() { |
bd54d363 AM |
209 | return getClass().getSimpleName() + " [fTimestamp=" + getTimestamp() |
210 | + ", fTrace=" + getTrace() + ", fRank=" + getRank() | |
e1de2fd4 | 211 | + ", fType=" + getType() + ", fContent=" + getContent() |
bd54d363 | 212 | + "]"; |
12c155f5 | 213 | } |
f9673903 | 214 | |
8c8bf09f | 215 | } |