Refactor TmfTimestamp as per the updated TMF Event Model
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / event / TmfDataEvent.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2012 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made 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>TmfDataEvent</u></b>
20 * <p>
21 * A basic implementation of ITmfDataEvent.
22 *
23 * Notice that for performance reasons TmfDataEvent is NOT immutable. If a copy
24 * of an event is needed, use the copy constructor (shallow copy) or the clone()
25 * method (deep copy).
26 */
27 public class TmfDataEvent implements Cloneable {
28
29 // ------------------------------------------------------------------------
30 // Attributes
31 // ------------------------------------------------------------------------
32
33 protected ITmfTrace<? extends TmfDataEvent> fTrace;
34 protected long fRank;
35 protected String fSource;
36 protected TmfEventType fType;
37 protected TmfEventContent fContent;
38 protected String fReference;
39
40 // ------------------------------------------------------------------------
41 // Constructors
42 // ------------------------------------------------------------------------
43
44 /**
45 * Default constructor
46 */
47 public TmfDataEvent() {
48 }
49
50 /**
51 * Full constructor
52 *
53 * @param trace the parent trace
54 * @param rank the vent rank (in the trace)
55 * @param source the event source
56 * @param type the event type
57 * @param reference the event reference
58 */
59 public TmfDataEvent(ITmfTrace<? extends TmfDataEvent> trace, long rank,
60 String source, TmfEventType type, TmfEventContent content,
61 String reference)
62 {
63 fTrace = trace;
64 fRank = rank;
65 fSource = source;
66 fType = type;
67 fContent = content;
68 fReference = reference;
69 }
70
71 /**
72 * Copy constructor
73 *
74 * @param event the original event
75 */
76 public TmfDataEvent(TmfDataEvent event) {
77 if (event == null)
78 throw new IllegalArgumentException();
79 fTrace = event.fTrace;
80 fRank = event.fRank;
81 fSource = event.fSource;
82 fType = event.fType;
83 fContent = event.fContent;
84 fReference = event.fReference;
85 }
86
87 // ------------------------------------------------------------------------
88 // ITmfDataEvent + Setters
89 // ------------------------------------------------------------------------
90
91 /**
92 * @return the parent trace
93 */
94 public ITmfTrace<? extends TmfDataEvent> getTrace() {
95 return fTrace;
96 }
97
98 /**
99 * @return the event rank
100 */
101 public long getRank() {
102 return fRank;
103 }
104
105 /**
106 * @param source the event source
107 */
108 public void setSource(String source) {
109 fSource = source;
110 }
111
112 /**
113 * @return the event source
114 */
115 public String getSource() {
116 return fSource;
117 }
118
119 /**
120 * @return the event type
121 */
122 public TmfEventType getType() {
123 return fType;
124 }
125
126 /**
127 * @param content the event new content
128 */
129 public void setContent(TmfEventContent content) {
130 fContent = content;
131 }
132
133 /**
134 * @return the event content
135 */
136 public TmfEventContent getContent() {
137 return fContent;
138 }
139
140 /**
141 * @return the event reference
142 */
143 public String getReference() {
144 return fReference;
145 }
146
147 // ------------------------------------------------------------------------
148 // Cloneable
149 // ------------------------------------------------------------------------
150
151 @Override
152 public TmfDataEvent clone() {
153 TmfDataEvent clone = null;
154 try {
155 clone = (TmfDataEvent) super.clone();
156 clone.fTrace = fTrace;
157 clone.fRank = fRank;
158 clone.fSource = fSource;
159 clone.fType = fType != null ? fType.clone() : null;
160 clone.fContent = fContent != null ? fContent.clone() : null;
161 clone.fReference = fReference;
162 } catch (CloneNotSupportedException e) {
163 }
164 return clone;
165 }
166
167 // ------------------------------------------------------------------------
168 // Object
169 // ------------------------------------------------------------------------
170
171 @Override
172 public int hashCode() {
173 final int prime = 31;
174 int result = 1;
175 result = prime * result + ((fContent == null) ? 0 : fContent.hashCode());
176 result = prime * result + (int) (fRank ^ (fRank >>> 32));
177 result = prime * result + ((fReference == null) ? 0 : fReference.hashCode());
178 result = prime * result + ((fSource == null) ? 0 : fSource.hashCode());
179 result = prime * result + ((fTrace == null) ? 0 : fTrace.hashCode());
180 result = prime * result + ((fType == null) ? 0 : fType.hashCode());
181 return result;
182 }
183
184 @Override
185 public boolean equals(Object obj) {
186 if (this == obj)
187 return true;
188 if (obj == null)
189 return false;
190 if (getClass() != obj.getClass())
191 return false;
192 TmfDataEvent other = (TmfDataEvent) obj;
193 if (fContent == null) {
194 if (other.fContent != null)
195 return false;
196 } else if (!fContent.equals(other.fContent))
197 return false;
198 if (fRank != other.fRank)
199 return false;
200 if (fReference == null) {
201 if (other.fReference != null)
202 return false;
203 } else if (!fReference.equals(other.fReference))
204 return false;
205 if (fSource == null) {
206 if (other.fSource != null)
207 return false;
208 } else if (!fSource.equals(other.fSource))
209 return false;
210 if (fTrace == null) {
211 if (other.fTrace != null)
212 return false;
213 } else if (!fTrace.equals(other.fTrace))
214 return false;
215 if (fType == null) {
216 if (other.fType != null)
217 return false;
218 } else if (!fType.equals(other.fType))
219 return false;
220 return true;
221 }
222
223 @Override
224 @SuppressWarnings("nls")
225 public String toString() {
226 return "TmfDataEvent [fTrace=" + fTrace + ", fRank=" + fRank
227 + ", fSource=" + fSource + ", fType=" + fType + ", fContent="
228 + fContent + ", fReference=" + fReference + "]";
229 }
230
231 }
This page took 0.063924 seconds and 5 git commands to generate.