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
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.lttng.ui.views.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.lttng.ui.views.control.model.IChannelInfo;
19 import 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 */
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
38 // ------------------------------------------------------------------------
39 // Constructors
40 // ------------------------------------------------------------------------
41 /**
42 * Constructor
43 * @param name - name of domain
44 */
45 public DomainInfo(String name) {
46 super(name);
47 }
48
49 /**
50 * Copy constructor
51 * @param other - the instance to copy
52 */
53 public DomainInfo(DomainInfo other) {
54 super(other);
55 for (int i = 0; i < other.fChannels.size(); i++) {
56 if (other.fChannels.get(i) instanceof ChannelInfo) {
57 fChannels.add(new ChannelInfo((ChannelInfo)other.fChannels.get(i)));
58 } else {
59 fChannels.add(other.fChannels.get(i));
60 }
61 }
62 }
63
64 // ------------------------------------------------------------------------
65 // Accessors
66 // ------------------------------------------------------------------------
67 /*
68 * (non-Javadoc)
69 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo#getChannels()
70 */
71 @Override
72 public IChannelInfo[] getChannels() {
73 return fChannels.toArray(new IChannelInfo[fChannels.size()]);
74 }
75
76 /*
77 * (non-Javadoc)
78 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo#setChannels(java.util.List)
79 */
80 @Override
81 public void setChannels(List<IChannelInfo> channels) {
82 for (Iterator<IChannelInfo> iterator = channels.iterator(); iterator.hasNext();) {
83 IChannelInfo channelInfo = (IChannelInfo) iterator.next();
84 fChannels.add(channelInfo);
85 }
86 }
87
88 /*
89 * (non-Javadoc)
90 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo#addChannel(org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo)
91 */
92 @Override
93 public void addChannel(IChannelInfo channel) {
94 fChannels.add(channel);
95 }
96
97 /*
98 * (non-Javadoc)
99 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#hashCode()
100 */
101 @Override
102 public int hashCode() {
103 int result = 17;
104 result = 37 * result + super.hashCode();
105 for (Iterator<IChannelInfo> iterator = fChannels.iterator(); iterator.hasNext();) {
106 IChannelInfo channel = (IChannelInfo) iterator.next();
107 result = 37 * result + channel.hashCode();
108 }
109 return result;
110 }
111
112 /*
113 * (non-Javadoc)
114 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object)
115 */
116 @Override
117 public boolean equals(Object other) {
118 if (!(other instanceof DomainInfo)) {
119 return false;
120 }
121
122 DomainInfo otherInfo = (DomainInfo) other;
123 if (!super.equals(otherInfo)) {
124 return false;
125 }
126
127 if (fChannels.size() != otherInfo.fChannels.size()) {
128 return false;
129 }
130 for (int i = 0; i < fChannels.size(); i++) {
131 if (!fChannels.get(i).equals(otherInfo.fChannels.get(i))) {
132 return false;
133 }
134 }
135 return true;
136 }
137
138 /*
139 * (non-Javadoc)
140 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#toString()
141 */
142 @SuppressWarnings("nls")
143 @Override
144 public String toString() {
145 StringBuffer output = new StringBuffer();
146 output.append("[DomainInfo(");
147 output.append(super.toString());
148 output.append(",Channels=");
149 if (fChannels.isEmpty()) {
150 output.append("None");
151 } else {
152 for (Iterator<IChannelInfo> iterator = fChannels.iterator(); iterator.hasNext();) {
153 IChannelInfo channel = (IChannelInfo) iterator.next();
154 output.append(channel.toString());
155 }
156 }
157 output.append(")]");
158 return output.toString();
159 }
160 }
This page took 0.034154 seconds and 6 git commands to generate.