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