Merge branch 'master' into lttng_2_0_control_dev
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / control / model / impl / DomainInfo.java
CommitLineData
eb1bab5b
BH
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 **********************************************************************/
12package org.eclipse.linuxtools.lttng.ui.views.control.model.impl;
13
14import java.util.ArrayList;
15import java.util.Iterator;
16import java.util.List;
17
18import org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo;
19import org.eclipse.linuxtools.lttng.ui.views.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 */
28public 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>();
bbb3538a 37 private boolean fIsKernel = false;
eb1bab5b
BH
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 }
bbb3538a
BH
63 fIsKernel = other.fIsKernel;
64 }
65
66 /*
67 * (non-Javadoc)
68 * @see org.eclipse.linuxtools.lttng.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.lttng.ui.views.control.model.IDomainInfo#setIsKernel(boolean)
78 */
79 @Override
80 public void setIsKernel(boolean isKernel) {
81 fIsKernel = isKernel;
eb1bab5b
BH
82 }
83
84 // ------------------------------------------------------------------------
85 // Accessors
86 // ------------------------------------------------------------------------
87 /*
88 * (non-Javadoc)
89 * @see org.eclipse.linuxtools.lttng.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.lttng.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.lttng.ui.views.control.model.IDomainInfo#addChannel(org.eclipse.linuxtools.lttng.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.lttng.ui.views.control.model.impl.TraceInfo#hashCode()
120 */
121 @Override
122 public int hashCode() {
123 int result = 17;
124 result = 37 * result + super.hashCode();
125 for (Iterator<IChannelInfo> iterator = fChannels.iterator(); iterator.hasNext();) {
126 IChannelInfo channel = (IChannelInfo) iterator.next();
127 result = 37 * result + channel.hashCode();
128 }
bbb3538a 129 result += 37 * result + (fIsKernel ? 1 : 0);
eb1bab5b
BH
130 return result;
131 }
132
133 /*
134 * (non-Javadoc)
135 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object)
136 */
137 @Override
138 public boolean equals(Object other) {
139 if (!(other instanceof DomainInfo)) {
140 return false;
141 }
142
143 DomainInfo otherInfo = (DomainInfo) other;
144 if (!super.equals(otherInfo)) {
145 return false;
146 }
147
148 if (fChannels.size() != otherInfo.fChannels.size()) {
149 return false;
150 }
151 for (int i = 0; i < fChannels.size(); i++) {
152 if (!fChannels.get(i).equals(otherInfo.fChannels.get(i))) {
153 return false;
154 }
155 }
bbb3538a
BH
156
157 if (fIsKernel != otherInfo.fIsKernel) {
158 return false;
159 }
eb1bab5b
BH
160 return true;
161 }
162
163 /*
164 * (non-Javadoc)
165 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#toString()
166 */
167 @SuppressWarnings("nls")
168 @Override
169 public String toString() {
170 StringBuffer output = new StringBuffer();
171 output.append("[DomainInfo(");
172 output.append(super.toString());
173 output.append(",Channels=");
174 if (fChannels.isEmpty()) {
175 output.append("None");
176 } else {
177 for (Iterator<IChannelInfo> iterator = fChannels.iterator(); iterator.hasNext();) {
178 IChannelInfo channel = (IChannelInfo) iterator.next();
179 output.append(channel.toString());
180 }
181 }
bbb3538a
BH
182 output.append(",isKernel=");
183 output.append(String.valueOf(fIsKernel));
eb1bab5b
BH
184 output.append(")]");
185 return output.toString();
186 }
187}
This page took 0.032401 seconds and 5 git commands to generate.