0c2feaa20fb74826de337d7991bdb43048ab98b7
[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 for (Iterator<IChannelInfo> iterator = channels.iterator(); iterator.hasNext();) {
104 IChannelInfo channelInfo = iterator.next();
105 fChannels.add(channelInfo);
106 }
107 }
108
109 /*
110 * (non-Javadoc)
111 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IDomainInfo#addChannel(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo)
112 */
113 @Override
114 public void addChannel(IChannelInfo channel) {
115 fChannels.add(channel);
116 }
117
118 /*
119 * (non-Javadoc)
120 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#hashCode()
121 */
122 @Override
123 public int hashCode() {
124 final int prime = 31;
125 int result = super.hashCode();
126 result = prime * result + fChannels.hashCode();
127 result = prime * result + (fIsKernel ? 1231 : 1237);
128 return result;
129 }
130
131 /*
132 * (non-Javadoc)
133 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object)
134 */
135 @Override
136 public boolean equals(Object obj) {
137 if (this == obj) {
138 return true;
139 }
140 if (!super.equals(obj)) {
141 return false;
142 }
143 if (getClass() != obj.getClass()) {
144 return false;
145 }
146 DomainInfo other = (DomainInfo) obj;
147 if (!fChannels.equals(other.fChannels)) {
148 return false;
149 }
150 if (fIsKernel != other.fIsKernel) {
151 return false;
152 }
153 return true;
154 }
155
156 /*
157 * (non-Javadoc)
158 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#toString()
159 */
160 @SuppressWarnings("nls")
161 @Override
162 public String toString() {
163 StringBuffer output = new StringBuffer();
164 output.append("[DomainInfo(");
165 output.append(super.toString());
166 output.append(",Channels=");
167 if (fChannels.isEmpty()) {
168 output.append("None");
169 } else {
170 for (Iterator<IChannelInfo> iterator = fChannels.iterator(); iterator.hasNext();) {
171 IChannelInfo channel = iterator.next();
172 output.append(channel.toString());
173 }
174 }
175 output.append(",isKernel=");
176 output.append(String.valueOf(fIsKernel));
177 output.append(")]");
178 return output.toString();
179 }
180
181 }
This page took 0.03448 seconds and 4 git commands to generate.