Skip to content

Commit

Permalink
Cleaned up some PMD and compile warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
david-waltermire committed Jan 24, 2024
1 parent c2b64dd commit cd8ce6f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void registerFunction(@NonNull IFunction function) {
registerFunctionByName(function);
}

protected void registerFunctionByQName(@NonNull IFunction function) {
private void registerFunctionByQName(@NonNull IFunction function) {
QName qname = function.getQName();
IFunction duplicate;
synchronized (this) {
Expand All @@ -75,7 +75,7 @@ protected void registerFunctionByQName(@NonNull IFunction function) {
}
}

protected void registerFunctionByName(@NonNull IFunction function) {
private void registerFunctionByName(@NonNull IFunction function) {
String name = function.getName();
synchronized (this) {
NamedFunctionSet functions = libraryByName.get(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public Level getHighestSeverity() {
return highestLevel;
}

/**
* Add a finding to the collection of findings maintained by this instance.
*
* @param finding
* the finding to add
*/
protected void addFinding(@NonNull ConstraintValidationFinding finding) {
findings.add(finding);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public void writeItemFieldValue(Object parentItem, IBoundFieldValue fieldValue)
item = fieldValue.getDefaultValue();
}
} else if (item.equals(fieldValue.getResolvedDefaultValue())) {
// same as default
item = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public static <A extends Annotation> A getAnnotation(
@Nullable
public static String resolveNoneOrDefault(@Nullable String value, @Nullable String defaultValue) {
String retval;
if (value == null || ModelUtil.DEFAULT_STRING_VALUE.equals(value)) {
if (value == null || DEFAULT_STRING_VALUE.equals(value)) {
retval = defaultValue;
} else if (ModelUtil.NO_STRING_VALUE.equals(value)) {
} else if (NO_STRING_VALUE.equals(value)) {
retval = null; // NOPMD - intentional
} else {
retval = value;
Expand Down Expand Up @@ -136,10 +136,10 @@ public static String resolveNamespace(String annotationValue) {
*/
private static String resolveNamespace(String value, boolean allowNone) {
String retval;
if (value == null || ModelUtil.DEFAULT_STRING_VALUE.equals(value)) {
if (value == null || DEFAULT_STRING_VALUE.equals(value)) {
// get namespace from the metaschema
retval = null;
} else if (allowNone && ModelUtil.NO_STRING_VALUE.equals(value)) {
} else if (allowNone && NO_STRING_VALUE.equals(value)) {
retval = ""; // NOPMD - intentional
} else {
retval = value;
Expand All @@ -157,7 +157,7 @@ private static String resolveNamespace(String value, boolean allowNone) {
*/
@Nullable
public static String resolveNoneOrValue(@NonNull String value) {
return ModelUtil.NO_STRING_VALUE.equals(value) ? null : value;
return NO_STRING_VALUE.equals(value) ? null : value;
}

/**
Expand Down Expand Up @@ -202,7 +202,7 @@ public static IDataTypeAdapter<?> getDataTypeAdapter(
@Nullable
public static Object resolveDefaultValue(@NonNull String defaultValue, IDataTypeAdapter<?> adapter) {
Object retval = null;
if (!ModelUtil.NULL_VALUE.equals(defaultValue)) {
if (!NULL_VALUE.equals(defaultValue)) {
retval = adapter.parse(defaultValue);
}
return retval;
Expand All @@ -215,14 +215,14 @@ public static Integer resolveNullOrInteger(int value) {
public static Object resolveNullOrValue(
@NonNull String defaultValue,
@NonNull IDataTypeAdapter<?> javaTypeAdapter) {
return ModelUtil.NULL_VALUE.equals(defaultValue)
return NULL_VALUE.equals(defaultValue)
? null
: javaTypeAdapter.parse(defaultValue);
}

@NonNull
public static IGroupAs groupAs(@NonNull GroupAs groupAs) {
return ModelUtil.NULL_VALUE.equals(groupAs.name())
return NULL_VALUE.equals(groupAs.name())
? IGroupAs.SINGLETON_GROUP_AS
: new DefaultGroupAs(groupAs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,13 @@ public DefinitionAssembly(

String rootLocalName = ModelUtil.resolveNoneOrDefault(getAnnotation().rootName(), null);
this.xmlRootQName = ObjectUtils.notNull(Lazy.lazy(() -> {
QName retval;
if (rootLocalName == null) {
retval = null;
} else {
QName retval = null;
if (rootLocalName != null) {
String namespace = ModelUtil.resolveOptionalNamespace(getAnnotation().rootNamespace());
if (namespace == null) {
namespace = getContainingModule().getXmlNamespace().toASCIIString();
}
retval = new QName(
namespace,
rootLocalName);
retval = new QName(namespace, rootLocalName);
}
return retval;
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

package gov.nist.secauto.metaschema.databind.codegen;

import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import gov.nist.secauto.metaschema.core.model.MetaschemaException;
Expand All @@ -50,7 +51,8 @@ void testOscalBindingModuleLoader() throws MetaschemaException, IOException {
IBindingModule module = loader.load(ObjectUtils.notNull(URI.create(
"https://raw.githubusercontent.com/usnistgov/OSCAL/main/src/metaschema/oscal_complete_metaschema.xml")));
IBindingContext context = IBindingContext.instance().registerModule(module, Paths.get("target/oscal-classes"));

assertNotNull(module);
assertAll(
() -> assertNotNull(module),
() -> assertNotNull(context));
}
}

0 comments on commit cd8ce6f

Please sign in to comment.