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 | /** | |
eb1bab5b BH |
22 | * <p> |
23 | * Implementation of the Ust Provider interface (IUstProviderInfo) to store UST | |
24 | * provider related data. | |
25 | * </p> | |
dbd4432d BH |
26 | * |
27 | * @author Bernd Hufmann | |
eb1bab5b BH |
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 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) | |
115b4a01 | 77 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IUstProviderInfo#getPid() |
eb1bab5b BH |
78 | */ |
79 | @Override | |
80 | public int getPid() { | |
81 | return fPid; | |
82 | } | |
83 | ||
84 | /* | |
85 | * (non-Javadoc) | |
115b4a01 | 86 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IUstProviderInfo#setPid(int) |
eb1bab5b BH |
87 | */ |
88 | @Override | |
89 | public void setPid(int pid) { | |
90 | fPid = pid; | |
91 | } | |
92 | ||
93 | /* | |
94 | * (non-Javadoc) | |
115b4a01 | 95 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IUstProviderInfo#getEvents() |
eb1bab5b BH |
96 | */ |
97 | @Override | |
98 | public IBaseEventInfo[] getEvents() { | |
99 | return fEvents.toArray(new IBaseEventInfo[fEvents.size()]); | |
100 | } | |
101 | ||
102 | /* | |
103 | * (non-Javadoc) | |
115b4a01 | 104 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IUstProviderInfo#setEvents(java.util.List) |
eb1bab5b BH |
105 | */ |
106 | @Override | |
107 | public void setEvents(List<IBaseEventInfo> events) { | |
108 | for (Iterator<IBaseEventInfo> iterator = events.iterator(); iterator.hasNext();) { | |
109 | IBaseEventInfo eventInfo = (IBaseEventInfo) iterator.next(); | |
110 | fEvents.add(eventInfo); | |
111 | } | |
112 | } | |
113 | ||
114 | /* | |
115 | * (non-Javadoc) | |
115b4a01 | 116 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IUstProviderInfo#addEvent(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IBaseEventInfo) |
eb1bab5b BH |
117 | */ |
118 | @Override | |
119 | public void addEvent(IBaseEventInfo event) { | |
120 | fEvents.add(event); | |
121 | } | |
122 | ||
123 | // ------------------------------------------------------------------------ | |
124 | // Operations | |
125 | // ------------------------------------------------------------------------ | |
d132bcc7 | 126 | |
d132bcc7 BH |
127 | /* |
128 | * (non-Javadoc) | |
115b4a01 | 129 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#hashCode() |
d132bcc7 BH |
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; | |
eb1bab5b BH |
137 | return result; |
138 | } | |
139 | ||
140 | /* | |
141 | * (non-Javadoc) | |
115b4a01 | 142 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object) |
eb1bab5b BH |
143 | */ |
144 | @Override | |
d132bcc7 BH |
145 | public boolean equals(Object obj) { |
146 | if (this == obj) { | |
147 | return true; | |
eb1bab5b | 148 | } |
d132bcc7 | 149 | if (!super.equals(obj)) { |
eb1bab5b BH |
150 | return false; |
151 | } | |
d132bcc7 | 152 | if (getClass() != obj.getClass()) { |
eb1bab5b BH |
153 | return false; |
154 | } | |
d132bcc7 BH |
155 | UstProviderInfo other = (UstProviderInfo) obj; |
156 | if (fEvents == null) { | |
157 | if (other.fEvents != null) { | |
eb1bab5b BH |
158 | return false; |
159 | } | |
d132bcc7 BH |
160 | } else if (!fEvents.equals(other.fEvents)) { |
161 | return false; | |
162 | } | |
163 | if (fPid != other.fPid) { | |
164 | return false; | |
eb1bab5b BH |
165 | } |
166 | return true; | |
167 | } | |
168 | ||
169 | /* | |
170 | * (non-Javadoc) | |
115b4a01 | 171 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#toString() |
eb1bab5b BH |
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 = (IBaseEventInfo) iterator.next(); | |
187 | output.append(event.toString()); | |
188 | } | |
189 | } | |
190 | output.append(")]"); | |
191 | return output.toString(); | |
192 | } | |
d132bcc7 BH |
193 | |
194 | ||
eb1bab5b | 195 | } |