Commit | Line | Data |
---|---|---|
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 | **********************************************************************/ | |
31a6a4e4 | 12 | package org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl; |
eb1bab5b BH |
13 | |
14 | import java.util.ArrayList; | |
15 | import java.util.Iterator; | |
16 | import java.util.List; | |
17 | ||
31a6a4e4 BH |
18 | import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo; |
19 | import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IDomainInfo; | |
eb1bab5b BH |
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>(); | |
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) | |
31a6a4e4 | 68 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IDomainInfo#isKernel() |
bbb3538a BH |
69 | */ |
70 | @Override | |
71 | public boolean isKernel() { | |
72 | return fIsKernel; | |
73 | } | |
74 | ||
75 | /* | |
76 | * (non-Javadoc) | |
31a6a4e4 | 77 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IDomainInfo#setIsKernel(boolean) |
bbb3538a BH |
78 | */ |
79 | @Override | |
80 | public void setIsKernel(boolean isKernel) { | |
81 | fIsKernel = isKernel; | |
eb1bab5b BH |
82 | } |
83 | ||
84 | // ------------------------------------------------------------------------ | |
85 | // Accessors | |
86 | // ------------------------------------------------------------------------ | |
87 | /* | |
88 | * (non-Javadoc) | |
31a6a4e4 | 89 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IDomainInfo#getChannels() |
eb1bab5b BH |
90 | */ |
91 | @Override | |
92 | public IChannelInfo[] getChannels() { | |
93 | return fChannels.toArray(new IChannelInfo[fChannels.size()]); | |
94 | } | |
95 | ||
96 | /* | |
97 | * (non-Javadoc) | |
31a6a4e4 | 98 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IDomainInfo#setChannels(java.util.List) |
eb1bab5b BH |
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) | |
31a6a4e4 | 110 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IDomainInfo#addChannel(org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo) |
eb1bab5b BH |
111 | */ |
112 | @Override | |
113 | public void addChannel(IChannelInfo channel) { | |
114 | fChannels.add(channel); | |
115 | } | |
116 | ||
d132bcc7 BH |
117 | /* |
118 | * (non-Javadoc) | |
31a6a4e4 | 119 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.ITraceInfo#formatString() |
d132bcc7 BH |
120 | */ |
121 | @SuppressWarnings("nls") | |
122 | @Override | |
123 | public String formatString() { | |
124 | StringBuffer output = new StringBuffer(); | |
125 | //=== Domain: Kernel === | |
126 | output.append("\n=== Domain: "); | |
127 | output.append(getName()); | |
128 | output.append(" ===\n"); | |
129 | output.append("\n"); | |
130 | // Channels: | |
131 | output.append("Channels:\n"); | |
132 | // ------------- | |
133 | output.append("-------------"); | |
134 | if (fChannels.isEmpty()) { | |
135 | output.append("\nNone"); | |
136 | } else { | |
137 | for (Iterator<IChannelInfo> iterator = fChannels.iterator(); iterator.hasNext();) { | |
138 | IChannelInfo channel = (IChannelInfo) iterator.next(); | |
139 | output.append(channel.formatString()); | |
140 | } | |
141 | } | |
142 | output.append("\n"); | |
143 | return output.toString(); | |
144 | } | |
145 | ||
eb1bab5b BH |
146 | /* |
147 | * (non-Javadoc) | |
31a6a4e4 | 148 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl.TraceInfo#hashCode() |
eb1bab5b BH |
149 | */ |
150 | @Override | |
151 | public int hashCode() { | |
d132bcc7 BH |
152 | final int prime = 31; |
153 | int result = super.hashCode(); | |
154 | result = prime * result + ((fChannels == null) ? 0 : fChannels.hashCode()); | |
155 | result = prime * result + (fIsKernel ? 1231 : 1237); | |
eb1bab5b BH |
156 | return result; |
157 | } | |
158 | ||
159 | /* | |
160 | * (non-Javadoc) | |
31a6a4e4 | 161 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object) |
eb1bab5b BH |
162 | */ |
163 | @Override | |
d132bcc7 BH |
164 | public boolean equals(Object obj) { |
165 | if (this == obj) { | |
166 | return true; | |
eb1bab5b | 167 | } |
d132bcc7 | 168 | if (!super.equals(obj)) { |
eb1bab5b BH |
169 | return false; |
170 | } | |
d132bcc7 | 171 | if (getClass() != obj.getClass()) { |
eb1bab5b BH |
172 | return false; |
173 | } | |
d132bcc7 BH |
174 | DomainInfo other = (DomainInfo) obj; |
175 | if (fChannels == null) { | |
176 | if (other.fChannels != null) { | |
eb1bab5b BH |
177 | return false; |
178 | } | |
d132bcc7 BH |
179 | } else if (!fChannels.equals(other.fChannels)) { |
180 | return false; | |
eb1bab5b | 181 | } |
d132bcc7 | 182 | if (fIsKernel != other.fIsKernel) { |
bbb3538a BH |
183 | return false; |
184 | } | |
eb1bab5b BH |
185 | return true; |
186 | } | |
d132bcc7 | 187 | |
eb1bab5b BH |
188 | /* |
189 | * (non-Javadoc) | |
31a6a4e4 | 190 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl.TraceInfo#toString() |
eb1bab5b BH |
191 | */ |
192 | @SuppressWarnings("nls") | |
193 | @Override | |
194 | public String toString() { | |
195 | StringBuffer output = new StringBuffer(); | |
196 | output.append("[DomainInfo("); | |
197 | output.append(super.toString()); | |
198 | output.append(",Channels="); | |
199 | if (fChannels.isEmpty()) { | |
200 | output.append("None"); | |
201 | } else { | |
202 | for (Iterator<IChannelInfo> iterator = fChannels.iterator(); iterator.hasNext();) { | |
203 | IChannelInfo channel = (IChannelInfo) iterator.next(); | |
204 | output.append(channel.toString()); | |
205 | } | |
206 | } | |
bbb3538a BH |
207 | output.append(",isKernel="); |
208 | output.append(String.valueOf(fIsKernel)); | |
eb1bab5b BH |
209 | output.append(")]"); |
210 | return output.toString(); | |
211 | } | |
d132bcc7 | 212 | |
eb1bab5b | 213 | } |