Commit | Line | Data |
---|---|---|
eb1bab5b | 1 | /********************************************************************** |
60ae41e1 | 2 | * Copyright (c) 2012, 2014 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 BH |
10 | * Bernd Hufmann - Initial API and implementation |
11 | **********************************************************************/ | |
8e8c0226 | 12 | package org.eclipse.linuxtools.internal.lttng2.control.core.model.impl; |
eb1bab5b BH |
13 | |
14 | import java.util.ArrayList; | |
15 | import java.util.Iterator; | |
16 | import java.util.List; | |
17 | ||
8e8c0226 AM |
18 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.IBaseEventInfo; |
19 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.IUstProviderInfo; | |
eb1bab5b BH |
20 | |
21 | /** | |
eb1bab5b | 22 | * <p> |
b0318660 AM |
23 | * Implementation of the Ust Provider interface (IUstProviderInfo) to store UST |
24 | * provider related data. | |
eb1bab5b | 25 | * </p> |
b0318660 | 26 | * |
dbd4432d | 27 | * @author Bernd Hufmann |
eb1bab5b BH |
28 | */ |
29 | public class UstProviderInfo extends TraceInfo implements IUstProviderInfo { | |
30 | ||
31 | // ------------------------------------------------------------------------ | |
32 | // Attributes | |
33 | // ------------------------------------------------------------------------ | |
11252342 | 34 | |
eb1bab5b BH |
35 | /** |
36 | * The process ID of the UST provider. | |
37 | */ | |
38 | private int fPid = 0; | |
11252342 | 39 | |
eb1bab5b BH |
40 | /** |
41 | * List of event information. | |
42 | */ | |
e0838ca1 | 43 | private final List<IBaseEventInfo> fEvents = new ArrayList<>(); |
b0318660 | 44 | |
eb1bab5b BH |
45 | // ------------------------------------------------------------------------ |
46 | // Constructors | |
47 | // ------------------------------------------------------------------------ | |
11252342 | 48 | |
eb1bab5b BH |
49 | /** |
50 | * Constructor | |
51 | * @param name - name of UST provider | |
52 | */ | |
53 | public UstProviderInfo(String name) { | |
54 | super(name); | |
55 | } | |
b0318660 | 56 | |
eb1bab5b BH |
57 | /** |
58 | * Copy constructor | |
59 | * @param other - the instance to copy | |
60 | */ | |
61 | public UstProviderInfo(UstProviderInfo other) { | |
62 | super(other); | |
63 | fPid = other.fPid; | |
64 | for (Iterator<IBaseEventInfo> iterator = other.fEvents.iterator(); iterator.hasNext();) { | |
65 | IBaseEventInfo event = iterator.next(); | |
66 | if (event instanceof BaseEventInfo) { | |
67 | fEvents.add(new BaseEventInfo((BaseEventInfo)event)); | |
68 | } else { | |
69 | fEvents.add(event); | |
70 | } | |
71 | } | |
72 | } | |
b0318660 | 73 | |
eb1bab5b BH |
74 | // ------------------------------------------------------------------------ |
75 | // Accessors | |
76 | // ------------------------------------------------------------------------ | |
77 | ||
eb1bab5b BH |
78 | @Override |
79 | public int getPid() { | |
80 | return fPid; | |
81 | } | |
82 | ||
eb1bab5b BH |
83 | @Override |
84 | public void setPid(int pid) { | |
85 | fPid = pid; | |
86 | } | |
87 | ||
eb1bab5b BH |
88 | @Override |
89 | public IBaseEventInfo[] getEvents() { | |
90 | return fEvents.toArray(new IBaseEventInfo[fEvents.size()]); | |
91 | } | |
92 | ||
eb1bab5b BH |
93 | @Override |
94 | public void setEvents(List<IBaseEventInfo> events) { | |
a6702bfa | 95 | fEvents.clear(); |
eb1bab5b | 96 | for (Iterator<IBaseEventInfo> iterator = events.iterator(); iterator.hasNext();) { |
b0318660 | 97 | IBaseEventInfo eventInfo = iterator.next(); |
eb1bab5b BH |
98 | fEvents.add(eventInfo); |
99 | } | |
100 | } | |
101 | ||
eb1bab5b BH |
102 | @Override |
103 | public void addEvent(IBaseEventInfo event) { | |
104 | fEvents.add(event); | |
105 | } | |
106 | ||
107 | // ------------------------------------------------------------------------ | |
108 | // Operations | |
109 | // ------------------------------------------------------------------------ | |
d132bcc7 | 110 | |
d132bcc7 BH |
111 | @Override |
112 | public int hashCode() { | |
113 | final int prime = 31; | |
114 | int result = super.hashCode(); | |
77fdc5df | 115 | result = prime * result + fEvents.hashCode(); |
d132bcc7 | 116 | result = prime * result + fPid; |
eb1bab5b BH |
117 | return result; |
118 | } | |
119 | ||
eb1bab5b | 120 | @Override |
d132bcc7 BH |
121 | public boolean equals(Object obj) { |
122 | if (this == obj) { | |
123 | return true; | |
eb1bab5b | 124 | } |
d132bcc7 | 125 | if (!super.equals(obj)) { |
eb1bab5b BH |
126 | return false; |
127 | } | |
d132bcc7 | 128 | if (getClass() != obj.getClass()) { |
eb1bab5b BH |
129 | return false; |
130 | } | |
d132bcc7 | 131 | UstProviderInfo other = (UstProviderInfo) obj; |
77fdc5df | 132 | if (!fEvents.equals(other.fEvents)) { |
d132bcc7 BH |
133 | return false; |
134 | } | |
135 | if (fPid != other.fPid) { | |
136 | return false; | |
eb1bab5b BH |
137 | } |
138 | return true; | |
139 | } | |
b0318660 | 140 | |
eb1bab5b BH |
141 | @SuppressWarnings("nls") |
142 | @Override | |
143 | public String toString() { | |
144 | StringBuffer output = new StringBuffer(); | |
145 | output.append("[EventInfo("); | |
146 | output.append(super.toString()); | |
147 | output.append(",PID="); | |
148 | output.append(fPid); | |
149 | output.append(",Events="); | |
150 | if (fEvents.isEmpty()) { | |
151 | output.append("None"); | |
152 | } else { | |
153 | for (Iterator<IBaseEventInfo> iterator = fEvents.iterator(); iterator.hasNext();) { | |
b0318660 | 154 | IBaseEventInfo event = iterator.next(); |
eb1bab5b BH |
155 | output.append(event.toString()); |
156 | } | |
157 | } | |
158 | output.append(")]"); | |
159 | return output.toString(); | |
160 | } | |
d132bcc7 | 161 | |
eb1bab5b | 162 | } |