1 /*******************************************************************************
2 * Copyright (c) 2009, 2015 Ericsson
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
10 * Francois Chouinard - Initial API and implementation, updated as per TMF Event Model 1.0
11 * Alexandre Montplaisir - Made immutable, consolidated constructors
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.core
.event
;
16 import org
.eclipse
.core
.runtime
.PlatformObject
;
17 import org
.eclipse
.jdt
.annotation
.NonNull
;
18 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
25 * A basic implementation of ITmfEvent.
27 * @author Francois Chouinard
34 public class TmfEvent
extends PlatformObject
implements ITmfEvent
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
40 private final ITmfTrace fTrace
;
41 private final long fRank
;
42 private final @NonNull ITmfTimestamp fTimestamp
;
43 private final ITmfEventType fType
;
44 private final ITmfEventField fContent
;
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
51 * Default constructor. Is required for extension points, but should not be
54 * @deprecated Do not use, extension-point use only. Use
55 * {@link #TmfEvent(ITmfTrace, long, ITmfTimestamp, ITmfEventType, ITmfEventField)}
60 this(null, ITmfContext
.UNKNOWN_RANK
, null, null, null);
69 * the event rank (in the trace). You can use
70 * {@link ITmfContext#UNKNOWN_RANK} as default value
76 * the event content (payload)
78 public TmfEvent(final ITmfTrace trace
,
80 final ITmfTimestamp timestamp
,
81 final ITmfEventType type
,
82 final ITmfEventField content
) {
85 if (timestamp
!= null) {
86 fTimestamp
= timestamp
;
88 fTimestamp
= TmfTimestamp
.ZERO
;
97 * @param event the original event
99 public TmfEvent(final @NonNull ITmfEvent event
) {
100 fTrace
= event
.getTrace();
101 fRank
= event
.getRank();
102 fTimestamp
= event
.getTimestamp();
103 fType
= event
.getType();
104 fContent
= event
.getContent();
107 // ------------------------------------------------------------------------
109 // ------------------------------------------------------------------------
112 public ITmfTrace
getTrace() {
113 ITmfTrace trace
= fTrace
;
115 throw new IllegalStateException("Null traces are only allowed on special kind of events and getTrace() should not be called on them"); //$NON-NLS-1$
121 public long getRank() {
126 public ITmfTimestamp
getTimestamp() {
131 public ITmfEventType
getType() {
136 public ITmfEventField
getContent() {
144 public String
getName() {
145 ITmfEventType type
= getType();
147 return type
.getName();
149 return ""; //$NON-NLS-1$
152 // ------------------------------------------------------------------------
154 // ------------------------------------------------------------------------
157 public int hashCode() {
158 final int prime
= 31;
160 result
= prime
* result
+ ((fTrace
== null) ?
0 : getTrace().hashCode());
161 result
= prime
* result
+ (int) (getRank() ^
(getRank() >>> 32));
162 result
= prime
* result
+ getTimestamp().hashCode();
163 result
= prime
* result
+ ((getType() == null) ?
0 : getType().hashCode());
164 result
= prime
* result
+ ((getContent() == null) ?
0 : getContent().hashCode());
169 public boolean equals(final Object obj
) {
177 /* Two events must be of the exact same class to be equal */
178 if (!(this.getClass().equals(obj
.getClass()))) {
181 final TmfEvent other
= (TmfEvent
) obj
;
183 if (fTrace
== null) {
184 if (other
.fTrace
!= null) {
187 } else if (!getTrace().equals(other
.getTrace())) {
191 if (getRank() != other
.getRank()) {
194 if (!getTimestamp().equals(other
.getTimestamp())) {
197 if (!NonNullUtils
.equalsNullable(getType(), other
.getType())) {
200 if (!NonNullUtils
.equalsNullable(getContent(), other
.getContent())) {
207 @SuppressWarnings("nls")
208 public String
toString() {
209 return getClass().getSimpleName() + " [fTimestamp=" + getTimestamp()
210 + ", fTrace=" + getTrace() + ", fRank=" + getRank()
211 + ", fType=" + getType() + ", fContent=" + getContent()
This page took 0.041776 seconds and 5 git commands to generate.