Commit | Line | Data |
---|---|---|
ce970a71 | 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 | /** | |
60ab19fe | 19 | * <b><u>TmfDataItem</u></b> |
ce970a71 | 20 | * <p> |
60ab19fe | 21 | * A basic implementation of ITmfDataItem. |
ce970a71 | 22 | * |
23 | * Notice that for performance reasons TmfDataEvent is NOT immutable. If a copy | |
5179fc01 FC |
24 | * of an event is needed, use the copy constructor (shallow copy) or the clone() |
25 | * method (deep copy). | |
ce970a71 | 26 | */ |
60ab19fe | 27 | public class TmfDataItem implements ITmfDataItem { |
ce970a71 | 28 | |
29 | // ------------------------------------------------------------------------ | |
30 | // Attributes | |
31 | // ------------------------------------------------------------------------ | |
32 | ||
60ab19fe | 33 | protected ITmfTrace<? extends TmfDataItem> fTrace; |
ce970a71 | 34 | protected long fRank; |
99005796 | 35 | protected String fSource; |
5d3e8747 | 36 | protected ITmfEventType fType; |
37 | protected ITmfEventContent fContent; | |
4641c2f7 | 38 | protected String fReference; |
ce970a71 | 39 | |
40 | // ------------------------------------------------------------------------ | |
41 | // Constructors | |
42 | // ------------------------------------------------------------------------ | |
43 | ||
44 | /** | |
45 | * Default constructor | |
46 | */ | |
60ab19fe | 47 | public TmfDataItem() { |
ce970a71 | 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 | */ | |
60ab19fe | 59 | public TmfDataItem(ITmfTrace<? extends TmfDataItem> trace, long rank, |
99005796 | 60 | String source, TmfEventType type, TmfEventContent content, |
4641c2f7 | 61 | String reference) |
ce970a71 | 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 | */ | |
60ab19fe | 76 | public TmfDataItem(TmfDataItem event) { |
ce970a71 | 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 | // ------------------------------------------------------------------------ | |
60ab19fe | 88 | // ITmfDataItem |
ce970a71 | 89 | // ------------------------------------------------------------------------ |
90 | ||
91 | /** | |
92 | * @return the parent trace | |
93 | */ | |
60ab19fe | 94 | public ITmfTrace<? extends TmfDataItem> getTrace() { |
ce970a71 | 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 | */ | |
99005796 | 108 | public String getSource() { |
ce970a71 | 109 | return fSource; |
110 | } | |
111 | ||
112 | /** | |
113 | * @return the event type | |
114 | */ | |
5d3e8747 | 115 | public ITmfEventType getType() { |
ce970a71 | 116 | return fType; |
117 | } | |
118 | ||
ce970a71 | 119 | /** |
120 | * @return the event content | |
121 | */ | |
5d3e8747 | 122 | public ITmfEventContent getContent() { |
ce970a71 | 123 | return fContent; |
124 | } | |
125 | ||
126 | /** | |
127 | * @return the event reference | |
128 | */ | |
4641c2f7 | 129 | public String getReference() { |
ce970a71 | 130 | return fReference; |
131 | } | |
132 | ||
21412413 | 133 | // ------------------------------------------------------------------------ |
134 | // Convenience setters | |
135 | // ------------------------------------------------------------------------ | |
136 | ||
137 | /** | |
138 | * @param source the new event source | |
139 | */ | |
bbc1c411 | 140 | public void setSource(String source) { |
21412413 | 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 | ||
ce970a71 | 165 | // ------------------------------------------------------------------------ |
166 | // Cloneable | |
167 | // ------------------------------------------------------------------------ | |
168 | ||
169 | @Override | |
60ab19fe FC |
170 | public TmfDataItem clone() { |
171 | TmfDataItem clone = null; | |
ce970a71 | 172 | try { |
60ab19fe | 173 | clone = (TmfDataItem) super.clone(); |
ce970a71 | 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; | |
60ab19fe | 210 | TmfDataItem other = (TmfDataItem) obj; |
ce970a71 | 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() { | |
5179fc01 FC |
244 | return "TmfDataEvent [fTrace=" + fTrace + ", fRank=" + fRank |
245 | + ", fSource=" + fSource + ", fType=" + fType + ", fContent=" | |
ce970a71 | 246 | + fContent + ", fReference=" + fReference + "]"; |
247 | } | |
248 | ||
249 | } |