7f33c8a150105f30239294d872c0b762e4dc70bd
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.core / src / org / eclipse / linuxtools / internal / lttng2 / control / core / model / impl / UstProviderInfo.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2014 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.control.core.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.control.core.model.IBaseEventInfo;
19 import org.eclipse.linuxtools.internal.lttng2.control.core.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 /**
36 * The process ID of the UST provider.
37 */
38 private int fPid = 0;
39
40 /**
41 * List of event information.
42 */
43 private final List<IBaseEventInfo> fEvents = new ArrayList<>();
44
45 // ------------------------------------------------------------------------
46 // Constructors
47 // ------------------------------------------------------------------------
48
49 /**
50 * Constructor
51 * @param name - name of UST provider
52 */
53 public UstProviderInfo(String name) {
54 super(name);
55 }
56
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 }
73
74 // ------------------------------------------------------------------------
75 // Accessors
76 // ------------------------------------------------------------------------
77
78 @Override
79 public int getPid() {
80 return fPid;
81 }
82
83 @Override
84 public void setPid(int pid) {
85 fPid = pid;
86 }
87
88 @Override
89 public IBaseEventInfo[] getEvents() {
90 return fEvents.toArray(new IBaseEventInfo[fEvents.size()]);
91 }
92
93 @Override
94 public void setEvents(List<IBaseEventInfo> events) {
95 fEvents.clear();
96 for (Iterator<IBaseEventInfo> iterator = events.iterator(); iterator.hasNext();) {
97 IBaseEventInfo eventInfo = iterator.next();
98 fEvents.add(eventInfo);
99 }
100 }
101
102 @Override
103 public void addEvent(IBaseEventInfo event) {
104 fEvents.add(event);
105 }
106
107 // ------------------------------------------------------------------------
108 // Operations
109 // ------------------------------------------------------------------------
110
111 @Override
112 public int hashCode() {
113 final int prime = 31;
114 int result = super.hashCode();
115 result = prime * result + fEvents.hashCode();
116 result = prime * result + fPid;
117 return result;
118 }
119
120 @Override
121 public boolean equals(Object obj) {
122 if (this == obj) {
123 return true;
124 }
125 if (!super.equals(obj)) {
126 return false;
127 }
128 if (getClass() != obj.getClass()) {
129 return false;
130 }
131 UstProviderInfo other = (UstProviderInfo) obj;
132 if (!fEvents.equals(other.fEvents)) {
133 return false;
134 }
135 if (fPid != other.fPid) {
136 return false;
137 }
138 return true;
139 }
140
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();) {
154 IBaseEventInfo event = iterator.next();
155 output.append(event.toString());
156 }
157 }
158 output.append(")]");
159 return output.toString();
160 }
161
162 }
This page took 0.035069 seconds and 4 git commands to generate.