| 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 | private boolean fIsKernel = false; |
| 38 | |
| 39 | // ------------------------------------------------------------------------ |
| 40 | // Constructors |
| 41 | // ------------------------------------------------------------------------ |
| 42 | /** |
| 43 | * Constructor |
| 44 | * @param name - name of domain |
| 45 | */ |
| 46 | public DomainInfo(String name) { |
| 47 | super(name); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Copy constructor |
| 52 | * @param other - the instance to copy |
| 53 | */ |
| 54 | public DomainInfo(DomainInfo other) { |
| 55 | super(other); |
| 56 | for (int i = 0; i < other.fChannels.size(); i++) { |
| 57 | if (other.fChannels.get(i) instanceof ChannelInfo) { |
| 58 | fChannels.add(new ChannelInfo((ChannelInfo)other.fChannels.get(i))); |
| 59 | } else { |
| 60 | fChannels.add(other.fChannels.get(i)); |
| 61 | } |
| 62 | } |
| 63 | fIsKernel = other.fIsKernel; |
| 64 | } |
| 65 | |
| 66 | /* |
| 67 | * (non-Javadoc) |
| 68 | * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo#isKernel() |
| 69 | */ |
| 70 | @Override |
| 71 | public boolean isKernel() { |
| 72 | return fIsKernel; |
| 73 | } |
| 74 | |
| 75 | /* |
| 76 | * (non-Javadoc) |
| 77 | * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo#setIsKernel(boolean) |
| 78 | */ |
| 79 | @Override |
| 80 | public void setIsKernel(boolean isKernel) { |
| 81 | fIsKernel = isKernel; |
| 82 | } |
| 83 | |
| 84 | // ------------------------------------------------------------------------ |
| 85 | // Accessors |
| 86 | // ------------------------------------------------------------------------ |
| 87 | /* |
| 88 | * (non-Javadoc) |
| 89 | * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo#getChannels() |
| 90 | */ |
| 91 | @Override |
| 92 | public IChannelInfo[] getChannels() { |
| 93 | return fChannels.toArray(new IChannelInfo[fChannels.size()]); |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * (non-Javadoc) |
| 98 | * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo#setChannels(java.util.List) |
| 99 | */ |
| 100 | @Override |
| 101 | public void setChannels(List<IChannelInfo> channels) { |
| 102 | for (Iterator<IChannelInfo> iterator = channels.iterator(); iterator.hasNext();) { |
| 103 | IChannelInfo channelInfo = (IChannelInfo) iterator.next(); |
| 104 | fChannels.add(channelInfo); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /* |
| 109 | * (non-Javadoc) |
| 110 | * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo#addChannel(org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo) |
| 111 | */ |
| 112 | @Override |
| 113 | public void addChannel(IChannelInfo channel) { |
| 114 | fChannels.add(channel); |
| 115 | } |
| 116 | |
| 117 | /* |
| 118 | * (non-Javadoc) |
| 119 | * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceInfo#formatString() |
| 120 | */ |
| 121 | @SuppressWarnings("nls") |
| 122 | @Override |
| 123 | public String formatString() { |
| 124 | StringBuffer output = new StringBuffer(); |
| 125 | //=== Domain: Kernel === |
| 126 | output.append("\n=== Domain: "); |
| 127 | output.append(getName()); |
| 128 | output.append(" ===\n"); |
| 129 | output.append("\n"); |
| 130 | // Channels: |
| 131 | output.append("Channels:\n"); |
| 132 | // ------------- |
| 133 | output.append("-------------"); |
| 134 | if (fChannels.isEmpty()) { |
| 135 | output.append("\nNone"); |
| 136 | } else { |
| 137 | for (Iterator<IChannelInfo> iterator = fChannels.iterator(); iterator.hasNext();) { |
| 138 | IChannelInfo channel = (IChannelInfo) iterator.next(); |
| 139 | output.append(channel.formatString()); |
| 140 | } |
| 141 | } |
| 142 | output.append("\n"); |
| 143 | return output.toString(); |
| 144 | } |
| 145 | |
| 146 | /* |
| 147 | * (non-Javadoc) |
| 148 | * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#hashCode() |
| 149 | */ |
| 150 | @Override |
| 151 | public int hashCode() { |
| 152 | final int prime = 31; |
| 153 | int result = super.hashCode(); |
| 154 | result = prime * result + ((fChannels == null) ? 0 : fChannels.hashCode()); |
| 155 | result = prime * result + (fIsKernel ? 1231 : 1237); |
| 156 | return result; |
| 157 | } |
| 158 | |
| 159 | /* |
| 160 | * (non-Javadoc) |
| 161 | * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object) |
| 162 | */ |
| 163 | @Override |
| 164 | public boolean equals(Object obj) { |
| 165 | if (this == obj) { |
| 166 | return true; |
| 167 | } |
| 168 | if (!super.equals(obj)) { |
| 169 | return false; |
| 170 | } |
| 171 | if (getClass() != obj.getClass()) { |
| 172 | return false; |
| 173 | } |
| 174 | DomainInfo other = (DomainInfo) obj; |
| 175 | if (fChannels == null) { |
| 176 | if (other.fChannels != null) { |
| 177 | return false; |
| 178 | } |
| 179 | } else if (!fChannels.equals(other.fChannels)) { |
| 180 | return false; |
| 181 | } |
| 182 | if (fIsKernel != other.fIsKernel) { |
| 183 | return false; |
| 184 | } |
| 185 | return true; |
| 186 | } |
| 187 | |
| 188 | /* |
| 189 | * (non-Javadoc) |
| 190 | * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#toString() |
| 191 | */ |
| 192 | @SuppressWarnings("nls") |
| 193 | @Override |
| 194 | public String toString() { |
| 195 | StringBuffer output = new StringBuffer(); |
| 196 | output.append("[DomainInfo("); |
| 197 | output.append(super.toString()); |
| 198 | output.append(",Channels="); |
| 199 | if (fChannels.isEmpty()) { |
| 200 | output.append("None"); |
| 201 | } else { |
| 202 | for (Iterator<IChannelInfo> iterator = fChannels.iterator(); iterator.hasNext();) { |
| 203 | IChannelInfo channel = (IChannelInfo) iterator.next(); |
| 204 | output.append(channel.toString()); |
| 205 | } |
| 206 | } |
| 207 | output.append(",isKernel="); |
| 208 | output.append(String.valueOf(fIsKernel)); |
| 209 | output.append(")]"); |
| 210 | return output.toString(); |
| 211 | } |
| 212 | |
| 213 | } |