Skip to content

Commit 1901634

Browse files
Add convenience static factory methods to Problem
Similar case to previous commit with overrides for ctors.
1 parent da40e24 commit 1901634

2 files changed

Lines changed: 498 additions & 1 deletion

File tree

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

Lines changed: 306 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,312 @@ static ProblemBuilder builder() {
6565
return new ProblemBuilderImpl();
6666
}
6767

68+
/**
69+
* Creates a new {@link Problem} instance with the given HTTP status code.
70+
*
71+
* @param status the HTTP status code applicable to this problem
72+
* @return a new {@link Problem} instance
73+
*/
74+
static Problem of(int status) {
75+
return builder().status(status).build();
76+
}
77+
78+
/**
79+
* Creates a new {@link Problem} instance with the given {@link ProblemStatus}.
80+
*
81+
* @param status the {@link ProblemStatus} applicable to this problem
82+
* @return a new {@link Problem} instance
83+
*/
84+
static Problem of(ProblemStatus status) {
85+
return builder().status(status).build();
86+
}
87+
88+
/**
89+
* Creates a new {@link Problem} instance with the given details.
90+
*
91+
* @param title a short, human-readable summary of the problem
92+
* @param status the HTTP status code applicable to this problem
93+
* @return a new {@link Problem} instance
94+
*/
95+
static Problem of(String title, int status) {
96+
return builder().title(title).status(status).build();
97+
}
98+
99+
/**
100+
* Creates a new {@link Problem} instance with the given details.
101+
*
102+
* @param title a short, human-readable summary of the problem
103+
* @param status the HTTP status code applicable to this problem
104+
* @param instance a URI reference that identifies the specific occurrence of the problem
105+
* @return a new {@link Problem} instance
106+
*/
107+
static Problem of(String title, int status, @Nullable URI instance) {
108+
return builder().title(title).status(status).instance(instance).build();
109+
}
110+
111+
/**
112+
* Creates a new {@link Problem} instance with the given details.
113+
*
114+
* @param title a short, human-readable summary of the problem
115+
* @param status the HTTP status code applicable to this problem
116+
* @param extensions a map of additional, application-specific properties to include in the
117+
* problem; a defensive copy is made, so changes to the original map do not affect this
118+
* instance
119+
* @return a new {@link Problem} instance
120+
*/
121+
static Problem of(String title, int status, @Nullable Map<String, @Nullable Object> extensions) {
122+
return builder().title(title).status(status).extensions(extensions).build();
123+
}
124+
125+
/**
126+
* Creates a new {@link Problem} instance with the given details.
127+
*
128+
* @param title a short, human-readable summary of the problem
129+
* @param status the HTTP status code applicable to this problem
130+
* @param instance a URI reference that identifies the specific occurrence of the problem
131+
* @param extensions a map of additional, application-specific properties to include in the
132+
* problem; a defensive copy is made, so changes to the original map do not affect this
133+
* instance
134+
* @return a new {@link Problem} instance
135+
*/
136+
static Problem of(
137+
String title,
138+
int status,
139+
@Nullable URI instance,
140+
@Nullable Map<String, @Nullable Object> extensions) {
141+
return builder().title(title).status(status).instance(instance).extensions(extensions).build();
142+
}
143+
144+
/**
145+
* Creates a new {@link Problem} instance with the given details.
146+
*
147+
* @param title a short, human-readable summary of the problem
148+
* @param status the HTTP status code applicable to this problem
149+
* @param detail a human-readable explanation specific to this occurrence of the problem
150+
* @return a new {@link Problem} instance
151+
*/
152+
static Problem of(String title, int status, @Nullable String detail) {
153+
return builder().title(title).status(status).detail(detail).build();
154+
}
155+
156+
/**
157+
* Creates a new {@link Problem} instance with the given details.
158+
*
159+
* @param title a short, human-readable summary of the problem
160+
* @param status the HTTP status code applicable to this problem
161+
* @param detail a human-readable explanation specific to this occurrence of the problem
162+
* @param instance a URI reference that identifies the specific occurrence of the problem
163+
* @return a new {@link Problem} instance
164+
*/
165+
static Problem of(String title, int status, @Nullable String detail, @Nullable URI instance) {
166+
return builder().title(title).status(status).detail(detail).instance(instance).build();
167+
}
168+
169+
/**
170+
* Creates a new {@link Problem} instance with the given details.
171+
*
172+
* @param title a short, human-readable summary of the problem
173+
* @param status the HTTP status code applicable to this problem
174+
* @param detail a human-readable explanation specific to this occurrence of the problem
175+
* @param extensions a map of additional, application-specific properties to include in the
176+
* problem; a defensive copy is made, so changes to the original map do not affect this
177+
* instance
178+
* @return a new {@link Problem} instance
179+
*/
180+
static Problem of(
181+
String title,
182+
int status,
183+
@Nullable String detail,
184+
@Nullable Map<String, @Nullable Object> extensions) {
185+
return builder().title(title).status(status).detail(detail).extensions(extensions).build();
186+
}
187+
188+
/**
189+
* Creates a new {@link Problem} instance with the given details.
190+
*
191+
* @param title a short, human-readable summary of the problem
192+
* @param status the HTTP status code applicable to this problem
193+
* @param detail a human-readable explanation specific to this occurrence of the problem
194+
* @param instance a URI reference that identifies the specific occurrence of the problem
195+
* @param extensions a map of additional, application-specific properties to include in the
196+
* problem; a defensive copy is made, so changes to the original map do not affect this
197+
* instance
198+
* @return a new {@link Problem} instance
199+
*/
200+
static Problem of(
201+
String title,
202+
int status,
203+
@Nullable String detail,
204+
@Nullable URI instance,
205+
@Nullable Map<String, @Nullable Object> extensions) {
206+
return builder()
207+
.title(title)
208+
.status(status)
209+
.detail(detail)
210+
.instance(instance)
211+
.extensions(extensions)
212+
.build();
213+
}
214+
215+
/**
216+
* Creates a new {@link Problem} instance with the given details.
217+
*
218+
* @param type the URI that identifies the type of the problem
219+
* @param title a short, human-readable summary of the problem
220+
* @param status the HTTP status code applicable to this problem
221+
* @return a new {@link Problem} instance
222+
*/
223+
static Problem of(URI type, String title, int status) {
224+
return builder().type(type).title(title).status(status).build();
225+
}
226+
227+
/**
228+
* Creates a new {@link Problem} instance with the given details.
229+
*
230+
* @param type the URI that identifies the type of the problem
231+
* @param title a short, human-readable summary of the problem
232+
* @param status the HTTP status code applicable to this problem
233+
* @param instance a URI reference that identifies the specific occurrence of the problem
234+
* @return a new {@link Problem} instance
235+
*/
236+
static Problem of(URI type, String title, int status, @Nullable URI instance) {
237+
return builder().type(type).title(title).status(status).instance(instance).build();
238+
}
239+
240+
/**
241+
* Creates a new {@link Problem} instance with the given details.
242+
*
243+
* @param type the URI that identifies the type of the problem
244+
* @param title a short, human-readable summary of the problem
245+
* @param status the HTTP status code applicable to this problem
246+
* @param extensions a map of additional, application-specific properties to include in the
247+
* problem; a defensive copy is made, so changes to the original map do not affect this
248+
* instance
249+
* @return a new {@link Problem} instance
250+
*/
251+
static Problem of(
252+
URI type, String title, int status, @Nullable Map<String, @Nullable Object> extensions) {
253+
return builder().type(type).title(title).status(status).extensions(extensions).build();
254+
}
255+
256+
/**
257+
* Creates a new {@link Problem} instance with the given details.
258+
*
259+
* @param type the URI that identifies the type of the problem
260+
* @param title a short, human-readable summary of the problem
261+
* @param status the HTTP status code applicable to this problem
262+
* @param instance a URI reference that identifies the specific occurrence of the problem
263+
* @param extensions a map of additional, application-specific properties to include in the
264+
* problem; a defensive copy is made, so changes to the original map do not affect this
265+
* instance
266+
* @return a new {@link Problem} instance
267+
*/
268+
static Problem of(
269+
URI type,
270+
String title,
271+
int status,
272+
@Nullable URI instance,
273+
@Nullable Map<String, @Nullable Object> extensions) {
274+
return builder()
275+
.type(type)
276+
.title(title)
277+
.status(status)
278+
.instance(instance)
279+
.extensions(extensions)
280+
.build();
281+
}
282+
283+
/**
284+
* Creates a new {@link Problem} instance with the given details.
285+
*
286+
* @param type the URI that identifies the type of the problem
287+
* @param title a short, human-readable summary of the problem
288+
* @param status the HTTP status code applicable to this problem
289+
* @param detail a human-readable explanation specific to this occurrence of the problem
290+
* @return a new {@link Problem} instance
291+
*/
292+
static Problem of(URI type, String title, int status, @Nullable String detail) {
293+
return builder().type(type).title(title).status(status).detail(detail).build();
294+
}
295+
296+
/**
297+
* Creates a new {@link Problem} instance with the given details.
298+
*
299+
* @param type the URI that identifies the type of the problem
300+
* @param title a short, human-readable summary of the problem
301+
* @param status the HTTP status code applicable to this problem
302+
* @param detail a human-readable explanation specific to this occurrence of the problem
303+
* @param instance a URI reference that identifies the specific occurrence of the problem
304+
* @return a new {@link Problem} instance
305+
*/
306+
static Problem of(
307+
URI type, String title, int status, @Nullable String detail, @Nullable URI instance) {
308+
return builder()
309+
.type(type)
310+
.title(title)
311+
.status(status)
312+
.detail(detail)
313+
.instance(instance)
314+
.build();
315+
}
316+
317+
/**
318+
* Creates a new {@link Problem} instance with the given details.
319+
*
320+
* @param type the URI that identifies the type of the problem
321+
* @param title a short, human-readable summary of the problem
322+
* @param status the HTTP status code applicable to this problem
323+
* @param detail a human-readable explanation specific to this occurrence of the problem
324+
* @param extensions a map of additional, application-specific properties to include in the
325+
* problem; a defensive copy is made, so changes to the original map do not affect this
326+
* instance
327+
* @return a new {@link Problem} instance
328+
*/
329+
static Problem of(
330+
URI type,
331+
String title,
332+
int status,
333+
@Nullable String detail,
334+
@Nullable Map<String, @Nullable Object> extensions) {
335+
return builder()
336+
.type(type)
337+
.title(title)
338+
.status(status)
339+
.detail(detail)
340+
.extensions(extensions)
341+
.build();
342+
}
343+
344+
/**
345+
* Creates a new {@link Problem} instance with the given details.
346+
*
347+
* @param type the URI that identifies the type of the problem
348+
* @param title a short, human-readable summary of the problem
349+
* @param status the HTTP status code applicable to this problem
350+
* @param detail a human-readable explanation specific to this occurrence of the problem
351+
* @param instance a URI reference that identifies the specific occurrence of the problem
352+
* @param extensions a map of additional, application-specific properties to include in the
353+
* problem; a defensive copy is made, so changes to the original map do not affect this
354+
* instance
355+
* @return a new {@link Problem} instance
356+
*/
357+
static Problem of(
358+
URI type,
359+
String title,
360+
int status,
361+
@Nullable String detail,
362+
@Nullable URI instance,
363+
@Nullable Map<String, @Nullable Object> extensions) {
364+
return builder()
365+
.type(type)
366+
.title(title)
367+
.status(status)
368+
.detail(detail)
369+
.instance(instance)
370+
.extensions(extensions)
371+
.build();
372+
}
373+
68374
/**
69375
* Creates a named extension for use in a {@link Problem}.
70376
*

0 commit comments

Comments
 (0)