-
Notifications
You must be signed in to change notification settings - Fork 10
/
TmfConfigurationSourceType.java
176 lines (156 loc) · 5.24 KB
/
TmfConfigurationSourceType.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*******************************************************************************
* Copyright (c) 2023 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.tracecompass.tmf.core.config;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.eclipse.jdt.annotation.Nullable;
/**
* Implementation of {@link ITmfConfigurationSourceType} interface. It provides
* a builder class to create instances of that interface.
*
* @author Bernd Hufmann
* @since 9.2
*/
public class TmfConfigurationSourceType implements ITmfConfigurationSourceType {
private final String fId;
private final String fName;
private final String fDescription;
private final List<ITmfConfigParamDescriptor> fParamDescriptors;
/**
* Constructor
*
* @param bulider
* the builder object to create the descriptor
*/
private TmfConfigurationSourceType(Builder builder) {
fId = builder.fId;
fName = builder.fName;
fDescription = builder.fDescription;
fParamDescriptors = builder.fDescriptors;
}
@Override
public String getName() {
return fName;
}
@Override
public String getId() {
return fId;
}
@Override
public String getDescription() {
return fDescription;
}
@Override
public List<ITmfConfigParamDescriptor> getConfigParamDescriptors() {
return fParamDescriptors;
}
@Override
@SuppressWarnings("nls")
public String toString() {
return new StringBuilder(getClass().getSimpleName())
.append("[")
.append("fName=").append(getName())
.append(", fDescription=").append(getDescription())
.append(", fId=").append(getId())
.append(", fKeys=").append(getConfigParamDescriptors())
.append("]").toString();
}
@Override
public boolean equals(@Nullable Object arg0) {
if (!(arg0 instanceof TmfConfigurationSourceType)) {
return false;
}
TmfConfigurationSourceType other = (TmfConfigurationSourceType) arg0;
return Objects.equals(fName, other.fName) && Objects.equals(fId, other.fId) && Objects.equals(fDescription, other.fDescription)
&& Objects.equals(fParamDescriptors, other.fParamDescriptors);
}
@Override
public int hashCode() {
return Objects.hash(fName, fId, fParamDescriptors, fDescription);
}
/**
* A builder class to build instances implementing interface
* {@link ITmfConfigurationSourceType}
*/
public static class Builder {
private String fId = ""; //$NON-NLS-1$
private String fName = ""; //$NON-NLS-1$
private String fDescription = ""; //$NON-NLS-1$
private List<ITmfConfigParamDescriptor> fDescriptors = new ArrayList<>();
/**
* Constructor
*/
public Builder() {
// Empty constructor
}
/**
* Sets the ID of the configuration source type
*
* @param id
* the ID of the data provider
* @return the builder instance.
*/
public Builder setId(String id) {
fId = id;
return this;
}
/**
* Sets the name of the configuration source type
*
* @param name
* the name to set
* @return the builder instance.
*/
public Builder setName(String name) {
fName = name;
return this;
}
/**
* Sets the description of the configuration source type
*
* @param description
* the description text to set
* @return the builder instance.
*/
public Builder setDescription(String description) {
fDescription = description;
return this;
}
/**
* Sets the configuration parameter descriptors of the configuration
* source type
*
* @param descriptors
* the query parameter keys to set
* @return the builder instance.
*/
public Builder setConfigParamDescriptors(List<ITmfConfigParamDescriptor> descriptors) {
fDescriptors = descriptors;
return this;
}
/**
* The method to construct an instance of
* {@link ITmfConfigurationSourceType}
*
* @return a {@link ITmfConfigurationSourceType} instance
*/
public ITmfConfigurationSourceType build() {
if (fId.isBlank()) {
throw new IllegalStateException("Configuration source type ID not set"); //$NON-NLS-1$
}
if (fName.isBlank()) {
throw new IllegalStateException("Configuration source type name not set"); //$NON-NLS-1$
}
return new TmfConfigurationSourceType(this);
}
}
}