Skip to content

Commit 574815b

Browse files
committed
#121 Add Missing JavaDoc
Signed-off-by: Sven Strittmatter <[email protected]>
1 parent 5aa53f7 commit 574815b

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

src/main/java/io/securecodebox/persistence/defectdojo/model/Model.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,15 @@
66
* Interface for all models
77
*/
88
public interface Model {
9+
/**
10+
* Compares this model with the given query parameters
11+
* <p>
12+
* The given query parameters are name value pairs, e.g.:
13+
* </p>
14+
*
15+
* TODO: Should we annotate queryParams with {@code @NonNull}?
16+
* @param queryParams may be {@code null}
17+
* @return {@code true} if equal, elas {@code false}
18+
*/
919
boolean equalsQueryString(Map<String, Object> queryParams);
1020
}

src/main/java/io/securecodebox/persistence/defectdojo/model/QueryParamsComparator.java

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,55 @@
1414
* </p>
1515
*/
1616
final class QueryParamsComparator {
17-
17+
/**
18+
* Query parameter name for id
19+
*/
1820
static final String QUERY_PARAM_KEY_FOR_ID = "id";
21+
/**
22+
* Query parameter name for name
23+
*/
1924
static final String QUERY_PARAM_KEY_FOR_NAME = "name";
2025

26+
/**
27+
* Hidden for pure static helper class
28+
*/
2129
private QueryParamsComparator() {
2230
super();
2331
}
2432

33+
/**
34+
* Determines whether the given object is {@code null} or not
35+
*
36+
* @param o maybe {@code null}
37+
* @return {@code true} if {@code o} is {@code null}, else {@code false}
38+
*/
2539
static boolean isNull(Object o) {
2640
return o == null;
2741
}
2842

43+
/**
44+
* Determines whether the {@link HasId id} of the given model object is equal the given {@link #QUERY_PARAM_KEY_FOR_ID id}
45+
* <p>
46+
* Example:
47+
* </p>
48+
* <pre>
49+
* {@code
50+
* final var model = ...
51+
* final var queryParams = new HashMap<String, Object>();
52+
* queryParams.put(QueryParamsComparator.QUERY_PARAM_KEY_FOR_ID, 42);
53+
*
54+
* if (QueryParamsComparator.isIdEqual(model, queryParams)) {
55+
* ...
56+
* }
57+
* }
58+
* </pre>
59+
* <p>
60+
* TODO: What about type conversions? The id is a long in the models, but it may be a string in the map. Should it be treated as equal (42 == "42")?
61+
*
62+
* @param model may be {@code null}
63+
* @param queryParams may be {@code null}
64+
* @return {@code true} id id is equal, else {@code false}
65+
*/
2966
static boolean isIdEqual(HasId model, Map<String, Object> queryParams) {
3067
if (isNull(model)) {
3168
return false;
@@ -46,6 +83,28 @@ static boolean isIdEqual(HasId model, Map<String, Object> queryParams) {
4683
return queryParams.get(QUERY_PARAM_KEY_FOR_ID).equals(model.getId());
4784
}
4885

86+
/**
87+
* Determines whether the {@link HasName name} of the given model object is equal the given {@link #QUERY_PARAM_KEY_FOR_NAME name}
88+
* <p>
89+
* Example:
90+
* </p>
91+
* <pre>
92+
* {@code
93+
* final var model = ...
94+
* final var queryParams = new HashMap<String, Object>();
95+
* queryParams.put(QueryParamsComparator.QUERY_PARAM_KEY_FOR_NAME, "foo");
96+
*
97+
* if (QueryParamsComparator.isNameEqual(model, queryParams)) {
98+
* ...
99+
* }
100+
* }
101+
* </pre>
102+
* <p>
103+
*
104+
* @param model may be {@code null}
105+
* @param queryParams may be {@code null}
106+
* @return {@code true} if name is equal, else {@code false}
107+
*/
49108
static boolean isNameEqual(HasName model, Map<String, Object> queryParams) {
50109
if (isNull(model)) {
51110
return false;

src/main/java/io/securecodebox/persistence/defectdojo/service/GenericDefectDojoService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
import java.net.URISyntaxException;
3838
import java.util.*;
3939

40+
/**
41+
* Generic base implementation with common functionality shared by services
42+
*
43+
* @param <T> type of model the service handles
44+
*/
4045
@Slf4j
4146
abstract class GenericDefectDojoService<T extends Model> implements DefectDojoService<T> {
4247
private static final String API_PREFIX = "/api/v2/";

0 commit comments

Comments
 (0)