gdbtrace: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.core / src / org / eclipse / linuxtools / internal / lttng2 / control / core / model / impl / DomainInfo.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2014 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.control.core.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.control.core.model.IChannelInfo;
19 import org.eclipse.linuxtools.internal.lttng2.control.core.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<>();
38 private boolean fIsKernel = false;
39 private BufferType fBufferType = BufferType.BUFFER_TYPE_UNKNOWN;
40
41 // ------------------------------------------------------------------------
42 // Constructors
43 // ------------------------------------------------------------------------
44 /**
45 * Constructor
46 * @param name - name of domain
47 */
48 public DomainInfo(String name) {
49 super(name);
50 }
51
52 /**
53 * Copy constructor
54 * @param other - the instance to copy
55 */
56 public DomainInfo(DomainInfo other) {
57 super(other);
58 for (int i = 0; i < other.fChannels.size(); i++) {
59 if (other.fChannels.get(i) instanceof ChannelInfo) {
60 fChannels.add(new ChannelInfo((ChannelInfo)other.fChannels.get(i)));
61 } else {
62 fChannels.add(other.fChannels.get(i));
63 }
64 }
65 fIsKernel = other.fIsKernel;
66 fBufferType = other.fBufferType;
67 }
68
69 @Override
70 public boolean isKernel() {
71 return fIsKernel;
72 }
73
74 @Override
75 public void setIsKernel(boolean isKernel) {
76 fIsKernel = isKernel;
77 }
78
79 // ------------------------------------------------------------------------
80 // Accessors
81 // ------------------------------------------------------------------------
82
83 @Override
84 public IChannelInfo[] getChannels() {
85 return fChannels.toArray(new IChannelInfo[fChannels.size()]);
86 }
87
88 @Override
89 public void setChannels(List<IChannelInfo> channels) {
90 fChannels.clear();
91 for (Iterator<IChannelInfo> iterator = channels.iterator(); iterator.hasNext();) {
92 IChannelInfo channelInfo = iterator.next();
93 fChannels.add(channelInfo);
94 }
95 }
96
97 @Override
98 public void addChannel(IChannelInfo channel) {
99 fChannels.add(channel);
100 }
101
102 @Override
103 public int hashCode() {
104 final int prime = 31;
105 int result = super.hashCode();
106 result = prime * result + fChannels.hashCode();
107 result = prime * result + (fIsKernel ? 1231 : 1237);
108 result = prime * result + ((fBufferType == null) ? 0 : (fBufferType.ordinal() + 1));
109 return result;
110 }
111
112 @Override
113 public boolean equals(Object obj) {
114 if (this == obj) {
115 return true;
116 }
117 if (!super.equals(obj)) {
118 return false;
119 }
120 if (getClass() != obj.getClass()) {
121 return false;
122 }
123 DomainInfo other = (DomainInfo) obj;
124 if (!fChannels.equals(other.fChannels)) {
125 return false;
126 }
127 if (fIsKernel != other.fIsKernel) {
128 return false;
129 }
130 if (fBufferType != other.fBufferType) {
131 return false;
132 }
133 return true;
134 }
135
136 @Override
137 public BufferType getBufferType() {
138 if (fIsKernel) {
139 return BufferType.BUFFER_SHARED;
140 }
141 return fBufferType;
142 }
143
144 @Override
145 public void setBufferType(BufferType bufferType) {
146 fBufferType = bufferType;
147 }
148
149 @SuppressWarnings("nls")
150 @Override
151 public String toString() {
152 StringBuffer output = new StringBuffer();
153 output.append("[DomainInfo(");
154 output.append(super.toString());
155 output.append(",Channels=");
156 if (fChannels.isEmpty()) {
157 output.append("None");
158 } else {
159 for (Iterator<IChannelInfo> iterator = fChannels.iterator(); iterator.hasNext();) {
160 IChannelInfo channel = iterator.next();
161 output.append(channel.toString());
162 }
163 }
164 output.append(",isKernel=");
165 output.append(String.valueOf(fIsKernel));
166 if ((fBufferType != null) && !fBufferType.equals(BufferType.BUFFER_TYPE_UNKNOWN) && !fBufferType.equals(BufferType.BUFFER_SHARED)) {
167 output.append(",BufferType=");
168 output.append(fBufferType);
169 }
170 output.append(")]");
171 return output.toString();
172 }
173 }
This page took 0.040937 seconds and 5 git commands to generate.