tmf: Remove source and reference from ITmfEvent
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / event / TmfEvent.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2014 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.trace.ITmfContext;
20 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
21
22 /**
23 * A basic implementation of ITmfEvent.
24 *
25 * @version 1.0
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 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 * @since 2.0
77 */
78 public TmfEvent(final ITmfTrace trace,
79 final long rank,
80 final ITmfTimestamp timestamp,
81 final ITmfEventType type,
82 final ITmfEventField content) {
83 fTrace = trace;
84 fRank = rank;
85 fTimestamp = timestamp;
86 fType = type;
87 fContent = content;
88 }
89
90 /**
91 * Copy constructor
92 *
93 * @param event the original event
94 */
95 public TmfEvent(final @NonNull ITmfEvent event) {
96 fTrace = event.getTrace();
97 fRank = event.getRank();
98 fTimestamp = event.getTimestamp();
99 fType = event.getType();
100 fContent = event.getContent();
101 }
102
103 // ------------------------------------------------------------------------
104 // ITmfEvent
105 // ------------------------------------------------------------------------
106
107 @Override
108 public ITmfTrace getTrace() {
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;
114 }
115
116 @Override
117 public long getRank() {
118 return fRank;
119 }
120
121 /**
122 * @since 2.0
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 // Object
141 // ------------------------------------------------------------------------
142
143 @Override
144 public int hashCode() {
145 final int prime = 31;
146 int result = 1;
147 result = prime * result + ((fTrace == null) ? 0 : fTrace.hashCode());
148 result = prime * result + (int) (fRank ^ (fRank >>> 32));
149 result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
150 result = prime * result + ((fType == null) ? 0 : fType.hashCode());
151 result = prime * result + ((fContent == null) ? 0 : fContent.hashCode());
152 return result;
153 }
154
155 @Override
156 public boolean equals(final Object obj) {
157 if (this == obj) {
158 return true;
159 }
160 if (obj == null) {
161 return false;
162 }
163 if (!(obj instanceof TmfEvent)) {
164 return false;
165 }
166 final TmfEvent other = (TmfEvent) obj;
167 if (fTrace == null) {
168 if (other.fTrace != null) {
169 return false;
170 }
171 } else if (!fTrace.equals(other.fTrace)) {
172 return false;
173 }
174 if (fRank != other.fRank) {
175 return false;
176 }
177 if (fTimestamp == null) {
178 if (other.fTimestamp != null) {
179 return false;
180 }
181 } else if (!fTimestamp.equals(other.fTimestamp)) {
182 return false;
183 }
184 if (fType == null) {
185 if (other.fType != null) {
186 return false;
187 }
188 } else if (!fType.equals(other.fType)) {
189 return false;
190 }
191 if (fContent == null) {
192 if (other.fContent != null) {
193 return false;
194 }
195 } else if (!fContent.equals(other.fContent)) {
196 return false;
197 }
198 return true;
199 }
200
201 @Override
202 @SuppressWarnings("nls")
203 public String toString() {
204 return getClass().getSimpleName() + " [fTimestamp=" + getTimestamp()
205 + ", fTrace=" + getTrace() + ", fRank=" + getRank()
206 + ", fType=" + getType() + ", fContent=" + getContent()
207 + "]";
208 }
209
210 }
This page took 0.03607 seconds and 5 git commands to generate.