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 / DomainInfo.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.IDomainInfo;
20
21 /**
22 * <p>
23 * Implementation of the trace domain interface (IDomainInfo) to store domain
24 * related data.
25 * </p>
26 *
27 * @author Bernd Hufmann
28 */
29 public class DomainInfo extends TraceInfo implements IDomainInfo {
30
31 // ------------------------------------------------------------------------
32 // Attributes
33 // ------------------------------------------------------------------------
34 /**
35 * The channels information of the domain.
36 */
37 private final List<IChannelInfo> fChannels = new ArrayList<IChannelInfo>();
38 private boolean fIsKernel = false;
39
40 // ------------------------------------------------------------------------
41 // Constructors
42 // ------------------------------------------------------------------------
43 /**
44 * Constructor
45 * @param name - name of domain
46 */
47 public DomainInfo(String name) {
48 super(name);
49 }
50
51 /**
52 * Copy constructor
53 * @param other - the instance to copy
54 */
55 public DomainInfo(DomainInfo other) {
56 super(other);
57 for (int i = 0; i < other.fChannels.size(); i++) {
58 if (other.fChannels.get(i) instanceof ChannelInfo) {
59 fChannels.add(new ChannelInfo((ChannelInfo)other.fChannels.get(i)));
60 } else {
61 fChannels.add(other.fChannels.get(i));
62 }
63 }
64 fIsKernel = other.fIsKernel;
65 }
66
67 /*
68 * (non-Javadoc)
69 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IDomainInfo#isKernel()
70 */
71 @Override
72 public boolean isKernel() {
73 return fIsKernel;
74 }
75
76 /*
77 * (non-Javadoc)
78 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IDomainInfo#setIsKernel(boolean)
79 */
80 @Override
81 public void setIsKernel(boolean isKernel) {
82 fIsKernel = isKernel;
83 }
84
85 // ------------------------------------------------------------------------
86 // Accessors
87 // ------------------------------------------------------------------------
88 /*
89 * (non-Javadoc)
90 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IDomainInfo#getChannels()
91 */
92 @Override
93 public IChannelInfo[] getChannels() {
94 return fChannels.toArray(new IChannelInfo[fChannels.size()]);
95 }
96
97 /*
98 * (non-Javadoc)
99 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IDomainInfo#setChannels(java.util.List)
100 */
101 @Override
102 public void setChannels(List<IChannelInfo> channels) {
103 fChannels.clear();
104 for (Iterator<IChannelInfo> iterator = channels.iterator(); iterator.hasNext();) {
105 IChannelInfo channelInfo = iterator.next();
106 fChannels.add(channelInfo);
107 }
108 }
109
110 /*
111 * (non-Javadoc)
112 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IDomainInfo#addChannel(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo)
113 */
114 @Override
115 public void addChannel(IChannelInfo channel) {
116 fChannels.add(channel);
117 }
118
119 /*
120 * (non-Javadoc)
121 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#hashCode()
122 */
123 @Override
124 public int hashCode() {
125 final int prime = 31;
126 int result = super.hashCode();
127 result = prime * result + fChannels.hashCode();
128 result = prime * result + (fIsKernel ? 1231 : 1237);
129 return result;
130 }
131
132 /*
133 * (non-Javadoc)
134 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object)
135 */
136 @Override
137 public boolean equals(Object obj) {
138 if (this == obj) {
139 return true;
140 }
141 if (!super.equals(obj)) {
142 return false;
143 }
144 if (getClass() != obj.getClass()) {
145 return false;
146 }
147 DomainInfo other = (DomainInfo) obj;
148 if (!fChannels.equals(other.fChannels)) {
149 return false;
150 }
151 if (fIsKernel != other.fIsKernel) {
152 return false;
153 }
154 return true;
155 }
156
157 /*
158 * (non-Javadoc)
159 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#toString()
160 */
161 @SuppressWarnings("nls")
162 @Override
163 public String toString() {
164 StringBuffer output = new StringBuffer();
165 output.append("[DomainInfo(");
166 output.append(super.toString());
167 output.append(",Channels=");
168 if (fChannels.isEmpty()) {
169 output.append("None");
170 } else {
171 for (Iterator<IChannelInfo> iterator = fChannels.iterator(); iterator.hasNext();) {
172 IChannelInfo channel = iterator.next();
173 output.append(channel.toString());
174 }
175 }
176 output.append(",isKernel=");
177 output.append(String.valueOf(fIsKernel));
178 output.append(")]");
179 return output.toString();
180 }
181
182 }
This page took 0.034187 seconds and 5 git commands to generate.