Update to session creation procedure
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / event / TmfEvent.java
CommitLineData
8c8bf09f 1/*******************************************************************************
bd54d363 2 * Copyright (c) 2009, 2012, 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:
10 * Francois Chouinard - Initial API and implementation
ce970a71 11 * Francois Chouinard - Updated as per TMF Event Model 1.0
bd54d363 12 * Alexandre Montplaisir - Made immutable
8c8bf09f
ASL
13 *******************************************************************************/
14
6c13869b 15package org.eclipse.linuxtools.tmf.core.event;
8c8bf09f 16
9b749023 17import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
6c13869b 18import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
93bfd50a 19import org.eclipse.ui.views.properties.IPropertySource;
2c8610f7 20
8c8bf09f 21/**
4c564a2d 22 * A basic implementation of ITmfEvent.
6256d8ad 23 *
b9e37ffd
FC
24 * @version 1.0
25 * @author Francois Chouinard
6256d8ad 26 *
b9e37ffd
FC
27 * @see ITmfTimestamp
28 * @see ITmfEventType
29 * @see ITmfEventField
30 * @see ITmfTrace
31*/
bd54d363 32public class TmfEvent implements ITmfEvent {
12c155f5 33
cbd4ad82 34 // ------------------------------------------------------------------------
8c8bf09f 35 // Attributes
cbd4ad82 36 // ------------------------------------------------------------------------
8c8bf09f 37
bd54d363
AM
38 private final ITmfTrace fTrace;
39 private final long fRank;
40 private final ITmfTimestamp fTimestamp;
41 private final String fSource;
42 private final ITmfEventType fType;
43 private final ITmfEventField fContent;
44 private final String fReference;
28b94d61 45
cbd4ad82 46 // ------------------------------------------------------------------------
8c8bf09f 47 // Constructors
cbd4ad82 48 // ------------------------------------------------------------------------
8c8bf09f 49
2c8610f7 50 /**
f7703ed6
FC
51 * Default constructor. All fields have their default value (null) and the
52 * event rank is set to TmfContext.UNKNOWN_RANK.
2c8610f7 53 */
ce970a71 54 public TmfEvent() {
9b749023 55 this(null, ITmfContext.UNKNOWN_RANK, null, null, null, null, null);
12c155f5 56 }
1f506a43 57
12c155f5 58 /**
f7703ed6
FC
59 * Standard constructor. The event rank will be set to TmfContext.UNKNOWN_RANK.
60 *
61 * @param trace the parent trace
62 * @param timestamp the event timestamp
63 * @param source the event source
64 * @param type the event type
65 * @param content the event content (payload)
66 * @param reference the event reference
8c8bf09f 67
12c155f5 68 */
6256d8ad 69 public TmfEvent(final ITmfTrace trace, final ITmfTimestamp timestamp, final String source,
f7703ed6 70 final ITmfEventType type, final ITmfEventField content, final String reference)
4c564a2d 71 {
9b749023 72 this(trace, ITmfContext.UNKNOWN_RANK, timestamp, source, type, content, reference);
12c155f5 73 }
8c8bf09f 74
b4d534a0
FC
75 /**
76 * Full constructor
6256d8ad 77 *
b4d534a0
FC
78 * @param trace the parent trace
79 * @param rank the event rank (in the trace)
80 * @param timestamp the event timestamp
81 * @param source the event source
82 * @param type the event type
0d9a6d76 83 * @param content the event content (payload)
b4d534a0
FC
84 * @param reference the event reference
85 */
6256d8ad 86 public TmfEvent(final ITmfTrace trace, final long rank, final ITmfTimestamp timestamp, final String source,
085d898f 87 final ITmfEventType type, final ITmfEventField content, final String reference)
b4d534a0
FC
88 {
89 fTrace = trace;
90 fRank = rank;
91 fTimestamp = timestamp;
92 fSource = source;
93 fType = type;
94 fContent = content;
95 fReference = reference;
96 }
97
12c155f5 98 /**
ce970a71 99 * Copy constructor
6256d8ad 100 *
ce970a71 101 * @param event the original event
12c155f5 102 */
085d898f 103 public TmfEvent(final ITmfEvent event) {
b9e37ffd 104 if (event == null) {
4c564a2d 105 throw new IllegalArgumentException();
b9e37ffd 106 }
72f1e62a
FC
107 fTrace = event.getTrace();
108 fRank = event.getRank();
109 fTimestamp = event.getTimestamp();
110 fSource = event.getSource();
111 fType = event.getType();
112 fContent = event.getContent();
113 fReference = event.getReference();
12c155f5 114 }
8c8bf09f 115
ce970a71 116 // ------------------------------------------------------------------------
117 // ITmfEvent
118 // ------------------------------------------------------------------------
8c8bf09f 119
d7dbf09a 120 @Override
6256d8ad 121 public ITmfTrace getTrace() {
4c564a2d
FC
122 return fTrace;
123 }
124
d7dbf09a 125 @Override
4c564a2d
FC
126 public long getRank() {
127 return fRank;
128 }
129
d7dbf09a 130 @Override
4df4581d 131 public ITmfTimestamp getTimestamp() {
ce970a71 132 return fTimestamp;
12c155f5 133 }
1f506a43 134
d7dbf09a 135 @Override
4c564a2d
FC
136 public String getSource() {
137 return fSource;
138 }
139
d7dbf09a 140 @Override
4c564a2d
FC
141 public ITmfEventType getType() {
142 return fType;
143 }
144
d7dbf09a 145 @Override
4c564a2d
FC
146 public ITmfEventField getContent() {
147 return fContent;
148 }
149
d7dbf09a 150 @Override
4c564a2d
FC
151 public String getReference() {
152 return fReference;
153 }
154
12c155f5 155 // ------------------------------------------------------------------------
cbd4ad82
FC
156 // Object
157 // ------------------------------------------------------------------------
28b94d61 158
12c155f5 159 @Override
cbd4ad82 160 public int hashCode() {
ce970a71 161 final int prime = 31;
4c564a2d
FC
162 int result = 1;
163 result = prime * result + ((fTrace == null) ? 0 : fTrace.hashCode());
164 result = prime * result + (int) (fRank ^ (fRank >>> 32));
ce970a71 165 result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
4c564a2d
FC
166 result = prime * result + ((fSource == null) ? 0 : fSource.hashCode());
167 result = prime * result + ((fType == null) ? 0 : fType.hashCode());
168 result = prime * result + ((fContent == null) ? 0 : fContent.hashCode());
169 result = prime * result + ((fReference == null) ? 0 : fReference.hashCode());
cbd4ad82
FC
170 return result;
171 }
172
173 @Override
085d898f 174 public boolean equals(final Object obj) {
b9e37ffd 175 if (this == obj) {
ce970a71 176 return true;
b9e37ffd
FC
177 }
178 if (obj == null) {
12c155f5 179 return false;
b9e37ffd
FC
180 }
181 if (!(obj instanceof TmfEvent)) {
ce970a71 182 return false;
b9e37ffd 183 }
085d898f 184 final TmfEvent other = (TmfEvent) obj;
4c564a2d 185 if (fTrace == null) {
b9e37ffd 186 if (other.fTrace != null) {
4c564a2d 187 return false;
b9e37ffd
FC
188 }
189 } else if (!fTrace.equals(other.fTrace)) {
4c564a2d 190 return false;
b9e37ffd
FC
191 }
192 if (fRank != other.fRank) {
4c564a2d 193 return false;
b9e37ffd 194 }
ce970a71 195 if (fTimestamp == null) {
b9e37ffd 196 if (other.fTimestamp != null) {
0c841e0f 197 return false;
b9e37ffd
FC
198 }
199 } else if (!fTimestamp.equals(other.fTimestamp)) {
ce970a71 200 return false;
b9e37ffd 201 }
4c564a2d 202 if (fSource == null) {
b9e37ffd 203 if (other.fSource != null) {
4c564a2d 204 return false;
b9e37ffd
FC
205 }
206 } else if (!fSource.equals(other.fSource)) {
4c564a2d 207 return false;
b9e37ffd 208 }
4c564a2d 209 if (fType == null) {
b9e37ffd 210 if (other.fType != null) {
4c564a2d 211 return false;
b9e37ffd
FC
212 }
213 } else if (!fType.equals(other.fType)) {
4c564a2d 214 return false;
b9e37ffd 215 }
4c564a2d 216 if (fContent == null) {
b9e37ffd 217 if (other.fContent != null) {
4c564a2d 218 return false;
b9e37ffd
FC
219 }
220 } else if (!fContent.equals(other.fContent)) {
4c564a2d 221 return false;
b9e37ffd 222 }
4c564a2d 223 if (fReference == null) {
b9e37ffd 224 if (other.fReference != null) {
4c564a2d 225 return false;
b9e37ffd
FC
226 }
227 } else if (!fReference.equals(other.fReference)) {
4c564a2d 228 return false;
b9e37ffd 229 }
0c841e0f 230 return true;
cbd4ad82 231 }
28b94d61 232
12c155f5 233 @Override
3b38ea61 234 @SuppressWarnings("nls")
12c155f5 235 public String toString() {
bd54d363
AM
236 return getClass().getSimpleName() + " [fTimestamp=" + getTimestamp()
237 + ", fTrace=" + getTrace() + ", fRank=" + getRank()
238 + ", fSource=" + getSource() + ", fType=" + getType()
239 + ", fContent=" + getContent() + ", fReference=" + getReference()
240 + "]";
12c155f5 241 }
f9673903 242
93bfd50a
PT
243 /**
244 * @since 2.0
245 */
246 @Override
247 public Object getAdapter(Class adapter) {
248 if (adapter == IPropertySource.class) {
249 return new TmfEventPropertySource(this);
250 }
251 return null;
252 }
8c8bf09f 253}
This page took 0.056352 seconds and 5 git commands to generate.