8ac03fbb9dc314783e540c52bbd75205728c07b7
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.core / src / org / eclipse / linuxtools / internal / lttng2 / core / control / model / impl / UstProviderInfo.java
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.internal.lttng2.core.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.internal.lttng2.core.control.model.IBaseEventInfo;
19 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IUstProviderInfo;
20
21 /**
22 * <p>
23 * Implementation of the Ust Provider interface (IUstProviderInfo) to store UST
24 * provider related data.
25 * </p>
26 *
27 * @author Bernd Hufmann
28 */
29 public class UstProviderInfo extends TraceInfo implements IUstProviderInfo {
30
31 // ------------------------------------------------------------------------
32 // Attributes
33 // ------------------------------------------------------------------------
34 /**
35 * The process ID of the UST provider.
36 */
37 private int fPid = 0;
38 /**
39 * List of event information.
40 */
41 private final List<IBaseEventInfo> fEvents = new ArrayList<IBaseEventInfo>();
42
43 // ------------------------------------------------------------------------
44 // Constructors
45 // ------------------------------------------------------------------------
46 /**
47 * Constructor
48 * @param name - name of UST provider
49 */
50 public UstProviderInfo(String name) {
51 super(name);
52 }
53
54 /**
55 * Copy constructor
56 * @param other - the instance to copy
57 */
58 public UstProviderInfo(UstProviderInfo other) {
59 super(other);
60 fPid = other.fPid;
61 for (Iterator<IBaseEventInfo> iterator = other.fEvents.iterator(); iterator.hasNext();) {
62 IBaseEventInfo event = iterator.next();
63 if (event instanceof BaseEventInfo) {
64 fEvents.add(new BaseEventInfo((BaseEventInfo)event));
65 } else {
66 fEvents.add(event);
67 }
68 }
69 }
70
71 // ------------------------------------------------------------------------
72 // Accessors
73 // ------------------------------------------------------------------------
74
75 /*
76 * (non-Javadoc)
77 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IUstProviderInfo#getPid()
78 */
79 @Override
80 public int getPid() {
81 return fPid;
82 }
83
84 /*
85 * (non-Javadoc)
86 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IUstProviderInfo#setPid(int)
87 */
88 @Override
89 public void setPid(int pid) {
90 fPid = pid;
91 }
92
93 /*
94 * (non-Javadoc)
95 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IUstProviderInfo#getEvents()
96 */
97 @Override
98 public IBaseEventInfo[] getEvents() {
99 return fEvents.toArray(new IBaseEventInfo[fEvents.size()]);
100 }
101
102 /*
103 * (non-Javadoc)
104 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IUstProviderInfo#setEvents(java.util.List)
105 */
106 @Override
107 public void setEvents(List<IBaseEventInfo> events) {
108 for (Iterator<IBaseEventInfo> iterator = events.iterator(); iterator.hasNext();) {
109 IBaseEventInfo eventInfo = iterator.next();
110 fEvents.add(eventInfo);
111 }
112 }
113
114 /*
115 * (non-Javadoc)
116 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IUstProviderInfo#addEvent(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IBaseEventInfo)
117 */
118 @Override
119 public void addEvent(IBaseEventInfo event) {
120 fEvents.add(event);
121 }
122
123 // ------------------------------------------------------------------------
124 // Operations
125 // ------------------------------------------------------------------------
126
127 /*
128 * (non-Javadoc)
129 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#hashCode()
130 */
131 @Override
132 public int hashCode() {
133 final int prime = 31;
134 int result = super.hashCode();
135 result = prime * result + ((fEvents == null) ? 0 : fEvents.hashCode());
136 result = prime * result + fPid;
137 return result;
138 }
139
140 /*
141 * (non-Javadoc)
142 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object)
143 */
144 @Override
145 public boolean equals(Object obj) {
146 if (this == obj) {
147 return true;
148 }
149 if (!super.equals(obj)) {
150 return false;
151 }
152 if (getClass() != obj.getClass()) {
153 return false;
154 }
155 UstProviderInfo other = (UstProviderInfo) obj;
156 if (fEvents == null) {
157 if (other.fEvents != null) {
158 return false;
159 }
160 } else if (!fEvents.equals(other.fEvents)) {
161 return false;
162 }
163 if (fPid != other.fPid) {
164 return false;
165 }
166 return true;
167 }
168
169 /*
170 * (non-Javadoc)
171 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#toString()
172 */
173 @SuppressWarnings("nls")
174 @Override
175 public String toString() {
176 StringBuffer output = new StringBuffer();
177 output.append("[EventInfo(");
178 output.append(super.toString());
179 output.append(",PID=");
180 output.append(fPid);
181 output.append(",Events=");
182 if (fEvents.isEmpty()) {
183 output.append("None");
184 } else {
185 for (Iterator<IBaseEventInfo> iterator = fEvents.iterator(); iterator.hasNext();) {
186 IBaseEventInfo event = iterator.next();
187 output.append(event.toString());
188 }
189 }
190 output.append(")]");
191 return output.toString();
192 }
193
194
195 }
This page took 0.033917 seconds and 4 git commands to generate.