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
CommitLineData
eb1bab5b 1/**********************************************************************
94cce698 2 * Copyright (c) 2012, 2013 Ericsson
b0318660 3 *
eb1bab5b
BH
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
b0318660
AM
8 *
9 * Contributors:
eb1bab5b
BH
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
9315aeee 12package org.eclipse.linuxtools.internal.lttng2.core.control.model.impl;
eb1bab5b
BH
13
14import java.util.ArrayList;
15import java.util.Iterator;
16import java.util.List;
17
9315aeee
BH
18import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo;
19import org.eclipse.linuxtools.internal.lttng2.core.control.model.IEventInfo;
20import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement;
eb1bab5b
BH
21
22/**
eb1bab5b
BH
23 * <p>
24 * Implementation of the trace channel interface (IChannelInfo) to store channel
b0318660 25 * related data.
eb1bab5b 26 * </p>
b0318660 27 *
dbd4432d 28 * @author Bernd Hufmann
eb1bab5b
BH
29 */
30public 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 */
b0318660
AM
66 private final List<IEventInfo> fEvents = new ArrayList<IEventInfo>();
67
eb1bab5b 68
eb1bab5b
BH
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)
115b4a01 108 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getOverwriteMode()
eb1bab5b
BH
109 */
110 @Override
111 public boolean isOverwriteMode() {
112 return fOverwriteMode;
113 }
114
115 /*
116 * (non-Javadoc)
115b4a01 117 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setOverwriteMode(boolean)
eb1bab5b
BH
118 */
119 @Override
120 public void setOverwriteMode(boolean mode) {
121 fOverwriteMode = mode;
122 }
123
124 /*
125 * (non-Javadoc)
115b4a01 126 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getSubBufferSize()
eb1bab5b
BH
127 */
128 @Override
129 public long getSubBufferSize() {
130 return fSubBufferSize;
131 }
132
133 /*
134 * (non-Javadoc)
115b4a01 135 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setSubBufferSize(long)
eb1bab5b
BH
136 */
137 @Override
138 public void setSubBufferSize(long bufferSize) {
139 fSubBufferSize = bufferSize;
140
141 }
142
143 /*
144 * (non-Javadoc)
115b4a01 145 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getNumberOfSubBuffers()
eb1bab5b
BH
146 */
147 @Override
148 public int getNumberOfSubBuffers() {
149 return fNumberOfSubBuffers;
150 }
151
152 /*
153 * (non-Javadoc)
115b4a01 154 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setNumberOfSubBuffers(int)
eb1bab5b
BH
155 */
156 @Override
157 public void setNumberOfSubBuffers(int numberOfSubBuffers) {
158 fNumberOfSubBuffers = numberOfSubBuffers;
159 }
160
161 /*
162 * (non-Javadoc)
115b4a01 163 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getSwitchTimer()
eb1bab5b
BH
164 */
165 @Override
166 public long getSwitchTimer() {
167 return fSwitchTimer;
168 }
169
170 /*
171 * (non-Javadoc)
115b4a01 172 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setSwitchTimer(long)
eb1bab5b
BH
173 */
174 @Override
175 public void setSwitchTimer(long timer) {
176 fSwitchTimer = timer;
177 }
178
179 /*
180 * (non-Javadoc)
115b4a01 181 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getReadTimer()
eb1bab5b
BH
182 */
183 @Override
184 public long getReadTimer() {
185 return fReadTimer;
186 }
187
188 /*
189 * (non-Javadoc)
115b4a01 190 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setReadTimer(long)
eb1bab5b
BH
191 */
192 @Override
193 public void setReadTimer(long timer) {
194 fReadTimer = timer;
195 }
196
197 /*
198 * (non-Javadoc)
115b4a01 199 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getOutputType()
eb1bab5b
BH
200 */
201 @Override
202 public String getOutputType() {
203 return fOutputType;
204 }
205
206 /*
207 * (non-Javadoc)
115b4a01 208 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setOutputType(java.lang.String)
eb1bab5b
BH
209 */
210 @Override
211 public void setOutputType(String type) {
212 fOutputType = type;
213 }
214
215 /*
216 * (non-Javadoc)
115b4a01 217 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getState()
eb1bab5b
BH
218 */
219 @Override
220 public TraceEnablement getState() {
221 return fState;
222 }
223
224 /*
225 * (non-Javadoc)
115b4a01 226 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setState(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceEnablement)
eb1bab5b
BH
227 */
228 @Override
229 public void setState(TraceEnablement state) {
230 fState = state;
231 }
b0318660 232
eb1bab5b
BH
233 /*
234 * (non-Javadoc)
115b4a01 235 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setState(java.lang.String)
eb1bab5b
BH
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 }
b0318660 246
eb1bab5b
BH
247 /*
248 * (non-Javadoc)
115b4a01 249 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getEvents()
eb1bab5b
BH
250 */
251 @Override
252 public IEventInfo[] getEvents() {
253 return fEvents.toArray(new IEventInfo[fEvents.size()]);
254 }
255
256 /*
257 * (non-Javadoc)
115b4a01 258 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setEvents(java.util.List)
eb1bab5b
BH
259 */
260 @Override
261 public void setEvents(List<IEventInfo> events) {
a6702bfa 262 fEvents.clear();
eb1bab5b 263 for (Iterator<IEventInfo> iterator = events.iterator(); iterator.hasNext();) {
b0318660 264 IEventInfo eventInfo = iterator.next();
eb1bab5b
BH
265 fEvents.add(eventInfo);
266 }
267 }
268
269 /*
270 * (non-Javadoc)
115b4a01 271 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#addEvent(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IEventInfo)
eb1bab5b
BH
272 */
273 @Override
274 public void addEvent(IEventInfo channel) {
275 fEvents.add(channel);
276 }
b0318660 277
eb1bab5b
BH
278 /*
279 * (non-Javadoc)
115b4a01 280 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#hashCode()
eb1bab5b
BH
281 */
282 @Override
283 public int hashCode() {
d132bcc7
BH
284 final int prime = 31;
285 int result = super.hashCode();
77fdc5df 286 result = prime * result + fEvents.hashCode();
d132bcc7
BH
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));
eb1bab5b 294 return result;
b0318660 295 }
eb1bab5b
BH
296
297 /*
298 * (non-Javadoc)
115b4a01 299 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object)
eb1bab5b
BH
300 */
301 @Override
d132bcc7
BH
302 public boolean equals(Object obj) {
303 if (this == obj) {
304 return true;
eb1bab5b 305 }
d132bcc7 306 if (!super.equals(obj)) {
eb1bab5b
BH
307 return false;
308 }
d132bcc7 309 if (getClass() != obj.getClass()) {
eb1bab5b
BH
310 return false;
311 }
d132bcc7 312 ChannelInfo other = (ChannelInfo) obj;
77fdc5df 313 if (!fEvents.equals(other.fEvents)) {
eb1bab5b
BH
314 return false;
315 }
d132bcc7 316 if (fNumberOfSubBuffers != other.fNumberOfSubBuffers) {
eb1bab5b
BH
317 return false;
318 }
d132bcc7
BH
319 if (fOutputType == null) {
320 if (other.fOutputType != null) {
321 return false;
322 }
323 } else if (!fOutputType.equals(other.fOutputType)) {
eb1bab5b
BH
324 return false;
325 }
d132bcc7 326 if (fOverwriteMode != other.fOverwriteMode) {
eb1bab5b
BH
327 return false;
328 }
d132bcc7 329 if (fReadTimer != other.fReadTimer) {
eb1bab5b
BH
330 return false;
331 }
d132bcc7 332 if (fState != other.fState) {
eb1bab5b
BH
333 return false;
334 }
d132bcc7 335 if (fSubBufferSize != other.fSubBufferSize) {
eb1bab5b
BH
336 return false;
337 }
d132bcc7
BH
338 if (fSwitchTimer != other.fSwitchTimer) {
339 return false;
eb1bab5b
BH
340 }
341 return true;
342 }
b0318660 343
eb1bab5b
BH
344 /*
345 * (non-Javadoc)
115b4a01 346 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#toString()
eb1bab5b
BH
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();) {
b0318660 373 IEventInfo event = iterator.next();
eb1bab5b
BH
374 output.append(event.toString());
375 }
376 }
377 output.append(")]");
378 return output.toString();
379 }
d132bcc7
BH
380
381
a6702bfa 382}
This page took 0.053089 seconds and 5 git commands to generate.