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 | **********************************************************************/ | |
9315aeee | 12 | package org.eclipse.linuxtools.internal.lttng2.core.control.model.impl; |
eb1bab5b BH |
13 | |
14 | import java.util.ArrayList; | |
15 | import java.util.Iterator; | |
16 | import java.util.List; | |
17 | ||
9315aeee BH |
18 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo; |
19 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IDomainInfo; | |
eb1bab5b BH |
20 | |
21 | /** | |
eb1bab5b BH |
22 | * <p> |
23 | * Implementation of the trace domain interface (IDomainInfo) to store domain | |
24 | * related data. | |
25 | * </p> | |
dbd4432d BH |
26 | * |
27 | * @author Bernd Hufmann | |
eb1bab5b BH |
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 List<IChannelInfo> fChannels = new ArrayList<IChannelInfo>(); | |
bbb3538a | 38 | private boolean fIsKernel = false; |
eb1bab5b BH |
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 | } | |
bbb3538a BH |
64 | fIsKernel = other.fIsKernel; |
65 | } | |
66 | ||
67 | /* | |
68 | * (non-Javadoc) | |
115b4a01 | 69 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IDomainInfo#isKernel() |
bbb3538a BH |
70 | */ |
71 | @Override | |
72 | public boolean isKernel() { | |
73 | return fIsKernel; | |
74 | } | |
75 | ||
76 | /* | |
77 | * (non-Javadoc) | |
115b4a01 | 78 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IDomainInfo#setIsKernel(boolean) |
bbb3538a BH |
79 | */ |
80 | @Override | |
81 | public void setIsKernel(boolean isKernel) { | |
82 | fIsKernel = isKernel; | |
eb1bab5b BH |
83 | } |
84 | ||
85 | // ------------------------------------------------------------------------ | |
86 | // Accessors | |
87 | // ------------------------------------------------------------------------ | |
88 | /* | |
89 | * (non-Javadoc) | |
115b4a01 | 90 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IDomainInfo#getChannels() |
eb1bab5b BH |
91 | */ |
92 | @Override | |
93 | public IChannelInfo[] getChannels() { | |
94 | return fChannels.toArray(new IChannelInfo[fChannels.size()]); | |
95 | } | |
96 | ||
97 | /* | |
98 | * (non-Javadoc) | |
115b4a01 | 99 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IDomainInfo#setChannels(java.util.List) |
eb1bab5b BH |
100 | */ |
101 | @Override | |
102 | public void setChannels(List<IChannelInfo> channels) { | |
103 | for (Iterator<IChannelInfo> iterator = channels.iterator(); iterator.hasNext();) { | |
104 | IChannelInfo channelInfo = (IChannelInfo) iterator.next(); | |
105 | fChannels.add(channelInfo); | |
106 | } | |
107 | } | |
108 | ||
109 | /* | |
110 | * (non-Javadoc) | |
115b4a01 | 111 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IDomainInfo#addChannel(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo) |
eb1bab5b BH |
112 | */ |
113 | @Override | |
114 | public void addChannel(IChannelInfo channel) { | |
115 | fChannels.add(channel); | |
116 | } | |
117 | ||
118 | /* | |
119 | * (non-Javadoc) | |
115b4a01 | 120 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#hashCode() |
eb1bab5b BH |
121 | */ |
122 | @Override | |
123 | public int hashCode() { | |
d132bcc7 BH |
124 | final int prime = 31; |
125 | int result = super.hashCode(); | |
126 | result = prime * result + ((fChannels == null) ? 0 : fChannels.hashCode()); | |
127 | result = prime * result + (fIsKernel ? 1231 : 1237); | |
eb1bab5b BH |
128 | return result; |
129 | } | |
130 | ||
131 | /* | |
132 | * (non-Javadoc) | |
115b4a01 | 133 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object) |
eb1bab5b BH |
134 | */ |
135 | @Override | |
d132bcc7 BH |
136 | public boolean equals(Object obj) { |
137 | if (this == obj) { | |
138 | return true; | |
eb1bab5b | 139 | } |
d132bcc7 | 140 | if (!super.equals(obj)) { |
eb1bab5b BH |
141 | return false; |
142 | } | |
d132bcc7 | 143 | if (getClass() != obj.getClass()) { |
eb1bab5b BH |
144 | return false; |
145 | } | |
d132bcc7 BH |
146 | DomainInfo other = (DomainInfo) obj; |
147 | if (fChannels == null) { | |
148 | if (other.fChannels != null) { | |
eb1bab5b BH |
149 | return false; |
150 | } | |
d132bcc7 BH |
151 | } else if (!fChannels.equals(other.fChannels)) { |
152 | return false; | |
eb1bab5b | 153 | } |
d132bcc7 | 154 | if (fIsKernel != other.fIsKernel) { |
bbb3538a BH |
155 | return false; |
156 | } | |
eb1bab5b BH |
157 | return true; |
158 | } | |
d132bcc7 | 159 | |
eb1bab5b BH |
160 | /* |
161 | * (non-Javadoc) | |
115b4a01 | 162 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#toString() |
eb1bab5b BH |
163 | */ |
164 | @SuppressWarnings("nls") | |
165 | @Override | |
166 | public String toString() { | |
167 | StringBuffer output = new StringBuffer(); | |
168 | output.append("[DomainInfo("); | |
169 | output.append(super.toString()); | |
170 | output.append(",Channels="); | |
171 | if (fChannels.isEmpty()) { | |
172 | output.append("None"); | |
173 | } else { | |
174 | for (Iterator<IChannelInfo> iterator = fChannels.iterator(); iterator.hasNext();) { | |
175 | IChannelInfo channel = (IChannelInfo) iterator.next(); | |
176 | output.append(channel.toString()); | |
177 | } | |
178 | } | |
bbb3538a BH |
179 | output.append(",isKernel="); |
180 | output.append(String.valueOf(fIsKernel)); | |
eb1bab5b BH |
181 | output.append(")]"); |
182 | return output.toString(); | |
183 | } | |
d132bcc7 | 184 | |
eb1bab5b | 185 | } |