Commit | Line | Data |
---|---|---|
eb1bab5b | 1 | /********************************************************************** |
94cce698 | 2 | * Copyright (c) 2012, 2013 Ericsson |
b0318660 | 3 | * |
eb1bab5b BH |
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 | |
b0318660 AM |
8 | * |
9 | * Contributors: | |
eb1bab5b BH |
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 | |
b0318660 | 24 | * related data. |
eb1bab5b | 25 | * </p> |
b0318660 | 26 | * |
dbd4432d | 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 | */ | |
b0318660 | 37 | private final List<IChannelInfo> fChannels = new ArrayList<IChannelInfo>(); |
bbb3538a | 38 | private boolean fIsKernel = false; |
ca8c54b3 | 39 | private String fBufferType = null; |
eb1bab5b BH |
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 | } | |
bbb3538a BH |
65 | fIsKernel = other.fIsKernel; |
66 | } | |
b0318660 | 67 | |
bbb3538a BH |
68 | @Override |
69 | public boolean isKernel() { | |
70 | return fIsKernel; | |
71 | } | |
b0318660 | 72 | |
bbb3538a BH |
73 | @Override |
74 | public void setIsKernel(boolean isKernel) { | |
75 | fIsKernel = isKernel; | |
eb1bab5b BH |
76 | } |
77 | ||
78 | // ------------------------------------------------------------------------ | |
79 | // Accessors | |
80 | // ------------------------------------------------------------------------ | |
11252342 | 81 | |
eb1bab5b BH |
82 | @Override |
83 | public IChannelInfo[] getChannels() { | |
84 | return fChannels.toArray(new IChannelInfo[fChannels.size()]); | |
85 | } | |
86 | ||
eb1bab5b BH |
87 | @Override |
88 | public void setChannels(List<IChannelInfo> channels) { | |
a6702bfa | 89 | fChannels.clear(); |
eb1bab5b | 90 | for (Iterator<IChannelInfo> iterator = channels.iterator(); iterator.hasNext();) { |
b0318660 | 91 | IChannelInfo channelInfo = iterator.next(); |
eb1bab5b BH |
92 | fChannels.add(channelInfo); |
93 | } | |
94 | } | |
95 | ||
eb1bab5b BH |
96 | @Override |
97 | public void addChannel(IChannelInfo channel) { | |
98 | fChannels.add(channel); | |
99 | } | |
b0318660 | 100 | |
eb1bab5b BH |
101 | @Override |
102 | public int hashCode() { | |
d132bcc7 BH |
103 | final int prime = 31; |
104 | int result = super.hashCode(); | |
77fdc5df | 105 | result = prime * result + fChannels.hashCode(); |
d132bcc7 | 106 | result = prime * result + (fIsKernel ? 1231 : 1237); |
eb1bab5b BH |
107 | return result; |
108 | } | |
109 | ||
eb1bab5b | 110 | @Override |
d132bcc7 BH |
111 | public boolean equals(Object obj) { |
112 | if (this == obj) { | |
113 | return true; | |
eb1bab5b | 114 | } |
d132bcc7 | 115 | if (!super.equals(obj)) { |
eb1bab5b BH |
116 | return false; |
117 | } | |
d132bcc7 | 118 | if (getClass() != obj.getClass()) { |
eb1bab5b BH |
119 | return false; |
120 | } | |
d132bcc7 | 121 | DomainInfo other = (DomainInfo) obj; |
77fdc5df | 122 | if (!fChannels.equals(other.fChannels)) { |
d132bcc7 | 123 | return false; |
eb1bab5b | 124 | } |
d132bcc7 | 125 | if (fIsKernel != other.fIsKernel) { |
bbb3538a BH |
126 | return false; |
127 | } | |
eb1bab5b BH |
128 | return true; |
129 | } | |
d132bcc7 | 130 | |
ca8c54b3 SD |
131 | @Override |
132 | public String getBufferType() { | |
133 | if (fIsKernel) { | |
134 | return BufferTypeConstants.BUFFER_SHARED; | |
135 | } | |
136 | return fBufferType; | |
137 | } | |
138 | ||
139 | @Override | |
140 | public void setBufferType(String bufferType) { | |
141 | fBufferType = bufferType; | |
142 | } | |
143 | ||
eb1bab5b BH |
144 | @SuppressWarnings("nls") |
145 | @Override | |
146 | public String toString() { | |
147 | StringBuffer output = new StringBuffer(); | |
148 | output.append("[DomainInfo("); | |
149 | output.append(super.toString()); | |
150 | output.append(",Channels="); | |
151 | if (fChannels.isEmpty()) { | |
152 | output.append("None"); | |
153 | } else { | |
154 | for (Iterator<IChannelInfo> iterator = fChannels.iterator(); iterator.hasNext();) { | |
b0318660 | 155 | IChannelInfo channel = iterator.next(); |
eb1bab5b BH |
156 | output.append(channel.toString()); |
157 | } | |
158 | } | |
bbb3538a BH |
159 | output.append(",isKernel="); |
160 | output.append(String.valueOf(fIsKernel)); | |
eb1bab5b BH |
161 | output.append(")]"); |
162 | return output.toString(); | |
163 | } | |
164 | } |