Merge branch 'master' into TmfEventModel
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / event / TmfDataItem.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>TmfDataItem</u></b>
20 * <p>
21 * A basic implementation of ITmfDataItem.
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 TmfDataItem implements ITmfDataItem {
28
29 // ------------------------------------------------------------------------
30 // Attributes
31 // ------------------------------------------------------------------------
32
33 protected ITmfTrace<? extends TmfDataItem> fTrace;
34 protected long fRank;
35 protected String fSource;
36 protected ITmfEventType fType;
37 protected ITmfEventContent fContent;
38 protected String fReference;
39
40 // ------------------------------------------------------------------------
41 // Constructors
42 // ------------------------------------------------------------------------
43
44 /**
45 * Default constructor
46 */
47 public TmfDataItem() {
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 TmfDataItem(ITmfTrace<? extends TmfDataItem> 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 TmfDataItem(TmfDataItem 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 // ITmfDataItem
89 // ------------------------------------------------------------------------
90
91 /**
92 * @return the parent trace
93 */
94 public ITmfTrace<? extends TmfDataItem> getTrace() {
95 return fTrace;
96 }
97
98 /**
99 * @return the event rank
100 */
101 public long getRank() {
102 return fRank;
103 }
104
105 /**
106 * @return the event source
107 */
108 public String getSource() {
109 return fSource;
110 }
111
112 /**
113 * @return the event type
114 */
115 public ITmfEventType getType() {
116 return fType;
117 }
118
119 /**
120 * @return the event content
121 */
122 public ITmfEventContent getContent() {
123 return fContent;
124 }
125
126 /**
127 * @return the event reference
128 */
129 public String getReference() {
130 return fReference;
131 }
132
133 // ------------------------------------------------------------------------
134 // Convenience setters
135 // ------------------------------------------------------------------------
136
137 /**
138 * @param source the new event source
139 */
140 public void setSource(String source) {
141 fSource = source;
142 }
143
144 /**
145 * @param type the new event type
146 */
147 public void setType(TmfEventType type) {
148 fType = type;
149 }
150
151 /**
152 * @param content the event new content
153 */
154 public void setContent(TmfEventContent content) {
155 fContent = content;
156 }
157
158 /**
159 * @param reference the new event reference
160 */
161 public void setReference(String reference) {
162 fReference = reference;
163 }
164
165 // ------------------------------------------------------------------------
166 // Cloneable
167 // ------------------------------------------------------------------------
168
169 @Override
170 public TmfDataItem clone() {
171 TmfDataItem clone = null;
172 try {
173 clone = (TmfDataItem) super.clone();
174 clone.fTrace = fTrace;
175 clone.fRank = fRank;
176 clone.fSource = fSource;
177 clone.fType = fType != null ? fType.clone() : null;
178 clone.fContent = fContent != null ? fContent.clone() : null;
179 clone.fReference = fReference;
180 } catch (CloneNotSupportedException e) {
181 }
182 return clone;
183 }
184
185 // ------------------------------------------------------------------------
186 // Object
187 // ------------------------------------------------------------------------
188
189 @Override
190 public int hashCode() {
191 final int prime = 31;
192 int result = 1;
193 result = prime * result + ((fContent == null) ? 0 : fContent.hashCode());
194 result = prime * result + (int) (fRank ^ (fRank >>> 32));
195 result = prime * result + ((fReference == null) ? 0 : fReference.hashCode());
196 result = prime * result + ((fSource == null) ? 0 : fSource.hashCode());
197 result = prime * result + ((fTrace == null) ? 0 : fTrace.hashCode());
198 result = prime * result + ((fType == null) ? 0 : fType.hashCode());
199 return result;
200 }
201
202 @Override
203 public boolean equals(Object obj) {
204 if (this == obj)
205 return true;
206 if (obj == null)
207 return false;
208 if (getClass() != obj.getClass())
209 return false;
210 TmfDataItem other = (TmfDataItem) obj;
211 if (fContent == null) {
212 if (other.fContent != null)
213 return false;
214 } else if (!fContent.equals(other.fContent))
215 return false;
216 if (fRank != other.fRank)
217 return false;
218 if (fReference == null) {
219 if (other.fReference != null)
220 return false;
221 } else if (!fReference.equals(other.fReference))
222 return false;
223 if (fSource == null) {
224 if (other.fSource != null)
225 return false;
226 } else if (!fSource.equals(other.fSource))
227 return false;
228 if (fTrace == null) {
229 if (other.fTrace != null)
230 return false;
231 } else if (!fTrace.equals(other.fTrace))
232 return false;
233 if (fType == null) {
234 if (other.fType != null)
235 return false;
236 } else if (!fType.equals(other.fType))
237 return false;
238 return true;
239 }
240
241 @Override
242 @SuppressWarnings("nls")
243 public String toString() {
244 return "TmfDataEvent [fTrace=" + fTrace + ", fRank=" + fRank
245 + ", fSource=" + fSource + ", fType=" + fType + ", fContent="
246 + fContent + ", fReference=" + fReference + "]";
247 }
248
249 }
This page took 0.035023 seconds and 5 git commands to generate.