From faa2006f6a7932105ee06909c7eb65fb883cc550 Mon Sep 17 00:00:00 2001 From: David Waltermire Date: Thu, 27 Oct 2022 09:52:52 -0400 Subject: [PATCH] Adjusting code formatting. Suppressing false PMD errors. --- pom.xml | 2 +- .../oscal/lib/OscalBindingContext.java | 2 +- .../nist/secauto/oscal/lib/OscalUtils.java | 2 +- .../function/library/HasOscalNamespace.java | 10 +++---- .../function/library/ResolveProfile.java | 4 +-- .../lib/model/control/AbstractParameter.java | 12 ++++----- .../oscal/lib/model/control/AbstractPart.java | 14 +++++----- .../control/catalog/AbstractControl.java | 6 ++--- .../lib/model/metadata/AbstractProperty.java | 10 +++---- .../profile/resolver/ModifyPhaseUtils.java | 6 ++--- .../lib/profile/resolver/ProfileResolver.java | 4 +-- .../profile/resolver/alter/AddVisitor.java | 6 ++--- .../profile/resolver/alter/RemoveVisitor.java | 8 +++--- .../merge/FlatteningStructuringVisitor.java | 27 ++++++++++--------- .../policy/AbstractCustomReferencePolicy.java | 4 +-- .../policy/ReferenceCountingVisitor.java | 4 +-- .../selection/ControlSelectionVisitor.java | 6 ++--- .../DefaultControlSelectionFilter.java | 2 +- .../resolver/selection/DefaultResult.java | 20 +++++++------- .../support/AbstractCatalogEntityVisitor.java | 10 +++---- .../support/AbstractCatalogVisitor.java | 1 - .../resolver/support/AbstractEntityItem.java | 6 ++--- .../resolver/support/ICatalogVisitor.java | 8 +++--- .../profile/resolver/support/IIndexer.java | 18 ++++++------- .../resolver/support/ReassignmentIndexer.java | 2 +- .../oscal/java/MetaschemaVisitorTest.java | 10 +++---- .../secauto/oscal/java/ReadWriteTest.java | 12 ++++----- .../oscal/lib/profile/resolver/TestUtil.java | 4 +-- .../DefaultControlSelectionFilterTest.java | 26 +++++++++--------- .../FilterNonSelectedVisitorTest.java | 5 ++-- .../resolver/selection/ImportTest.java | 2 +- 31 files changed, 127 insertions(+), 126 deletions(-) diff --git a/pom.xml b/pom.xml index 1a671bfc..f221a906 100644 --- a/pom.xml +++ b/pom.xml @@ -117,7 +117,7 @@ UTF-8 UTF-8 - 0.9.0 + 0.10.0 1.0.1 3.12.0 diff --git a/src/main/java/gov/nist/secauto/oscal/lib/OscalBindingContext.java b/src/main/java/gov/nist/secauto/oscal/lib/OscalBindingContext.java index 7ec0596e..6768a756 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/OscalBindingContext.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/OscalBindingContext.java @@ -200,7 +200,7 @@ public PlanOfActionAndMilestones loadPlanOfActionAndMilestones(@NonNull File fil private static class Matcher implements IBindingMatcher { @Override - public Class getBoundClassForXmlQName(QName startElementQName) { + public Class getBoundClassForXmlQName(QName startElementQName) { Class clazz = null; if ("http://csrc.nist.gov/ns/oscal/1.0".equals(startElementQName.getNamespaceURI())) { switch (startElementQName.getLocalPart()) { diff --git a/src/main/java/gov/nist/secauto/oscal/lib/OscalUtils.java b/src/main/java/gov/nist/secauto/oscal/lib/OscalUtils.java index 7ee58b58..f756d0a1 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/OscalUtils.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/OscalUtils.java @@ -58,7 +58,7 @@ private OscalUtils() { public static boolean isInternalReference(@NonNull URI uri) { if (uri.isAbsolute()) { - return false; + return false; } String schemeSpecificPart = uri.getSchemeSpecificPart(); diff --git a/src/main/java/gov/nist/secauto/oscal/lib/metapath/function/library/HasOscalNamespace.java b/src/main/java/gov/nist/secauto/oscal/lib/metapath/function/library/HasOscalNamespace.java index 3c8915e1..0b01497b 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/metapath/function/library/HasOscalNamespace.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/metapath/function/library/HasOscalNamespace.java @@ -101,12 +101,12 @@ public static ISequence executeOneArg( INodeItem focus) { INodeItem node = focus; if (node == null) { - return ISequence.empty(); + return ISequence.empty(); } ISequence namespaceArgs = FunctionUtils.asType(arguments.get(0)); if (namespaceArgs.isEmpty()) { - return ISequence.empty(); + return ISequence.empty(); } return ISequence.of(hasNamespace(FunctionUtils.asType(node), namespaceArgs)); @@ -123,19 +123,19 @@ public static ISequence executeTwoArg( IItem node = FunctionUtils.getFirstItem(nodeSequence, true); if (node == null) { - return ISequence.empty(); + return ISequence.empty(); } ISequence namespaceArgs = FunctionUtils.asType(arguments.get(1)); if (namespaceArgs.isEmpty()) { - return ISequence.empty(); + return ISequence.empty(); } return ISequence.of(hasNamespace(FunctionUtils.asType(node), namespaceArgs)); } @NonNull - public static IBooleanItem hasNamespace( + public static IBooleanItem hasNamespace( @NonNull IDefinitionNodeItem propOrPart, @NonNull ISequence namespaces) throws MetapathException { diff --git a/src/main/java/gov/nist/secauto/oscal/lib/metapath/function/library/ResolveProfile.java b/src/main/java/gov/nist/secauto/oscal/lib/metapath/function/library/ResolveProfile.java index da5dc2f5..aa761fdb 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/metapath/function/library/ResolveProfile.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/metapath/function/library/ResolveProfile.java @@ -87,7 +87,7 @@ public static ISequence executeNoArg( INodeItem item = focus; if (item == null) { - return ISequence.empty(); + return ISequence.empty(); } return ISequence.of(resolveProfile(FunctionUtils.asType(item), dynamicContext)); } @@ -103,7 +103,7 @@ public static ISequence executeOneArg( IItem item = FunctionUtils.getFirstItem(arg, true); if (item == null) { - return ISequence.empty(); + return ISequence.empty(); } return ISequence.of(resolveProfile(FunctionUtils.asType(item), dynamicContext)); diff --git a/src/main/java/gov/nist/secauto/oscal/lib/model/control/AbstractParameter.java b/src/main/java/gov/nist/secauto/oscal/lib/model/control/AbstractParameter.java index 11421a60..08e009ba 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/model/control/AbstractParameter.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/model/control/AbstractParameter.java @@ -87,16 +87,16 @@ public static class Builder { @NonNull private final String id; - private String clazz; + private String clazz; private final List props = new LinkedList<>(); private final List links = new LinkedList<>(); - private MarkupLine label; - private MarkupMultiline usage; + private MarkupLine label; + private MarkupMultiline usage; private final List constraints = new LinkedList<>(); private final List guidelines = new LinkedList<>(); - private List values = new LinkedList<>(); + private List values = new LinkedList<>(); private ParameterSelection selection; - private MarkupMultiline remarks; + private MarkupMultiline remarks; public Builder(@NonNull String id) { this.id = ObjectUtils.requireNonNull(id); @@ -179,7 +179,7 @@ public Builder remarks(@NonNull MarkupMultiline value) { } @NonNull - public Parameter build() { + public Parameter build() { Parameter retval = new Parameter(); retval.setId(id); diff --git a/src/main/java/gov/nist/secauto/oscal/lib/model/control/AbstractPart.java b/src/main/java/gov/nist/secauto/oscal/lib/model/control/AbstractPart.java index d0ab9aec..b2db50d1 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/model/control/AbstractPart.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/model/control/AbstractPart.java @@ -74,13 +74,13 @@ public static Builder builder(@NonNull String name) { } public static class Builder { - private String id; + private String id; @NonNull private final String name; - private URI namespace; - private String clazz; - private MarkupMultiline prose; - private MarkupLine title; + private URI namespace; + private String clazz; + private MarkupMultiline prose; + private MarkupLine title; private final List props = new LinkedList<>(); private final List links = new LinkedList<>(); private final List parts = new LinkedList<>(); @@ -90,7 +90,7 @@ public Builder(@NonNull String name) { } @NonNull - public Builder id(@NonNull String value) { + public Builder id(@NonNull String value) { this.id = Objects.requireNonNull(value); return this; } @@ -148,7 +148,7 @@ public Builder part(@NonNull ControlPart value) { } @NonNull - public ControlPart build() { + public ControlPart build() { ControlPart retval = new ControlPart(); retval.setName(name); diff --git a/src/main/java/gov/nist/secauto/oscal/lib/model/control/catalog/AbstractControl.java b/src/main/java/gov/nist/secauto/oscal/lib/model/control/catalog/AbstractControl.java index 9efbc314..7cee0236 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/model/control/catalog/AbstractControl.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/model/control/catalog/AbstractControl.java @@ -58,7 +58,7 @@ public void setParentControl(Control parent) { } @Override - public void beforeDeserialize(Object parent) { + public void beforeDeserialize(Object parent) { // NOPMD noop default // do nothing } @@ -101,8 +101,8 @@ public static class Builder { @NonNull private final String id; - private String clazz; - private MarkupLine title; + private String clazz; + private MarkupLine title; private final List params = new LinkedList<>(); private final List props = new LinkedList<>(); private final List links = new LinkedList<>(); diff --git a/src/main/java/gov/nist/secauto/oscal/lib/model/metadata/AbstractProperty.java b/src/main/java/gov/nist/secauto/oscal/lib/model/metadata/AbstractProperty.java index 3e9c00cf..5f92db17 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/model/metadata/AbstractProperty.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/model/metadata/AbstractProperty.java @@ -97,10 +97,10 @@ public static class Builder { @NonNull private final String name; - private UUID uuid; - private URI namespace; - private String value; - private String clazz; + private UUID uuid; + private URI namespace; + private String value; + private String clazz; public Builder(@NonNull String name) { this.name = Objects.requireNonNull(name, "name"); @@ -115,7 +115,7 @@ public Builder uuid(@NonNull UUID uuid) { @NonNull public Builder namespace(@NonNull URI namespace) { if (IProperty.OSCAL_NAMESPACE.equals(namespace)) { - this.namespace = null; + this.namespace = null; } else { this.namespace = Objects.requireNonNull(namespace); } diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/ModifyPhaseUtils.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/ModifyPhaseUtils.java index ce6810e7..4ef17d07 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/ModifyPhaseUtils.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/ModifyPhaseUtils.java @@ -64,7 +64,7 @@ public static Function identifierKey(@NonNull Function public static T mergeItem(@Nullable T original, @Nullable T additional) { if (additional == null) { - return original; + return original; } return additional; @@ -73,11 +73,11 @@ public static T mergeItem(@Nullable T original, @Nullable T additional) { public static List merge(@Nullable List original, @Nullable List additional, Function keyFunction) { if (additional == null || additional.isEmpty()) { - return original; + return original; } if (original == null || original.isEmpty()) { - return additional; + return additional; } // reverse the stream diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/ProfileResolver.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/ProfileResolver.java index faac524a..621e3f5f 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/ProfileResolver.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/ProfileResolver.java @@ -94,7 +94,7 @@ import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -public class ProfileResolver { +public class ProfileResolver { private static final Logger LOGGER = LogManager.getLogger(ProfileResolver.class); private static final MetapathExpression METAPATH_SET_PARAMETER = MetapathExpression.compile("/profile/modify/set-parameter"); @@ -343,7 +343,7 @@ protected IIndexer resolveImport( OscalBindingContext.instance().copyBoundObject(importedCatalog.getValue(), null), importedCatalog.getDocumentUri()); - IIndexer retval = new Import(profileDocument, profileImportItem) + IIndexer retval = new Import(profileDocument, profileImportItem) .resolve(importedCatalog, resolvedCatalog); return retval; diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/alter/AddVisitor.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/alter/AddVisitor.java index a0037179..e47720ac 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/alter/AddVisitor.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/alter/AddVisitor.java @@ -343,7 +343,7 @@ private static void handleCollection( // } // } - private static boolean handleChild( + private static boolean handleChild( @NonNull TargetType itemType, @NonNull Supplier> originalCollectionSupplier, @NonNull Supplier> newItemsSupplier, @@ -530,7 +530,7 @@ public boolean visitPart(ControlPart part, Context context) { return retval; } - static class Context { + static class Context { @NonNull private static final Set TITLE_TYPES = ObjectUtils.notNull( Set.of(TargetType.CONTROL, TargetType.PART)); @@ -566,7 +566,7 @@ static class Context { @NonNull private final Set targetItemTypes; - public Context( + public Context( @NonNull Control control, @NonNull Position position, @Nullable String byId, diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/alter/RemoveVisitor.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/alter/RemoveVisitor.java index ee27b5fe..29a142fb 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/alter/RemoveVisitor.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/alter/RemoveVisitor.java @@ -165,7 +165,7 @@ private static Set getApplicableTypes(@NonNull TargetType type) { return APPLICABLE_TARGETS.getOrDefault(type, CollectionUtil.emptySet()); } - private static boolean handle( + private static boolean handle( @NonNull TargetType itemType, @NonNull Supplier> supplier, @Nullable Function handler, @@ -220,7 +220,7 @@ private static boolean handle( * @throws ProfileResolutionEvaluationException * if a processing error occurred during profile resolution */ - public static boolean remove( + public static boolean remove( @NonNull Control control, @Nullable String objectName, @Nullable String objectClass, @@ -387,7 +387,7 @@ public boolean visitMappingEntry(MappingEntry map, Context context) { return retval; } - static class Context { + static class Context { /** * Types with an "name" flag. */ @@ -508,7 +508,7 @@ protected boolean checkValue(@Nullable String actual, @Nullable String expected) return expected == null || expected.equals(actual); } - public boolean isApplicableTo(@NonNull Object obj) { + public boolean isApplicableTo(@NonNull Object obj) { TargetType objectType = TargetType.forClass(obj.getClass()); boolean retval = objectType != null && getTargetItemTypes().contains(objectType); diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/merge/FlatteningStructuringVisitor.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/merge/FlatteningStructuringVisitor.java index 1880f0f6..2130f0fa 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/merge/FlatteningStructuringVisitor.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/merge/FlatteningStructuringVisitor.java @@ -99,7 +99,7 @@ public Void visitCatalog(@NonNull IDocumentNodeItem catalogItem, IIndexer index) @Override public Void visitGroup(IRequiredValueModelNodeItem item, Void childResult, IIndexer index) { - CatalogGroup group = (CatalogGroup)item.getValue(); + CatalogGroup group = (CatalogGroup) item.getValue(); String id = group.getId(); if (id != null) { IEntityItem entity = index.getEntity(ItemType.GROUP, id); @@ -115,7 +115,7 @@ public Void visitGroup(IRequiredValueModelNodeItem item, Void childResult, IInde @Override public Void visitControl(IRequiredValueModelNodeItem item, Void childResult, IIndexer index) { - Control control = (Control)item.getValue(); + Control control = (Control) item.getValue(); String id = ObjectUtils.requireNonNull(control.getId()); IEntityItem entity = index.getEntity(ItemType.CONTROL, id); assert entity != null; @@ -130,7 +130,7 @@ public Void visitControl(IRequiredValueModelNodeItem item, Void childResult, IIn @Override protected Void visitParameter(IRequiredValueModelNodeItem item, IRequiredValueModelNodeItem catalogOrGroupOrControl, IIndexer index) { - Parameter parameter = (Parameter)item.getValue(); + Parameter parameter = (Parameter) item.getValue(); String id = ObjectUtils.requireNonNull(parameter.getId()); IEntityItem entity = index.getEntity(ItemType.PARAMETER, id); assert entity != null; @@ -143,7 +143,7 @@ protected Void visitParameter(IRequiredValueModelNodeItem item, @Override protected void visitRole(IRequiredValueModelNodeItem item, IRequiredValueModelNodeItem metadataItem, IIndexer index) { - Role role = (Role)item.getValue(); + Role role = (Role) item.getValue(); String id = ObjectUtils.requireNonNull(role.getId()); IEntityItem entity = index.getEntity(ItemType.ROLE, id); assert entity != null; @@ -154,7 +154,7 @@ protected void visitRole(IRequiredValueModelNodeItem item, IRequiredValueModelNo @Override protected void visitLocation(IRequiredValueModelNodeItem item, IRequiredValueModelNodeItem metadataItem, IIndexer index) { - Location location = (Location)item.getValue(); + Location location = (Location) item.getValue(); UUID uuid = ObjectUtils.requireNonNull(location.getUuid()); IEntityItem entity = index.getEntity(ItemType.LOCATION, uuid); assert entity != null; @@ -165,7 +165,7 @@ protected void visitLocation(IRequiredValueModelNodeItem item, IRequiredValueMod @Override protected void visitParty(IRequiredValueModelNodeItem item, IRequiredValueModelNodeItem metadataItem, IIndexer index) { - Party location = (Party)item.getValue(); + Party location = (Party) item.getValue(); UUID uuid = ObjectUtils.requireNonNull(location.getUuid()); IEntityItem entity = index.getEntity(ItemType.PARTY, uuid); assert entity != null; @@ -176,7 +176,7 @@ protected void visitParty(IRequiredValueModelNodeItem item, IRequiredValueModelN @Override protected void visitResource(IRequiredValueModelNodeItem item, IRootAssemblyNodeItem rootItem, IIndexer index) { - Resource location = (Resource)item.getValue(); + Resource location = (Resource) item.getValue(); UUID uuid = ObjectUtils.requireNonNull(location.getUuid()); IEntityItem entity = index.getEntity(ItemType.RESOURCE, uuid); assert entity != null; @@ -192,8 +192,8 @@ private static void handlePartSelection( .map(item -> (IRequiredValueModelNodeItem) item) .forEachOrdered(partItem -> { index.setSelectionStatus(ObjectUtils.requireNonNull(partItem), selectionStatus); - - ControlPart part = (ControlPart)partItem.getValue(); + + ControlPart part = (ControlPart) partItem.getValue(); String id = part.getId(); if (id != null) { IEntityItem entity = index.getEntity(ItemType.PART, id); @@ -203,8 +203,9 @@ private static void handlePartSelection( } }); } - - private static class FlatteningFilterNonSelectedVisitor extends FilterNonSelectedVisitor { + + private static class FlatteningFilterNonSelectedVisitor + extends FilterNonSelectedVisitor { private static final FlatteningFilterNonSelectedVisitor SINGLETON = new FlatteningFilterNonSelectedVisitor(); public static FlatteningFilterNonSelectedVisitor instance() { @@ -215,7 +216,7 @@ public static FlatteningFilterNonSelectedVisitor instance() { public DefaultResult visitControl(IRequiredValueModelNodeItem item, DefaultResult childResult, Context context) { assert childResult != null; - + Control control = (Control) item.getValue(); IIndexer index = context.getIndexer(); // this control should always be found in the index @@ -238,7 +239,7 @@ public DefaultResult visitControl(IRequiredValueModelNodeItem item, DefaultResul } } else { // remove this control and promote any needed children - + if (SelectionStatus.SELECTED.equals(index.getSelectionStatus(parent))) { retval.removeControl(control); } diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/policy/AbstractCustomReferencePolicy.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/policy/AbstractCustomReferencePolicy.java index 858743d3..82b31b8a 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/policy/AbstractCustomReferencePolicy.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/policy/AbstractCustomReferencePolicy.java @@ -129,7 +129,7 @@ protected boolean handleIndexHit( * @throws ProfileResolutionEvaluationException * if there was an error handing the index hit */ - protected void handleUnselected( + protected void handleUnselected( // NOPMD noop default @NonNull IRequiredValueModelNodeItem contextItem, @NonNull TYPE reference, @NonNull IEntityItem item, @@ -153,7 +153,7 @@ protected void handleUnselected( * @throws ProfileResolutionEvaluationException * if there was an error handing the index hit */ - protected void handleSelected( + protected void handleSelected( // NOPMD noop default @NonNull IRequiredValueModelNodeItem contextItem, @NonNull TYPE reference, @NonNull IEntityItem item, diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/policy/ReferenceCountingVisitor.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/policy/ReferenceCountingVisitor.java index 1e14929b..1bc0f57d 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/policy/ReferenceCountingVisitor.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/policy/ReferenceCountingVisitor.java @@ -71,7 +71,7 @@ public class ReferenceCountingVisitor extends AbstractCatalogEntityVisitor - implements IReferenceVisitor { + implements IReferenceVisitor { private static final Logger LOGGER = LogManager.getLogger(ReferenceCountingVisitor.class); private static final ReferenceCountingVisitor SINGLETON = new ReferenceCountingVisitor(); @@ -270,7 +270,7 @@ protected void visitParts(@NonNull IRequiredValueModelNodeItem groupOrControlIte protected void visitPart(IRequiredValueModelNodeItem item, IRequiredValueModelNodeItem groupOrControlItem, Context context) { assert context != null; - + ControlPart part = (ControlPart) item.getValue(); String id = part.getId(); diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/ControlSelectionVisitor.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/ControlSelectionVisitor.java index 72d3ea2d..8aecb410 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/ControlSelectionVisitor.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/ControlSelectionVisitor.java @@ -66,13 +66,13 @@ public class ControlSelectionVisitor extends AbstractIndexingVisitor { private static final Logger LOGGER = LogManager.getLogger(ControlSelectionVisitor.class); - + private static final ControlSelectionVisitor SINGLETON = new ControlSelectionVisitor(); public static ControlSelectionVisitor instance() { return SINGLETON; } - + @Override protected IIndexer getIndexer(IControlSelectionState state) { return state.getIndex(); @@ -97,7 +97,7 @@ public void visitProfile( @NonNull IDocumentNodeItem profileDocument, @NonNull IControlSelectionState state) { visit(catalogDocument, state); - + IRootAssemblyNodeItem root = profileDocument.getRootAssemblyNodeItem(); visitMetadata(root, state); diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/DefaultControlSelectionFilter.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/DefaultControlSelectionFilter.java index 18f55190..2dbe64a6 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/DefaultControlSelectionFilter.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/DefaultControlSelectionFilter.java @@ -113,7 +113,7 @@ private static Pattern toPattern(@NonNull ProfileSelectControlById.Matching matc String regex = pattern.chars().boxed().map(ch -> (char) ch.intValue()).map(ch -> { String value; - switch (ch) { + switch (ch) { case '*': value = ".*"; break; diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/DefaultResult.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/DefaultResult.java index 6ed37df2..f7e08d59 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/DefaultResult.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/DefaultResult.java @@ -49,7 +49,7 @@ public class DefaultResult implements IResult { private static final Logger LOGGER = LogManager.getLogger(DefaultResult.class); @NonNull - private final Lazy> promotedControls = ObjectUtils.notNull( Lazy.lazy(LinkedHashSet::new)); + private final Lazy> promotedControls = ObjectUtils.notNull(Lazy.lazy(LinkedHashSet::new)); @NonNull private final Lazy> promotedParameters = ObjectUtils.notNull(Lazy.lazy(LinkedHashSet::new)); @NonNull @@ -136,20 +136,20 @@ public void applyTo(@NonNull Control parent) { } public void applyRemovesTo(Catalog parent) { - removeItems(parent.getGroups(),getRemovedGroups()); - removeItems(parent.getControls(),getRemovedControls()); - removeItems(parent.getParams(),getRemovedParameters()); + removeItems(parent.getGroups(), getRemovedGroups()); + removeItems(parent.getControls(), getRemovedControls()); + removeItems(parent.getParams(), getRemovedParameters()); } public void applyRemovesTo(CatalogGroup parent) { - removeItems(parent.getGroups(),getRemovedGroups()); - removeItems(parent.getControls(),getRemovedControls()); - removeItems(parent.getParams(),getRemovedParameters()); + removeItems(parent.getGroups(), getRemovedGroups()); + removeItems(parent.getControls(), getRemovedControls()); + removeItems(parent.getParams(), getRemovedParameters()); } public void applyRemovesTo(Control parent) { - removeItems(parent.getControls(),getRemovedControls()); - removeItems(parent.getParams(),getRemovedParameters()); + removeItems(parent.getControls(), getRemovedControls()); + removeItems(parent.getParams(), getRemovedParameters()); } public DefaultResult append(@NonNull DefaultResult that) { @@ -166,7 +166,7 @@ public DefaultResult appendPromoted(@NonNull DefaultResult that) { lazyAppend(promotedParameters, that.promotedParameters); return this; } - + protected static void lazyAppend(@NonNull Lazy> self, @NonNull Lazy> other) { if (other.isAvailable()) { Set otherSet = other.get(); diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/AbstractCatalogEntityVisitor.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/AbstractCatalogEntityVisitor.java index 99a9696f..d99a97d4 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/AbstractCatalogEntityVisitor.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/AbstractCatalogEntityVisitor.java @@ -205,7 +205,7 @@ protected R visitParameter( * @param state * the calling context information */ - protected void visitPart( + protected void visitPart( // NOPMD noop default @NonNull IRequiredValueModelNodeItem item, @NonNull IRequiredValueModelNodeItem groupOrControl, T state) { @@ -257,7 +257,7 @@ protected void visitMetadata(@NonNull IRootAssemblyNodeItem rootItem, T state) { * @param state * the calling context information */ - protected void visitRole( + protected void visitRole( // NOPMD noop default @NonNull IRequiredValueModelNodeItem item, @NonNull IRequiredValueModelNodeItem metadataItem, T state) { @@ -277,7 +277,7 @@ protected void visitRole( * @param state * the calling context information */ - protected void visitLocation( + protected void visitLocation( // NOPMD noop default @NonNull IRequiredValueModelNodeItem item, @NonNull IRequiredValueModelNodeItem metadataItem, T state) { @@ -297,7 +297,7 @@ protected void visitLocation( * @param state * the calling context information */ - protected void visitParty( + protected void visitParty( // NOPMD noop default @NonNull IRequiredValueModelNodeItem item, @NonNull IRequiredValueModelNodeItem metadataItem, T state) { @@ -337,7 +337,7 @@ protected void visitBackMatter(@NonNull IRootAssemblyNodeItem rootItem, T state) * @param state * the calling context information */ - protected void visitResource( + protected void visitResource( // NOPMD noop default @NonNull IRequiredValueModelNodeItem item, @NonNull IRootAssemblyNodeItem backMatterItem, T state) { diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/AbstractCatalogVisitor.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/AbstractCatalogVisitor.java index 13a0c883..31f9a9ad 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/AbstractCatalogVisitor.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/AbstractCatalogVisitor.java @@ -129,7 +129,6 @@ protected R visitControlContainer( .reduce(initialResult, (first, second) -> aggregateResults(first, second, state)); } - /** * Called when visiting a control. *

diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/AbstractEntityItem.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/AbstractEntityItem.java index ff655f42..733484c0 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/AbstractEntityItem.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/AbstractEntityItem.java @@ -125,11 +125,11 @@ public int resetReferenceCount() { } static final class Builder { - private String originalIdentifier; + private String originalIdentifier; private String reassignedIdentifier; - private IRequiredValueModelNodeItem instance; + private IRequiredValueModelNodeItem instance; private ItemType itemType; - private URI source; + private URI source; @NonNull public Builder instance(@NonNull IRequiredValueModelNodeItem item, @NonNull ItemType itemType) { diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/ICatalogVisitor.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/ICatalogVisitor.java index 594f7f5f..50a6b286 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/ICatalogVisitor.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/ICatalogVisitor.java @@ -39,11 +39,12 @@ * the type of the result for visiting a collection of groups and/or controls */ public interface ICatalogVisitor { - + /** * Called when visiting a group. *

- * Can be overridden by classes extending this interface to support processing of the visited object. + * Can be overridden by classes extending this interface to support processing of the visited + * object. * * @param item * the Metapath item for the group @@ -61,7 +62,8 @@ default R visitGroup(@NonNull IRequiredValueModelNodeItem item, R childResult, T /** * Called when visiting a control. *

- * Can be overridden by classes extending this interface to support processing of the visited object. + * Can be overridden by classes extending this interface to support processing of the visited + * object. * * @param item * the Metapath item for the control diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/IIndexer.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/IIndexer.java index 9d7f3049..7dbf505d 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/IIndexer.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/IIndexer.java @@ -67,13 +67,13 @@ public boolean test(IEntityItem entity) { return entity.getReferenceCount() > 0 || (Boolean) IIndexer.HAS_PROP_KEEP_METAPATH.evaluateAs(entity.getInstance(), ResultType.BOOLEAN); } - + }; static boolean isReferencedEntity(@NonNull IEntityItem entity) { return KEEP_ENTITY_PREDICATE.test(entity); } - + /** * Keep entities that have a reference count greater than zero or are required to be kept based on * the "keep"="always property. @@ -85,11 +85,10 @@ static boolean isReferencedEntity(@NonNull IEntityItem entity) { static Stream getReferencedEntitiesAsStream(@NonNull Collection entities) { return entities.stream().filter(KEEP_ENTITY_PREDICATE); } - - + /** - * Keep entities that have a reference count of zero or are not required to be kept based on - * the "keep"="always property. + * Keep entities that have a reference count of zero or are not required to be kept based on the + * "keep"="always property. * * @param entities * the entity items to filter @@ -150,12 +149,12 @@ static void logIndex(@NonNull IIndexer indexer, @NonNull Level logLevel) { } } } - + for (Map.Entry entry : indexer.getSelectionStatusMap().entrySet()) { INodeItem nodeItem = entry.getKey(); if (!indexedItems.contains(nodeItem)) { Object value = nodeItem.getValue(); - logger.atLevel(logLevel).log("{}: {}",value == null ? "(null)" : value.getClass().getName(), entry.getValue()); + logger.atLevel(logLevel).log("{}: {}", value == null ? "(null)" : value.getClass().getName(), entry.getValue()); } } } @@ -228,7 +227,6 @@ default IEntityItem getEntity(@NonNull IEntityItem.ItemType itemType, @NonNull S boolean isSelected(@NonNull IEntityItem entity); - Map getSelectionStatusMap(); @NonNull @@ -236,7 +234,7 @@ default IEntityItem getEntity(@NonNull IEntityItem.ItemType itemType, @NonNull S @NonNull SelectionStatus setSelectionStatus(@NonNull INodeItem item, @NonNull SelectionStatus selectionStatus); - + void resetSelectionStatus(); void append(@NonNull IIndexer result); diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/ReassignmentIndexer.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/ReassignmentIndexer.java index 0cb06234..64436673 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/ReassignmentIndexer.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/support/ReassignmentIndexer.java @@ -39,7 +39,7 @@ public class ReassignmentIndexer public ReassignmentIndexer(@NonNull IIdentifierMapper mapper) { this.mapper = mapper; } - + @NonNull protected IIdentifierMapper getMapper() { return mapper; diff --git a/src/test/java/gov/nist/secauto/oscal/java/MetaschemaVisitorTest.java b/src/test/java/gov/nist/secauto/oscal/java/MetaschemaVisitorTest.java index 080e86c2..8c31dd49 100644 --- a/src/test/java/gov/nist/secauto/oscal/java/MetaschemaVisitorTest.java +++ b/src/test/java/gov/nist/secauto/oscal/java/MetaschemaVisitorTest.java @@ -111,17 +111,17 @@ void test() throws FileNotFoundException, IOException, URISyntaxException { private static void evaluatePath(@NonNull MetapathExpression path, @NonNull INodeContext nodeContext, @NonNull DynamicContext dynamicContext) { -// System.out.println("Path: " + path.getPath()); -// System.out.println("Compiled Path: " + path.toString()); + // System.out.println("Path: " + path.getPath()); + // System.out.println("Compiled Path: " + path.toString()); ISequence result = path.evaluate(nodeContext, dynamicContext); -// System.out.println("Result: "); + // System.out.println("Result: "); AtomicInteger count = new AtomicInteger(); result.asStream().forEachOrdered(x -> { Object value = x.getValue(); -// System.out.println(String.format(" %s", value)); + // System.out.println(String.format(" %s", value)); count.incrementAndGet(); }); -// System.out.println(String.format(" %d items", count.get())); + // System.out.println(String.format(" %d items", count.get())); } } diff --git a/src/test/java/gov/nist/secauto/oscal/java/ReadWriteTest.java b/src/test/java/gov/nist/secauto/oscal/java/ReadWriteTest.java index bd74fe01..e00cf7a1 100644 --- a/src/test/java/gov/nist/secauto/oscal/java/ReadWriteTest.java +++ b/src/test/java/gov/nist/secauto/oscal/java/ReadWriteTest.java @@ -52,8 +52,8 @@ class ReadWriteTest { @NonNull private static CLASS measureDeserializer( - @NonNull String format, - @NonNull Path file, + @NonNull String format, + @NonNull Path file, @NonNull IDeserializer deserializer, int iterations) throws IOException { @@ -62,7 +62,7 @@ private static CLASS measureDeserializer( String.format("Illegal iteration value '%d'. The value must be greater than zero.", iterations)); } - + CLASS retval = null; long totalTime = 0; for (int i = 0; i < iterations; i++) { @@ -112,9 +112,9 @@ private static void measureSerializer( } private static void chainReadWrite( - @NonNull Path xmlSource, - @NonNull Class clazz, - @NonNull Path tempDir, + @NonNull Path xmlSource, + @NonNull Class clazz, + @NonNull Path tempDir, int iterations) throws IOException { IBindingContext context = IBindingContext.instance(); diff --git a/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/TestUtil.java b/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/TestUtil.java index a2b10563..f3ed5b00 100644 --- a/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/TestUtil.java +++ b/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/TestUtil.java @@ -63,7 +63,7 @@ private String reassign(@NonNull String identifier) { } return retval; } - + @Override public String mapRoleIdentifier(@NonNull String identifier) { return reassign(identifier); @@ -106,7 +106,7 @@ public static IDocumentNodeItem newImportedCatalog() { importedCatalog.addGroup(AbstractCatalogGroup.builder("group1") .title("Group 1") - .part(AbstractPart.builder("statement") + .part(AbstractPart.builder("statement") .prose("group 1 part 1") .build()) .param(AbstractParameter.builder("param2") diff --git a/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/DefaultControlSelectionFilterTest.java b/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/DefaultControlSelectionFilterTest.java index 60a43e34..e37b2e91 100644 --- a/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/DefaultControlSelectionFilterTest.java +++ b/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/DefaultControlSelectionFilterTest.java @@ -51,25 +51,25 @@ class DefaultControlSelectionFilterTest { @RegisterExtension final JUnit5Mockery context = new JUnit5Mockery() { - { + { setImposteriser(ByteBuddyClassImposteriser.INSTANCE); } }; @Mock - private IProfileSelectControlById selectControlByIdA; + private IProfileSelectControlById selectControlByIdA; @Mock - private ProfileSelectControlById.Matching matchingA; + private ProfileSelectControlById.Matching matchingA; @Mock - private ProfileSelectControlById.Matching matchingB; + private ProfileSelectControlById.Matching matchingB; @Mock - private IProfileSelectControlById selectControlByIdB; + private IProfileSelectControlById selectControlByIdB; @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT") @NonNull private IControlSelectionFilter newEmptyFilter() { context.checking(new Expectations() { - { + { allowing(selectControlByIdA).getWithChildControls(); will(returnValue("no")); allowing(selectControlByIdA).getWithIds(); @@ -88,7 +88,7 @@ private IControlSelectionFilter newEmptyFilter() { private IControlSelectionFilter newSingleSelectionFilter() { final List withIds = List.of("test1", "test2"); context.checking(new Expectations() { - { + { allowing(selectControlByIdA).getWithChildControls(); will(returnValue("no")); allowing(selectControlByIdA).getWithIds(); @@ -109,7 +109,7 @@ private IControlSelectionFilter newSingleSelectionFilter() { private IControlSelectionFilter newSingleSelectionWithChildFilter() { final List withIds = List.of("test1", "test2"); context.checking(new Expectations() { - { + { allowing(selectControlByIdA).getWithChildControls(); will(returnValue("yes")); allowing(selectControlByIdA).getWithIds(); @@ -131,7 +131,7 @@ private IControlSelectionFilter newMultipleSelectionFilter() { final List withIdsA = List.of("test1", "test2", "example1"); final List withIdsB = List.of("test3", "test4"); context.checking(new Expectations() { - { + { allowing(selectControlByIdA).getWithChildControls(); will(returnValue("yes")); allowing(selectControlByIdA).getWithIds(); @@ -164,7 +164,7 @@ private IControlSelectionFilter newMultipleSelectionFilter() { void testEmpty() { final IControl control1 = context.mock(IControl.class); context.checking(new Expectations() { - { + { allowing(control1).getId(); will(returnValue("test")); } @@ -185,7 +185,7 @@ void testSingleSelectionWithIdsFilter() { final IControl control1 = context.mock(IControl.class, "control1"); final IControl control2 = context.mock(IControl.class, "control2"); context.checking(new Expectations() { - { + { allowing(control1).getId(); will(returnValue("test")); allowing(control2).getId(); @@ -212,7 +212,7 @@ void testSingleSelectionWithIdsWithChildFilter() { final IControl control1 = context.mock(IControl.class, "control1"); final IControl control2 = context.mock(IControl.class, "control2"); context.checking(new Expectations() { - { + { allowing(control1).getId(); will(returnValue("test")); allowing(control2).getId(); @@ -244,7 +244,7 @@ void testMultipleSelectionFilter() { final IControl control6 = context.mock(IControl.class, "control6"); final IControl control7 = context.mock(IControl.class, "control7"); context.checking(new Expectations() { - { + { allowing(control1).getId(); will(returnValue("test")); allowing(control2).getId(); diff --git a/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/FilterNonSelectedVisitorTest.java b/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/FilterNonSelectedVisitorTest.java index 080b568c..3240c060 100644 --- a/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/FilterNonSelectedVisitorTest.java +++ b/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/FilterNonSelectedVisitorTest.java @@ -61,13 +61,14 @@ void test() throws IOException { IControlSelectionFilter.ALL_MATCH, IControlSelectionFilter.matchIds("control2", "control5", "control7")); IIndexer indexer = new BasicIndexer(); - + IControlSelectionState state = new ControlSelectionState(indexer, filter); // process selections ControlSelectionVisitor.instance().visitCatalog(importedCatalogDocumentItem, state); // setup reference counting - ReferenceCountingVisitor.instance().visitCatalog(importedCatalogDocumentItem, indexer, importedCatalogDocumentItem.getBaseUri()); + ReferenceCountingVisitor.instance().visitCatalog(importedCatalogDocumentItem, indexer, + importedCatalogDocumentItem.getBaseUri()); FilterNonSelectedVisitor.instance().visitCatalog(importedCatalogDocumentItem, indexer); diff --git a/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/ImportTest.java b/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/ImportTest.java index c853734a..dbc6da5a 100644 --- a/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/ImportTest.java +++ b/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/ImportTest.java @@ -107,7 +107,7 @@ void test() throws ProfileResolutionException { profileDocumentItem.getModelItemsByName("profile").stream() .flatMap(root -> root.getModelItemsByName("import").stream()))) { - Import catalogImport = new Import(profileDocumentItem, importItem); + Import catalogImport = new Import(profileDocumentItem, importItem); catalogImport.resolve(importedCatalogDocumentItem, resolvedCatalog); } }