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