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; | |
bd54d363 AM |
42 | private final ITmfEventType fType; |
43 | private final ITmfEventField fContent; | |
28b94d61 | 44 | |
cbd4ad82 | 45 | // ------------------------------------------------------------------------ |
8c8bf09f | 46 | // Constructors |
cbd4ad82 | 47 | // ------------------------------------------------------------------------ |
8c8bf09f | 48 | |
2c8610f7 | 49 | /** |
0c7471fb AM |
50 | * Default constructor. Is required for extension points, but should not be |
51 | * used normally. | |
ca5b04ad | 52 | * |
0c7471fb | 53 | * @deprecated Do not use, extension-point use only. Use |
e1de2fd4 | 54 | * {@link #TmfEvent(ITmfTrace, long, ITmfTimestamp, ITmfEventType, ITmfEventField)} |
0c7471fb | 55 | * instead. |
2c8610f7 | 56 | */ |
0c7471fb | 57 | @Deprecated |
ce970a71 | 58 | public TmfEvent() { |
e1de2fd4 | 59 | this(null, ITmfContext.UNKNOWN_RANK, null, null, null); |
12c155f5 | 60 | } |
1f506a43 | 61 | |
b4d534a0 FC |
62 | /** |
63 | * Full constructor | |
6256d8ad | 64 | * |
ca5b04ad GB |
65 | * @param trace |
66 | * the parent trace | |
67 | * @param rank | |
0c7471fb AM |
68 | * the event rank (in the trace). You can use |
69 | * {@link ITmfContext#UNKNOWN_RANK} as default value | |
ca5b04ad GB |
70 | * @param timestamp |
71 | * the event timestamp | |
ca5b04ad GB |
72 | * @param type |
73 | * the event type | |
74 | * @param content | |
75 | * the event content (payload) | |
3bd46eef | 76 | * @since 2.0 |
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; | |
85 | fTimestamp = timestamp; | |
b4d534a0 FC |
86 | fType = type; |
87 | fContent = content; | |
b4d534a0 FC |
88 | } |
89 | ||
12c155f5 | 90 | /** |
ce970a71 | 91 | * Copy constructor |
6256d8ad | 92 | * |
ce970a71 | 93 | * @param event the original event |
12c155f5 | 94 | */ |
ca5b04ad | 95 | public TmfEvent(final @NonNull ITmfEvent event) { |
72f1e62a FC |
96 | fTrace = event.getTrace(); |
97 | fRank = event.getRank(); | |
98 | fTimestamp = event.getTimestamp(); | |
72f1e62a FC |
99 | fType = event.getType(); |
100 | fContent = event.getContent(); | |
12c155f5 | 101 | } |
8c8bf09f | 102 | |
ce970a71 | 103 | // ------------------------------------------------------------------------ |
104 | // ITmfEvent | |
105 | // ------------------------------------------------------------------------ | |
8c8bf09f | 106 | |
d7dbf09a | 107 | @Override |
6256d8ad | 108 | public ITmfTrace getTrace() { |
ca5b04ad GB |
109 | ITmfTrace trace = fTrace; |
110 | if (trace == null) { | |
111 | throw new IllegalStateException("Null traces are only allowed on special kind of events and getTrace() should not be called on them"); //$NON-NLS-1$ | |
112 | } | |
113 | return trace; | |
4c564a2d FC |
114 | } |
115 | ||
d7dbf09a | 116 | @Override |
4c564a2d FC |
117 | public long getRank() { |
118 | return fRank; | |
119 | } | |
120 | ||
3bd46eef AM |
121 | /** |
122 | * @since 2.0 | |
123 | */ | |
d7dbf09a | 124 | @Override |
4df4581d | 125 | public ITmfTimestamp getTimestamp() { |
ce970a71 | 126 | return fTimestamp; |
12c155f5 | 127 | } |
1f506a43 | 128 | |
d7dbf09a | 129 | @Override |
4c564a2d FC |
130 | public ITmfEventType getType() { |
131 | return fType; | |
132 | } | |
133 | ||
d7dbf09a | 134 | @Override |
4c564a2d FC |
135 | public ITmfEventField getContent() { |
136 | return fContent; | |
137 | } | |
138 | ||
12c155f5 | 139 | // ------------------------------------------------------------------------ |
cbd4ad82 FC |
140 | // Object |
141 | // ------------------------------------------------------------------------ | |
28b94d61 | 142 | |
12c155f5 | 143 | @Override |
cbd4ad82 | 144 | public int hashCode() { |
ce970a71 | 145 | final int prime = 31; |
4c564a2d FC |
146 | int result = 1; |
147 | result = prime * result + ((fTrace == null) ? 0 : fTrace.hashCode()); | |
148 | result = prime * result + (int) (fRank ^ (fRank >>> 32)); | |
ce970a71 | 149 | result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode()); |
4c564a2d FC |
150 | result = prime * result + ((fType == null) ? 0 : fType.hashCode()); |
151 | result = prime * result + ((fContent == null) ? 0 : fContent.hashCode()); | |
cbd4ad82 FC |
152 | return result; |
153 | } | |
154 | ||
155 | @Override | |
085d898f | 156 | public boolean equals(final Object obj) { |
b9e37ffd | 157 | if (this == obj) { |
ce970a71 | 158 | return true; |
b9e37ffd FC |
159 | } |
160 | if (obj == null) { | |
12c155f5 | 161 | return false; |
b9e37ffd FC |
162 | } |
163 | if (!(obj instanceof TmfEvent)) { | |
ce970a71 | 164 | return false; |
b9e37ffd | 165 | } |
085d898f | 166 | final TmfEvent other = (TmfEvent) obj; |
4c564a2d | 167 | if (fTrace == null) { |
b9e37ffd | 168 | if (other.fTrace != null) { |
4c564a2d | 169 | return false; |
b9e37ffd FC |
170 | } |
171 | } else if (!fTrace.equals(other.fTrace)) { | |
4c564a2d | 172 | return false; |
b9e37ffd FC |
173 | } |
174 | if (fRank != other.fRank) { | |
4c564a2d | 175 | return false; |
b9e37ffd | 176 | } |
ce970a71 | 177 | if (fTimestamp == null) { |
b9e37ffd | 178 | if (other.fTimestamp != null) { |
0c841e0f | 179 | return false; |
b9e37ffd FC |
180 | } |
181 | } else if (!fTimestamp.equals(other.fTimestamp)) { | |
ce970a71 | 182 | return false; |
b9e37ffd | 183 | } |
4c564a2d | 184 | if (fType == null) { |
b9e37ffd | 185 | if (other.fType != null) { |
4c564a2d | 186 | return false; |
b9e37ffd FC |
187 | } |
188 | } else if (!fType.equals(other.fType)) { | |
4c564a2d | 189 | return false; |
b9e37ffd | 190 | } |
4c564a2d | 191 | if (fContent == null) { |
b9e37ffd | 192 | if (other.fContent != null) { |
4c564a2d | 193 | return false; |
b9e37ffd FC |
194 | } |
195 | } else if (!fContent.equals(other.fContent)) { | |
4c564a2d | 196 | return false; |
b9e37ffd | 197 | } |
0c841e0f | 198 | return true; |
cbd4ad82 | 199 | } |
28b94d61 | 200 | |
12c155f5 | 201 | @Override |
3b38ea61 | 202 | @SuppressWarnings("nls") |
12c155f5 | 203 | public String toString() { |
bd54d363 AM |
204 | return getClass().getSimpleName() + " [fTimestamp=" + getTimestamp() |
205 | + ", fTrace=" + getTrace() + ", fRank=" + getRank() | |
e1de2fd4 | 206 | + ", fType=" + getType() + ", fContent=" + getContent() |
bd54d363 | 207 | + "]"; |
12c155f5 | 208 | } |
f9673903 | 209 | |
8c8bf09f | 210 | } |