/
TmfConfigParamDescriptor.java
171 lines (152 loc) · 5.02 KB
/
TmfConfigParamDescriptor.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
/*******************************************************************************
* 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.Objects;
import org.eclipse.jdt.annotation.Nullable;
/**
* Implementation of {@link ITmfConfigParamDescriptor} interface. It provides a
* builder class to create instances of that interface.
*
* @author Bernd Hufmann
* @since 9.2
*/
public class TmfConfigParamDescriptor implements ITmfConfigParamDescriptor {
private final String fKeyName;
private final String fDescription;
private final String fDataType;
private final boolean fIsRequired;
/**
* Constructor
*
* @param bulider
* the builder object to create the descriptor
*/
private TmfConfigParamDescriptor(Builder builder) {
fKeyName = builder.fKeyName;
fDescription = builder.fDescription;
fDataType = builder.fDataType;
fIsRequired = builder.fIsRequired;
}
@Override
public String getKeyName() {
return fKeyName;
}
@Override
public String getDataType() {
return fDataType;
}
@Override
public boolean isRequired() {
return fIsRequired;
}
@Override
public String getDescription() {
return fDescription;
}
@Override
@SuppressWarnings("nls")
public String toString() {
return new StringBuilder(getClass().getSimpleName())
.append("[")
.append("fKeyName=").append(getKeyName())
.append(", fDataType=").append(getDataType())
.append(", fIsRequired=").append(isRequired())
.append(", fDescription=").append(getDescription())
.append("]").toString();
}
@Override
public boolean equals(@Nullable Object arg0) {
if (!(arg0 instanceof TmfConfigParamDescriptor)) {
return false;
}
TmfConfigParamDescriptor other = (TmfConfigParamDescriptor) arg0;
return Objects.equals(fKeyName, other.fKeyName)
&& Objects.equals(fDataType, other.fDataType)
&& Objects.equals(fDescription, other.fDescription)
&& Objects.equals(fIsRequired, other.fIsRequired);
}
@Override
public int hashCode() {
return Objects.hash(fKeyName, fIsRequired, fDataType, fDescription);
}
/**
* A builder class to build instances implementing interface
* {@link ITmfConfigParamDescriptor}
*/
public static class Builder {
private String fKeyName = ""; //$NON-NLS-1$
private String fDescription = ""; //$NON-NLS-1$ ;
private String fDataType = "STRING"; //$NON-NLS-1$
private boolean fIsRequired = true;
/**
* Constructor
*/
public Builder() {
// Empty constructor
}
/**
* Sets the data type string of the configuration parameter.
*
* @param dataType
* the ID to set
* @return the builder instance.
*/
public Builder setDataType(String dataType) {
fDataType = dataType;
return this;
}
/**
* Sets the unique key name of the configuration parameter.
*
* @param keyName
* the name to set
* @return the builder instance.
*/
public Builder setKeyName(String keyName) {
fKeyName = keyName;
return this;
}
/**
* Sets the description of the configuration parameter.
*
* @param description
* the description text to set
* @return the builder instance.
*/
public Builder setDescription(String description) {
fDescription = description;
return this;
}
/**
* Sets the isRequired flag of the configuration parameter.
*
* @param isRequired
* the is required flag.
* @return the builder instance.
*/
public Builder setIsRequired(boolean isRequired) {
fIsRequired = isRequired;
return this;
}
/**
* The method to construct an instance of {@link ITmfConfiguration}
*
* @return a {@link ITmfConfiguration} instance
*/
public ITmfConfigParamDescriptor build() {
String keyName = fKeyName;
if (keyName.isBlank()) {
throw new IllegalStateException("The key name of the configuration parameter is not set"); //$NON-NLS-1$
}
return new TmfConfigParamDescriptor(this);
}
}
}