TMF: Make the ITmfEvent#getTimestamp() return NonNull
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / event / TmfEvent.java
CommitLineData
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 14package org.eclipse.tracecompass.tmf.core.event;
8c8bf09f 15
080600d9 16import org.eclipse.core.runtime.PlatformObject;
ca5b04ad 17import org.eclipse.jdt.annotation.NonNull;
2bdf0193 18import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
cbf0057c 19import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
2bdf0193
AM
20import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
21import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
2c8610f7 22
8c8bf09f 23/**
4c564a2d 24 * A basic implementation of ITmfEvent.
6256d8ad 25 *
b9e37ffd
FC
26 * @version 1.0
27 * @author Francois Chouinard
6256d8ad 28 *
b9e37ffd
FC
29 * @see ITmfTimestamp
30 * @see ITmfEventType
31 * @see ITmfEventField
32 * @see ITmfTrace
080600d9
MAL
33 */
34public 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)
3bd46eef 77 * @since 2.0
b4d534a0 78 */
0c7471fb
AM
79 public TmfEvent(final ITmfTrace trace,
80 final long rank,
81 final ITmfTimestamp timestamp,
0c7471fb 82 final ITmfEventType type,
e1de2fd4 83 final ITmfEventField content) {
b4d534a0
FC
84 fTrace = trace;
85 fRank = rank;
cbf0057c
GB
86 if (timestamp != null) {
87 fTimestamp = timestamp;
88 } else {
89 fTimestamp = TmfTimestamp.ZERO;
90 }
b4d534a0
FC
91 fType = type;
92 fContent = content;
b4d534a0
FC
93 }
94
12c155f5 95 /**
ce970a71 96 * Copy constructor
6256d8ad 97 *
ce970a71 98 * @param event the original event
12c155f5 99 */
ca5b04ad 100 public TmfEvent(final @NonNull ITmfEvent event) {
72f1e62a
FC
101 fTrace = event.getTrace();
102 fRank = event.getRank();
103 fTimestamp = event.getTimestamp();
72f1e62a
FC
104 fType = event.getType();
105 fContent = event.getContent();
12c155f5 106 }
8c8bf09f 107
ce970a71 108 // ------------------------------------------------------------------------
109 // ITmfEvent
110 // ------------------------------------------------------------------------
8c8bf09f 111
d7dbf09a 112 @Override
6256d8ad 113 public ITmfTrace getTrace() {
ca5b04ad
GB
114 ITmfTrace trace = fTrace;
115 if (trace == null) {
116 throw new IllegalStateException("Null traces are only allowed on special kind of events and getTrace() should not be called on them"); //$NON-NLS-1$
117 }
118 return trace;
4c564a2d
FC
119 }
120
d7dbf09a 121 @Override
4c564a2d
FC
122 public long getRank() {
123 return fRank;
124 }
125
3bd46eef
AM
126 /**
127 * @since 2.0
128 */
d7dbf09a 129 @Override
4df4581d 130 public ITmfTimestamp getTimestamp() {
ce970a71 131 return fTimestamp;
12c155f5 132 }
1f506a43 133
d7dbf09a 134 @Override
4c564a2d
FC
135 public ITmfEventType getType() {
136 return fType;
137 }
138
d7dbf09a 139 @Override
4c564a2d
FC
140 public ITmfEventField getContent() {
141 return fContent;
142 }
143
12c155f5 144 // ------------------------------------------------------------------------
cbd4ad82
FC
145 // Object
146 // ------------------------------------------------------------------------
28b94d61 147
12c155f5 148 @Override
cbd4ad82 149 public int hashCode() {
ce970a71 150 final int prime = 31;
4c564a2d
FC
151 int result = 1;
152 result = prime * result + ((fTrace == null) ? 0 : fTrace.hashCode());
153 result = prime * result + (int) (fRank ^ (fRank >>> 32));
cbf0057c 154 result = prime * result + fTimestamp.hashCode();
4c564a2d
FC
155 result = prime * result + ((fType == null) ? 0 : fType.hashCode());
156 result = prime * result + ((fContent == null) ? 0 : fContent.hashCode());
cbd4ad82
FC
157 return result;
158 }
159
160 @Override
085d898f 161 public boolean equals(final Object obj) {
b9e37ffd 162 if (this == obj) {
ce970a71 163 return true;
b9e37ffd
FC
164 }
165 if (obj == null) {
12c155f5 166 return false;
b9e37ffd
FC
167 }
168 if (!(obj instanceof TmfEvent)) {
ce970a71 169 return false;
b9e37ffd 170 }
085d898f 171 final TmfEvent other = (TmfEvent) obj;
4c564a2d 172 if (fTrace == null) {
b9e37ffd 173 if (other.fTrace != null) {
4c564a2d 174 return false;
b9e37ffd
FC
175 }
176 } else if (!fTrace.equals(other.fTrace)) {
4c564a2d 177 return false;
b9e37ffd
FC
178 }
179 if (fRank != other.fRank) {
4c564a2d 180 return false;
b9e37ffd 181 }
cbf0057c 182 if (!fTimestamp.equals(other.fTimestamp)) {
ce970a71 183 return false;
b9e37ffd 184 }
4c564a2d 185 if (fType == null) {
b9e37ffd 186 if (other.fType != null) {
4c564a2d 187 return false;
b9e37ffd
FC
188 }
189 } else if (!fType.equals(other.fType)) {
4c564a2d 190 return false;
b9e37ffd 191 }
4c564a2d 192 if (fContent == null) {
b9e37ffd 193 if (other.fContent != null) {
4c564a2d 194 return false;
b9e37ffd
FC
195 }
196 } else if (!fContent.equals(other.fContent)) {
4c564a2d 197 return false;
b9e37ffd 198 }
0c841e0f 199 return true;
cbd4ad82 200 }
28b94d61 201
12c155f5 202 @Override
3b38ea61 203 @SuppressWarnings("nls")
12c155f5 204 public String toString() {
bd54d363
AM
205 return getClass().getSimpleName() + " [fTimestamp=" + getTimestamp()
206 + ", fTrace=" + getTrace() + ", fRank=" + getRank()
e1de2fd4 207 + ", fType=" + getType() + ", fContent=" + getContent()
bd54d363 208 + "]";
12c155f5 209 }
f9673903 210
8c8bf09f 211}
This page took 0.089037 seconds and 5 git commands to generate.