lttng: Add clear() call before add elements to list
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.core / src / org / eclipse / linuxtools / internal / lttng2 / core / control / model / impl / SessionInfo.java
CommitLineData
eb1bab5b 1/**********************************************************************
ba3a9bd2 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 10 * Bernd Hufmann - Initial API and implementation
ba3a9bd2 11 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
eb1bab5b 12 **********************************************************************/
9315aeee 13package org.eclipse.linuxtools.internal.lttng2.core.control.model.impl;
eb1bab5b
BH
14
15import java.util.ArrayList;
16import java.util.Iterator;
17import java.util.List;
18
9315aeee
BH
19import org.eclipse.linuxtools.internal.lttng2.core.control.model.IDomainInfo;
20import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo;
21import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState;
eb1bab5b
BH
22
23/**
eb1bab5b
BH
24 * <p>
25 * Implementation of the trace session interface (ISessionInfo) to store session
b0318660 26 * related data.
eb1bab5b 27 * </p>
b0318660 28 *
dbd4432d 29 * @author Bernd Hufmann
eb1bab5b
BH
30 */
31public class SessionInfo extends TraceInfo implements ISessionInfo {
32
33 // ------------------------------------------------------------------------
34 // Attributes
35 // ------------------------------------------------------------------------
36 /**
37 * The trace session state.
38 */
39 private TraceSessionState fState = TraceSessionState.INACTIVE;
b0318660 40 /**
eb1bab5b
BH
41 * The trace session path for storing traces.
42 */
43 private String fSessionPath = ""; //$NON-NLS-1$
44 /**
45 * The domains information of this session.
46 */
b0318660 47 private final List<IDomainInfo> fDomains = new ArrayList<IDomainInfo>();
f3b33d40
BH
48 /**
49 * Flag to indicate whether trace is streamed over network or not.
50 */
51 private boolean fIsStreamedTrace = false;
eb1bab5b
BH
52
53 // ------------------------------------------------------------------------
54 // Constructors
55 // ------------------------------------------------------------------------
56 /**
57 * Constructor
58 * @param name - name of base event
59 */
60 public SessionInfo(String name) {
61 super(name);
62 }
63
64 /**
65 * Copy constructor
66 * @param other - the instance to copy
67 */
68 public SessionInfo(SessionInfo other) {
69 super(other);
70 fState = other.fState;
71 fSessionPath = other.fSessionPath;
f3b33d40 72 fIsStreamedTrace = other.fIsStreamedTrace;
b0318660 73
eb1bab5b
BH
74 for (Iterator<IDomainInfo> iterator = other.fDomains.iterator(); iterator.hasNext();) {
75 IDomainInfo domain = iterator.next();
76 if (domain instanceof DomainInfo) {
77 fDomains.add(new DomainInfo((DomainInfo)domain));
78 } else {
79 fDomains.add(domain);
80 }
81 }
82 }
b0318660 83
eb1bab5b
BH
84 // ------------------------------------------------------------------------
85 // Accessors
86 // ------------------------------------------------------------------------
87 /*
88 * (non-Javadoc)
115b4a01 89 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ISessionInfo#getSessionState()
eb1bab5b
BH
90 */
91 @Override
92 public TraceSessionState getSessionState() {
93 return fState;
94 }
95
96 /*
97 * (non-Javadoc)
115b4a01 98 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ISessionInfo#setSessionState(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceSessionState)
eb1bab5b
BH
99 */
100 @Override
101 public void setSessionState(TraceSessionState state) {
102 fState = state;
103 }
104
105 /*
106 * (non-Javadoc)
115b4a01 107 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ISessionInfo#setSessionState(java.lang.String)
eb1bab5b
BH
108 */
109 @Override
110 public void setSessionState(String stateName) {
111 if (TraceSessionState.INACTIVE.getInName().equals(stateName)) {
112 fState = TraceSessionState.INACTIVE;
113 } else if (TraceSessionState.ACTIVE.getInName().equals(stateName)) {
114 fState = TraceSessionState.ACTIVE;
115 }
116 }
b0318660 117
eb1bab5b
BH
118 /*
119 * (non-Javadoc)
115b4a01 120 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ISessionInfo#getSessionPath()
eb1bab5b
BH
121 */
122 @Override
123 public String getSessionPath() {
124 return fSessionPath;
125 }
126
127 /*
128 * (non-Javadoc)
115b4a01 129 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ISessionInfo#setSessionPath(java.lang.String)
eb1bab5b
BH
130 */
131 @Override
132 public void setSessionPath(String path) {
133 fSessionPath = path;
134 }
135
136 /*
137 * (non-Javadoc)
115b4a01 138 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ISessionInfo#getDomains()
eb1bab5b
BH
139 */
140 @Override
141 public IDomainInfo[] getDomains() {
142 return fDomains.toArray(new IDomainInfo[fDomains.size()]);
143 }
144
145 /*
146 * (non-Javadoc)
115b4a01 147 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ISessionInfo#setDomains(java.util.List)
eb1bab5b
BH
148 */
149 @Override
150 public void setDomains(List<IDomainInfo> domains) {
a6702bfa 151 fDomains.clear();
eb1bab5b 152 for (Iterator<IDomainInfo> iterator = domains.iterator(); iterator.hasNext();) {
b0318660 153 IDomainInfo domainInfo = iterator.next();
eb1bab5b
BH
154 fDomains.add(domainInfo);
155 }
156 }
157
f3b33d40
BH
158 /*
159 * (non-Javadoc)
160 * @see org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo#isStreamedTrace()
161 */
162 @Override
163 public boolean isStreamedTrace() {
164 return fIsStreamedTrace;
165 }
166
167 /*
168 * (non-Javadoc)
169 * @see org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo#setIsStreamedTrace(boolean)
170 */
171
172 @Override
173 public void setStreamedTrace(boolean isStreamedTrace) {
174 fIsStreamedTrace = isStreamedTrace;
175 }
176
eb1bab5b
BH
177 // ------------------------------------------------------------------------
178 // Operations
179 // ------------------------------------------------------------------------
180 /*
181 * (non-Javadoc)
115b4a01 182 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ISessionInfo#addDomain(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IDomainInfo)
eb1bab5b
BH
183 */
184 @Override
185 public void addDomain(IDomainInfo domainInfo) {
186 fDomains.add(domainInfo);
187 }
b0318660 188
d132bcc7
BH
189 /*
190 * (non-Javadoc)
f3b33d40 191 * @see org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.TraceInfo#hashCode()
d132bcc7
BH
192 */
193 @Override
194 public int hashCode() {
195 final int prime = 31;
196 int result = super.hashCode();
77fdc5df 197 result = prime * result + fDomains.hashCode();
f3b33d40 198 result = prime * result + (fIsStreamedTrace ? 1231 : 1237);
d132bcc7 199 result = prime * result + ((fSessionPath == null) ? 0 : fSessionPath.hashCode());
f3b33d40 200 result = prime * result + ((fState == null) ? 0 : fState.hashCode());
eb1bab5b
BH
201 return result;
202 }
203
204 /*
205 * (non-Javadoc)
f3b33d40 206 * @see org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.TraceInfo#equals(java.lang.Object)
eb1bab5b
BH
207 */
208 @Override
d132bcc7
BH
209 public boolean equals(Object obj) {
210 if (this == obj) {
211 return true;
eb1bab5b 212 }
d132bcc7 213 if (!super.equals(obj)) {
eb1bab5b
BH
214 return false;
215 }
d132bcc7 216 if (getClass() != obj.getClass()) {
eb1bab5b
BH
217 return false;
218 }
d132bcc7 219 SessionInfo other = (SessionInfo) obj;
77fdc5df 220 if (!fDomains.equals(other.fDomains)) {
eb1bab5b
BH
221 return false;
222 }
f3b33d40
BH
223 if (fIsStreamedTrace != other.fIsStreamedTrace) {
224 return false;
225 }
d132bcc7
BH
226 if (fSessionPath == null) {
227 if (other.fSessionPath != null) {
eb1bab5b
BH
228 return false;
229 }
d132bcc7
BH
230 } else if (!fSessionPath.equals(other.fSessionPath)) {
231 return false;
232 }
233 if (fState != other.fState) {
234 return false;
eb1bab5b
BH
235 }
236 return true;
237 }
d132bcc7 238
eb1bab5b
BH
239 /*
240 * (non-Javadoc)
115b4a01 241 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#toString()
eb1bab5b
BH
242 */
243 @SuppressWarnings("nls")
244 @Override
245 public String toString() {
246 StringBuffer output = new StringBuffer();
247 output.append("[SessionInfo(");
248 output.append(super.toString());
249 output.append(",State=");
250 output.append(fState);
a30e79fe
BH
251 output.append(",isStreamedTrace=");
252 output.append(fIsStreamedTrace);
eb1bab5b
BH
253 output.append(",Domains=");
254 for (Iterator<IDomainInfo> iterator = fDomains.iterator(); iterator.hasNext();) {
b0318660 255 IDomainInfo domain = iterator.next();
d132bcc7 256 output.append(domain.toString());
eb1bab5b
BH
257 }
258 output.append(")]");
259 return output.toString();
260 }
261}
This page took 0.046266 seconds and 5 git commands to generate.