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