lttng: Add clear() call before add elements to list
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.core / src / org / eclipse / linuxtools / internal / lttng2 / core / control / model / impl / ChannelInfo.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org.eclipse.linuxtools.internal.lttng2.core.control.model.impl;
13
14 import java.util.ArrayList;
15 import java.util.Iterator;
16 import java.util.List;
17
18 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo;
19 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IEventInfo;
20 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement;
21
22 /**
23 * <p>
24 * Implementation of the trace channel interface (IChannelInfo) to store channel
25 * related data.
26 * </p>
27 *
28 * @author Bernd Hufmann
29 */
30 public class ChannelInfo extends TraceInfo implements IChannelInfo {
31
32 // ------------------------------------------------------------------------
33 // Attributes
34 // ------------------------------------------------------------------------
35 /**
36 * The overwrite mode of the channel.
37 */
38 private boolean fOverwriteMode;
39 /**
40 * The sub-buffer size of the channel.
41 */
42 private long fSubBufferSize;
43 /**
44 * The number of sub-buffers of the channel.
45 */
46 private int fNumberOfSubBuffers;
47 /**
48 * The switch timer interval of the channel.
49 */
50 private long fSwitchTimer;
51 /**
52 * The read timer interval of the channel.
53 */
54 private long fReadTimer;
55 /**
56 * The Output type of the channel.
57 */
58 private String fOutputType = ""; //$NON-NLS-1$
59 /**
60 * The channel enable state.
61 */
62 private TraceEnablement fState = TraceEnablement.DISABLED;
63 /**
64 * The events information of the channel.
65 */
66 private final List<IEventInfo> fEvents = new ArrayList<IEventInfo>();
67
68
69 // ------------------------------------------------------------------------
70 // Constructors
71 // ------------------------------------------------------------------------
72 /**
73 * Constructor
74 * @param name - name channel
75 */
76 public ChannelInfo(String name) {
77 super(name);
78 }
79
80 /**
81 * Copy constructor
82 * @param other - the instance to copy
83 */
84 public ChannelInfo(ChannelInfo other) {
85 super(other);
86 fOverwriteMode = other.fOverwriteMode;
87 fSubBufferSize = other.fSubBufferSize;
88 fNumberOfSubBuffers = other.fNumberOfSubBuffers;
89 fSwitchTimer = other.fSwitchTimer;
90 fReadTimer = other.fReadTimer;
91 fOutputType = (other.fOutputType == null ? null : String.valueOf(other.fOutputType));
92 fState = other.fState;
93 for (Iterator<IEventInfo> iterator = other.fEvents.iterator(); iterator.hasNext();) {
94 IEventInfo event = iterator.next();
95 if (event instanceof EventInfo) {
96 fEvents.add(new EventInfo((EventInfo)event));
97 } else {
98 fEvents.add(event);
99 }
100 }
101 }
102
103 // ------------------------------------------------------------------------
104 // Accessors
105 // ------------------------------------------------------------------------
106 /*
107 * (non-Javadoc)
108 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getOverwriteMode()
109 */
110 @Override
111 public boolean isOverwriteMode() {
112 return fOverwriteMode;
113 }
114
115 /*
116 * (non-Javadoc)
117 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setOverwriteMode(boolean)
118 */
119 @Override
120 public void setOverwriteMode(boolean mode) {
121 fOverwriteMode = mode;
122 }
123
124 /*
125 * (non-Javadoc)
126 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getSubBufferSize()
127 */
128 @Override
129 public long getSubBufferSize() {
130 return fSubBufferSize;
131 }
132
133 /*
134 * (non-Javadoc)
135 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setSubBufferSize(long)
136 */
137 @Override
138 public void setSubBufferSize(long bufferSize) {
139 fSubBufferSize = bufferSize;
140
141 }
142
143 /*
144 * (non-Javadoc)
145 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getNumberOfSubBuffers()
146 */
147 @Override
148 public int getNumberOfSubBuffers() {
149 return fNumberOfSubBuffers;
150 }
151
152 /*
153 * (non-Javadoc)
154 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setNumberOfSubBuffers(int)
155 */
156 @Override
157 public void setNumberOfSubBuffers(int numberOfSubBuffers) {
158 fNumberOfSubBuffers = numberOfSubBuffers;
159 }
160
161 /*
162 * (non-Javadoc)
163 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getSwitchTimer()
164 */
165 @Override
166 public long getSwitchTimer() {
167 return fSwitchTimer;
168 }
169
170 /*
171 * (non-Javadoc)
172 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setSwitchTimer(long)
173 */
174 @Override
175 public void setSwitchTimer(long timer) {
176 fSwitchTimer = timer;
177 }
178
179 /*
180 * (non-Javadoc)
181 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getReadTimer()
182 */
183 @Override
184 public long getReadTimer() {
185 return fReadTimer;
186 }
187
188 /*
189 * (non-Javadoc)
190 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setReadTimer(long)
191 */
192 @Override
193 public void setReadTimer(long timer) {
194 fReadTimer = timer;
195 }
196
197 /*
198 * (non-Javadoc)
199 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getOutputType()
200 */
201 @Override
202 public String getOutputType() {
203 return fOutputType;
204 }
205
206 /*
207 * (non-Javadoc)
208 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setOutputType(java.lang.String)
209 */
210 @Override
211 public void setOutputType(String type) {
212 fOutputType = type;
213 }
214
215 /*
216 * (non-Javadoc)
217 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getState()
218 */
219 @Override
220 public TraceEnablement getState() {
221 return fState;
222 }
223
224 /*
225 * (non-Javadoc)
226 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setState(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceEnablement)
227 */
228 @Override
229 public void setState(TraceEnablement state) {
230 fState = state;
231 }
232
233 /*
234 * (non-Javadoc)
235 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setState(java.lang.String)
236 */
237 @Override
238 public void setState(String stateName) {
239 fState = TraceEnablement.ENABLED;
240 if (TraceEnablement.DISABLED.getInName().equals(stateName)) {
241 fState = TraceEnablement.DISABLED;
242 } else if (TraceEnablement.ENABLED.getInName().equals(stateName)) {
243 fState = TraceEnablement.ENABLED;
244 }
245 }
246
247 /*
248 * (non-Javadoc)
249 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getEvents()
250 */
251 @Override
252 public IEventInfo[] getEvents() {
253 return fEvents.toArray(new IEventInfo[fEvents.size()]);
254 }
255
256 /*
257 * (non-Javadoc)
258 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setEvents(java.util.List)
259 */
260 @Override
261 public void setEvents(List<IEventInfo> events) {
262 fEvents.clear();
263 for (Iterator<IEventInfo> iterator = events.iterator(); iterator.hasNext();) {
264 IEventInfo eventInfo = iterator.next();
265 fEvents.add(eventInfo);
266 }
267 }
268
269 /*
270 * (non-Javadoc)
271 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#addEvent(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IEventInfo)
272 */
273 @Override
274 public void addEvent(IEventInfo channel) {
275 fEvents.add(channel);
276 }
277
278 /*
279 * (non-Javadoc)
280 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#hashCode()
281 */
282 @Override
283 public int hashCode() {
284 final int prime = 31;
285 int result = super.hashCode();
286 result = prime * result + fEvents.hashCode();
287 result = prime * result + fNumberOfSubBuffers;
288 result = prime * result + ((fOutputType == null) ? 0 : fOutputType.hashCode());
289 result = prime * result + (fOverwriteMode ? 1231 : 1237);
290 result = prime * result + (int) (fReadTimer ^ (fReadTimer >>> 32));
291 result = prime * result + ((fState == null) ? 0 : (fState.ordinal() + 1));
292 result = prime * result + (int) (fSubBufferSize ^ (fSubBufferSize >>> 32));
293 result = prime * result + (int) (fSwitchTimer ^ (fSwitchTimer >>> 32));
294 return result;
295 }
296
297 /*
298 * (non-Javadoc)
299 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object)
300 */
301 @Override
302 public boolean equals(Object obj) {
303 if (this == obj) {
304 return true;
305 }
306 if (!super.equals(obj)) {
307 return false;
308 }
309 if (getClass() != obj.getClass()) {
310 return false;
311 }
312 ChannelInfo other = (ChannelInfo) obj;
313 if (!fEvents.equals(other.fEvents)) {
314 return false;
315 }
316 if (fNumberOfSubBuffers != other.fNumberOfSubBuffers) {
317 return false;
318 }
319 if (fOutputType == null) {
320 if (other.fOutputType != null) {
321 return false;
322 }
323 } else if (!fOutputType.equals(other.fOutputType)) {
324 return false;
325 }
326 if (fOverwriteMode != other.fOverwriteMode) {
327 return false;
328 }
329 if (fReadTimer != other.fReadTimer) {
330 return false;
331 }
332 if (fState != other.fState) {
333 return false;
334 }
335 if (fSubBufferSize != other.fSubBufferSize) {
336 return false;
337 }
338 if (fSwitchTimer != other.fSwitchTimer) {
339 return false;
340 }
341 return true;
342 }
343
344 /*
345 * (non-Javadoc)
346 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#toString()
347 */
348 @SuppressWarnings("nls")
349 @Override
350 public String toString() {
351 StringBuffer output = new StringBuffer();
352 output.append("[ChannelInfo(");
353 output.append(super.toString());
354 output.append(",State=");
355 output.append(fState);
356 output.append(",OverwriteMode=");
357 output.append(fOverwriteMode);
358 output.append(",SubBuffersSize=");
359 output.append(fSubBufferSize);
360 output.append(",NumberOfSubBuffers=");
361 output.append(fNumberOfSubBuffers);
362 output.append(",SwitchTimer=");
363 output.append(fSwitchTimer);
364 output.append(",ReadTimer=");
365 output.append(fReadTimer);
366 output.append(",output=");
367 output.append(fOutputType);
368 output.append(",Events=");
369 if (fEvents.isEmpty()) {
370 output.append("None");
371 } else {
372 for (Iterator<IEventInfo> iterator = fEvents.iterator(); iterator.hasNext();) {
373 IEventInfo event = iterator.next();
374 output.append(event.toString());
375 }
376 }
377 output.append(")]");
378 return output.toString();
379 }
380
381
382 }
This page took 0.039702 seconds and 5 git commands to generate.