-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#23 Reduce code duplication in equalsQueryString() implememtations
Signed-off-by: Sven Strittmatter <[email protected]>
- Loading branch information
1 parent
324a497
commit cb75f1f
Showing
16 changed files
with
291 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/io/securecodebox/persistence/defectdojo/model/HasId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-FileCopyrightText: the secureCodeBox authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package io.securecodebox.persistence.defectdojo.model; | ||
|
||
/** | ||
* Interface to mark {@link Model models} which have an id | ||
* <p> | ||
* This type is package private because it is an implementation detail of the models and | ||
* z should not be used outside of this package. | ||
* </p> | ||
*/ | ||
interface HasId { | ||
long getId(); | ||
|
||
void setId(long id); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/io/securecodebox/persistence/defectdojo/model/HasName.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-FileCopyrightText: the secureCodeBox authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package io.securecodebox.persistence.defectdojo.model; | ||
|
||
/** | ||
* Interface to mark {@link Model models} which have a name | ||
* <p> | ||
* This type is package private because it is an implementation detail of the models and | ||
* z should not be used outside of this package. | ||
* </p> | ||
*/ | ||
interface HasName { | ||
String getName(); | ||
|
||
void setName(String id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/io/securecodebox/persistence/defectdojo/model/QueryParamsComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// SPDX-FileCopyrightText: the secureCodeBox authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package io.securecodebox.persistence.defectdojo.model; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Pure static helper class | ||
* <p> | ||
* This type is package private because it is an implementation detail of the models and | ||
* should not be used outside of this package. | ||
* </p> | ||
*/ | ||
final class QueryParamsComparator { | ||
|
||
static final String QUERY_PARAM_KEY_FOR_ID = "id"; | ||
static final String QUERY_PARAM_KEY_FOR_NAME = "name"; | ||
|
||
private QueryParamsComparator() { | ||
super(); | ||
} | ||
|
||
static boolean isNull(Object o) { | ||
return o == null; | ||
} | ||
|
||
static boolean isIdEqual(HasId model, Map<String, Object> queryParams) { | ||
if (isNull(model)) { | ||
return false; | ||
} | ||
|
||
if (isNull(queryParams)) { | ||
return false; | ||
} | ||
|
||
if (!queryParams.containsKey(QUERY_PARAM_KEY_FOR_ID)) { | ||
return false; | ||
} | ||
|
||
// FIXME: Since th generic type for value is Object, possible NPE here! | ||
return queryParams.get(QUERY_PARAM_KEY_FOR_ID).equals(model.getId()); | ||
} | ||
|
||
static boolean isNameEqual(HasName model, Map<String, Object> queryParams) { | ||
if (isNull(model)) { | ||
return false; | ||
} | ||
|
||
if (isNull(queryParams)) { | ||
return false; | ||
} | ||
|
||
if (!queryParams.containsKey(QUERY_PARAM_KEY_FOR_NAME)) { | ||
return false; | ||
} | ||
|
||
if (isNull(queryParams.get(QUERY_PARAM_KEY_FOR_NAME))) { | ||
return false; | ||
} | ||
|
||
return queryParams.get(QUERY_PARAM_KEY_FOR_NAME).equals(model.getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.