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