Remove UI dependencies in tmf.core.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / event / TmfEvent.java
CommitLineData
8c8bf09f 1/*******************************************************************************
61759503 2 * Copyright (c) 2009, 2013 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:
080600d9
MAL
10 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Updated as per TMF Event Model 1.0
12 * Alexandre Montplaisir - Made immutable
8c8bf09f
ASL
13 *******************************************************************************/
14
6c13869b 15package org.eclipse.linuxtools.tmf.core.event;
8c8bf09f 16
080600d9 17import org.eclipse.core.runtime.PlatformObject;
3bd46eef 18import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
9b749023 19import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
6c13869b 20import org.eclipse.linuxtools.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 */
33public 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 /**
f7703ed6
FC
52 * Default constructor. All fields have their default value (null) and the
53 * event rank is set to TmfContext.UNKNOWN_RANK.
2c8610f7 54 */
ce970a71 55 public TmfEvent() {
9b749023 56 this(null, ITmfContext.UNKNOWN_RANK, null, null, null, null, null);
12c155f5 57 }
1f506a43 58
12c155f5 59 /**
f7703ed6
FC
60 * Standard constructor. The event rank will be set to TmfContext.UNKNOWN_RANK.
61 *
62 * @param trace the parent trace
63 * @param timestamp the event timestamp
64 * @param source the event source
65 * @param type the event type
66 * @param content the event content (payload)
67 * @param reference the event reference
3bd46eef 68 * @since 2.0
8c8bf09f 69
12c155f5 70 */
6256d8ad 71 public TmfEvent(final ITmfTrace trace, final ITmfTimestamp timestamp, final String source,
f7703ed6 72 final ITmfEventType type, final ITmfEventField content, final String reference)
4c564a2d 73 {
9b749023 74 this(trace, ITmfContext.UNKNOWN_RANK, timestamp, source, type, content, reference);
12c155f5 75 }
8c8bf09f 76
b4d534a0
FC
77 /**
78 * Full constructor
6256d8ad 79 *
b4d534a0
FC
80 * @param trace the parent trace
81 * @param rank the event rank (in the trace)
82 * @param timestamp the event timestamp
83 * @param source the event source
84 * @param type the event type
0d9a6d76 85 * @param content the event content (payload)
b4d534a0 86 * @param reference the event reference
3bd46eef 87 * @since 2.0
b4d534a0 88 */
6256d8ad 89 public TmfEvent(final ITmfTrace trace, final long rank, final ITmfTimestamp timestamp, final String source,
085d898f 90 final ITmfEventType type, final ITmfEventField content, final String reference)
b4d534a0
FC
91 {
92 fTrace = trace;
93 fRank = rank;
94 fTimestamp = timestamp;
95 fSource = source;
96 fType = type;
97 fContent = content;
98 fReference = reference;
99 }
100
12c155f5 101 /**
ce970a71 102 * Copy constructor
6256d8ad 103 *
ce970a71 104 * @param event the original event
12c155f5 105 */
085d898f 106 public TmfEvent(final ITmfEvent event) {
b9e37ffd 107 if (event == null) {
4c564a2d 108 throw new IllegalArgumentException();
b9e37ffd 109 }
72f1e62a
FC
110 fTrace = event.getTrace();
111 fRank = event.getRank();
112 fTimestamp = event.getTimestamp();
113 fSource = event.getSource();
114 fType = event.getType();
115 fContent = event.getContent();
116 fReference = event.getReference();
12c155f5 117 }
8c8bf09f 118
ce970a71 119 // ------------------------------------------------------------------------
120 // ITmfEvent
121 // ------------------------------------------------------------------------
8c8bf09f 122
d7dbf09a 123 @Override
6256d8ad 124 public ITmfTrace getTrace() {
4c564a2d
FC
125 return fTrace;
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}
This page took 0.060427 seconds and 5 git commands to generate.