Merge branch 'master' into TmfEventModel
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / event / TmfEvent.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2012 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
11 * Francois Chouinard - Updated as per TMF Event Model 1.0
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.event;
15
16 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
17
18 /**
19 * <b><u>TmfEvent</u></b>
20 * <p>
21 * The basic event structure in the TMF. In its canonical form, an event has:
22 * <ul>
23 * <li>a normalized timestamp
24 * <li>a source (reporter)
25 * <li>a type
26 * <li>a content
27 * </ul>
28 * For convenience, a free-form reference field is also provided. It could be
29 * used as e.g. a location marker in the event stream to distinguish between
30 * otherwise identical events.
31 *
32 * Notice that for performance reasons TmfEvent is NOT immutable. If a copy of
33 * the event is needed, use the copy constructor.
34 */
35 public class TmfEvent extends TmfDataItem implements ITmfEvent {
36
37 // ------------------------------------------------------------------------
38 // Attributes
39 // ------------------------------------------------------------------------
40
41 protected ITmfTimestamp fTimestamp;
42
43 // ------------------------------------------------------------------------
44 // Constructors
45 // ------------------------------------------------------------------------
46
47 /**
48 * Default constructor
49 */
50 public TmfEvent() {
51 }
52
53 /**
54 * Full constructor
55 *
56 * @param trace the parent trace
57 * @param rank the vent rank (in the trace)
58 * @param timestamp the event timestamp
59 * @param source the event source
60 * @param type the event type
61 * @param reference the event reference
62 */
63 public TmfEvent(ITmfTrace<?> trace, long rank, ITmfTimestamp timestamp, String source,
64 TmfEventType type, String reference)
65 {
66 super(trace, rank, source, type, null, reference);
67 fTimestamp = timestamp;
68 }
69
70 /**
71 * Constructor - no rank
72 */
73 public TmfEvent(ITmfTrace<?> parentTrace, ITmfTimestamp timestamp, String source,
74 TmfEventType type, String reference)
75 {
76 this(parentTrace, -1, timestamp, source, type, reference);
77 }
78
79 /**
80 * Constructor - no trace, no rank
81 */
82 public TmfEvent(ITmfTimestamp timestamp, String source, TmfEventType type, String reference) {
83 this(null, -1, timestamp, source, type, reference);
84 }
85
86 /**
87 * Copy constructor
88 *
89 * @param event the original event
90 */
91 public TmfEvent(TmfEvent event) {
92 super(event);
93 fTimestamp = event.fTimestamp != null ? event.fTimestamp.clone() : null;
94 }
95
96 // ------------------------------------------------------------------------
97 // ITmfEvent
98 // ------------------------------------------------------------------------
99
100 /**
101 * @return the effective event timestamp
102 */
103 public ITmfTimestamp getTimestamp() {
104 return fTimestamp;
105 }
106
107 // ------------------------------------------------------------------------
108 // Cloneable
109 // ------------------------------------------------------------------------
110
111 @Override
112 public TmfEvent clone() {
113 TmfEvent clone = null;
114 clone = (TmfEvent) super.clone();
115 clone.fTimestamp = fTimestamp != null ? fTimestamp.clone() : null;
116 return clone;
117 }
118
119 // ------------------------------------------------------------------------
120 // Object
121 // ------------------------------------------------------------------------
122
123 @Override
124 public int hashCode() {
125 final int prime = 31;
126 int result = super.hashCode();
127 result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
128 return result;
129 }
130
131 @Override
132 public boolean equals(Object obj) {
133 if (this == obj)
134 return true;
135 if (!super.equals(obj))
136 return false;
137 if (getClass() != obj.getClass())
138 return false;
139 TmfEvent other = (TmfEvent) obj;
140 if (fTimestamp == null) {
141 if (other.fTimestamp != null)
142 return false;
143 } else if (!fTimestamp.equals(other.fTimestamp))
144 return false;
145 return true;
146 }
147
148 @Override
149 @SuppressWarnings("nls")
150 public String toString() {
151 return "TmfEvent [fTimestamp=" + fTimestamp + ", fTrace=" + fTrace + ", fRank=" + fRank
152 + ", fSource=" + fSource + ", fType=" + fType + ", fContent=" + fContent
153 + ", fReference=" + fReference + "]";
154 }
155
156 }
This page took 0.03822 seconds and 6 git commands to generate.