Skip to content

Commit 0e84ce5

Browse files
committed
Add alias methods to ProblemBuilder
Existing methods are confusing as they have singular name but take plural argument.
1 parent 149222a commit 0e84ce5

File tree

2 files changed

+61
-6
lines changed

2 files changed

+61
-6
lines changed

src/main/java/io/github/problem4j/core/AbstractProblemBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public ProblemBuilder extension(String name, Object value) {
193193
* @return this builder instance for chaining
194194
*/
195195
@Override
196-
public ProblemBuilder extension(Map<String, Object> extensions) {
196+
public ProblemBuilder extensions(Map<String, Object> extensions) {
197197
if (extensions != null && !extensions.isEmpty()) {
198198
extensions.forEach(
199199
(key, value) -> {
@@ -212,7 +212,7 @@ public ProblemBuilder extension(Map<String, Object> extensions) {
212212
* @return this builder instance for chaining
213213
*/
214214
@Override
215-
public ProblemBuilder extension(Problem.Extension... extensions) {
215+
public ProblemBuilder extensions(Problem.Extension... extensions) {
216216
if (extensions != null && extensions.length > 0) {
217217
Stream.of(extensions)
218218
.filter(AbstractProblemBuilder::isExtensionValid)
@@ -228,7 +228,7 @@ public ProblemBuilder extension(Problem.Extension... extensions) {
228228
* @return this builder instance for chaining
229229
*/
230230
@Override
231-
public ProblemBuilder extension(Collection<? extends Problem.Extension> extensions) {
231+
public ProblemBuilder extensions(Collection<? extends Problem.Extension> extensions) {
232232
if (extensions != null && !extensions.isEmpty()) {
233233
extensions.stream()
234234
.filter(AbstractProblemBuilder::isExtensionValid)

src/main/java/io/github/problem4j/core/ProblemBuilder.java

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,33 @@ public interface ProblemBuilder {
113113
* @param extensions map of extension keys and values
114114
* @return this builder instance for chaining
115115
*/
116-
ProblemBuilder extension(Map<String, Object> extensions);
116+
ProblemBuilder extensions(Map<String, Object> extensions);
117+
118+
/**
119+
* Adds multiple custom extensions from varargs of {@link Problem.Extension}.
120+
*
121+
* @param extension array of extensions
122+
* @return this builder instance for chaining
123+
*/
124+
default ProblemBuilder extension(Problem.Extension extension) {
125+
return extensions(extension);
126+
}
117127

118128
/**
119129
* Adds multiple custom extensions from varargs of {@link Problem.Extension}.
120130
*
121131
* @param extensions array of extensions
122132
* @return this builder instance for chaining
123133
*/
124-
ProblemBuilder extension(Problem.Extension... extensions);
134+
ProblemBuilder extensions(Problem.Extension... extensions);
125135

126136
/**
127137
* Adds multiple custom extensions from a collection of {@link Problem.Extension}.
128138
*
129139
* @param extensions collection of extensions
130140
* @return this builder instance for chaining
131141
*/
132-
ProblemBuilder extension(Collection<? extends Problem.Extension> extensions);
142+
ProblemBuilder extensions(Collection<? extends Problem.Extension> extensions);
133143

134144
/**
135145
* Builds an immutable {@link Problem} instance with the configured properties and extensions.
@@ -151,4 +161,49 @@ public interface ProblemBuilder {
151161
* @return a new {@link Problem} instance
152162
*/
153163
Problem build();
164+
165+
/**
166+
* Adds multiple custom extensions from a map.
167+
*
168+
* <p><b>Deprecated</b> due to confusing name as singular "extension" suggests adding a single
169+
* extension, while the method actually adds multiple extensions from the provided map.
170+
*
171+
* @param extensions map of extension keys and values
172+
* @return this builder instance for chaining
173+
* @deprecated use {@link #extensions(Map)} instead
174+
*/
175+
@Deprecated
176+
default ProblemBuilder extension(Map<String, Object> extensions) {
177+
return extensions(extensions);
178+
}
179+
180+
/**
181+
* Adds multiple custom extensions from varargs of {@link Problem.Extension}.
182+
*
183+
* <p><b>Deprecated</b> due to confusing name as singular "extension" suggests adding a single
184+
* extension, while the method actually adds multiple extensions from the provided vararg.
185+
*
186+
* @param extensions array of extensions
187+
* @return this builder instance for chaining
188+
* @deprecated use {@link #extensions(Problem.Extension...)} instead
189+
*/
190+
@Deprecated
191+
default ProblemBuilder extension(Problem.Extension... extensions) {
192+
return extensions(extensions);
193+
}
194+
195+
/**
196+
* Adds multiple custom extensions from a collection of {@link Problem.Extension}.
197+
*
198+
* <p><b>Deprecated</b> due to confusing name as singular "extension" suggests adding a single
199+
* extension, while the method actually adds multiple extensions from the provided collection.
200+
*
201+
* @param extensions collection of extensions
202+
* @return this builder instance for chaining
203+
* @deprecated use {@link #extensions(Collection)} instead
204+
*/
205+
@Deprecated
206+
default ProblemBuilder extension(Collection<? extends Problem.Extension> extensions) {
207+
return extensions(extensions);
208+
}
154209
}

0 commit comments

Comments
 (0)