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 7868edb commit 1c2517a
Show file tree
Hide file tree
Showing 88 changed files with 422 additions and 359 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 @@ -32,7 +32,7 @@

import edu.umd.cs.findbugs.annotations.NonNull;

public abstract class AbstractInstanceNodeItem<
abstract class AbstractInstanceNodeItem<
D extends IDefinition,
I extends INamedInstance,
P extends IModelNodeItem<? extends IModelDefinition, ? extends INamedInstance>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
* @param <M>
* the Java type of the Metaschema module loaded by this loader
*/
// REFACTOR: make an IModuleLoader interface
public abstract class AbstractModuleLoader<T, M extends IModuleExtended<M, ?, ?, ?, ?>>
extends AbstractLoader<M>
implements IModuleLoader<M> {
Expand Down Expand Up @@ -119,7 +118,8 @@ protected M parseResource(@NonNull URI resource, @NonNull Deque<URI> visitedReso

// now check if this Metaschema imports other metaschema
List<URI> imports = getImports(binding);
@NonNull Map<URI, M> importedModules;
@NonNull
Map<URI, M> importedModules;
if (imports.isEmpty()) {
importedModules = ObjectUtils.notNull(Collections.emptyMap());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*/
public interface IAttributable {
@NonNull
String DEFAULT_PROPERY_NAMESPACE = MetaschemaModelConstants.XML_NAMESPACE;
String DEFAULT_PROPERY_NAMESPACE = IModule.XML_NAMESPACE;

@NonNull
Map<Key, Set<String>> EMPTY = CollectionUtil.emptyMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,27 @@

import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;

import java.util.Locale;

import edu.umd.cs.findbugs.annotations.NonNull;

public interface IChoiceGroupInstance
extends IModelInstanceAbsolute, IContainerModelGrouped {

int DEFAULT_CHOICE_GROUP_GROUP_AS_MAX_OCCURS = -1;
@NonNull
String DEFAULT_JSON_DISCRIMINATOR_PROPERTY_NAME = "object-type";

/**
* {@inheritDoc}
*
* @see #DEFAULT_CHOICE_GROUP_GROUP_AS_MAX_OCCURS
*/
@Override
default int getMaxOccurs() {
return DEFAULT_CHOICE_GROUP_GROUP_AS_MAX_OCCURS;
}

/**
* Retrieve the Metaschema assembly definition on which this instance is
* declared.
Expand All @@ -58,6 +74,7 @@ default ModelType getModelType() {
* Get the JSON property to use to discriminate between JSON objects.
*
* @return the discriminator property
* @see #DEFAULT_JSON_DISCRIMINATOR_PROPERTY_NAME
*/
@NonNull
String getJsonDiscriminatorProperty();
Expand All @@ -72,4 +89,15 @@ default MarkupMultiline getRemarks() {
// no remarks
return null;
}

@SuppressWarnings("null")
@Override
default String toCoordinates() {
return String.format("%s:%s-instance:%s/%s@%d",
getContainingDefinition().getContainingModule().getShortName(),
getModelType().toString().toLowerCase(Locale.ROOT),
getContainingDefinition().getName(),
getGroupAsName(),
hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

package gov.nist.secauto.metaschema.core.model;

import java.util.Locale;

/**
* A marker interface for a choice of allowed instances in a Metachema.
*/
Expand Down Expand Up @@ -71,4 +73,14 @@ default int getMaxOccurs() {
default boolean isEffectiveValueWrappedInXml() {
throw new UnsupportedOperationException("not applicable");
}

@SuppressWarnings("null")
@Override
default String toCoordinates() {
return String.format("%s:%s-instance:%s@%d",
getContainingDefinition().getContainingModule().getShortName(),
getModelType().toString().toLowerCase(Locale.ROOT),
getContainingDefinition().getName(),
hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ default boolean hasChildren() {
*
* @return the containing Metaschema module definition
*/
// REFACTOR: can this be removed?
@NonNull
IAssemblyDefinition getOwningDefinition();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import gov.nist.secauto.metaschema.core.model.constraint.impl.IFeatureValueConstrained;

import java.util.Locale;

import edu.umd.cs.findbugs.annotations.NonNull;

public interface IDefinition extends IModelElement, INamed, IAttributable, IFeatureValueConstrained {
Expand Down Expand Up @@ -81,9 +83,11 @@ default boolean isInline() {
@SuppressWarnings("null")
@Override
default String toCoordinates() {
return String.format("%s:%s:%s(%d)",
return String.format("%s:%s-definition:%s(%d)",
getContainingModule().getShortName(),
getModelType(),
getName(), hashCode());
getModelType().toString().toUpperCase(Locale.ROOT),
getName(),
hashCode());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;

import java.util.Locale;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;

Expand All @@ -40,8 +42,7 @@
* @param <INSTANCE>
* the associated instance Java type
*/
// REFACTOR: rename to IFeatureInlinedDefinitionInstance
public interface IFeatureInlinedDefinition<DEFINITION extends IDefinition, INSTANCE extends INamedInstance>
public interface IFeatureDefinitionInstanceInlined<DEFINITION extends IDefinition, INSTANCE extends INamedInstance>
extends IDefinition, INamedInstance {
@Override
default boolean isInline() {
Expand Down Expand Up @@ -86,24 +87,26 @@ default Object getEffectiveDefaultValue() {
}

/**
* Generates a "coordinate" string for the provided information element
* instance.
* Generates a "coordinate" string for the provided inline definition instance.
*
* A coordinate consists of the element's:
* <ul>
* <li>containing Metaschema module's short name</li>
* <li>model type</li>
* <li>name</li>
* <li>definition name</li>
* <li>hash code</li>
* </ul>
*
* @return the coordinate
*/
@SuppressWarnings("null")
@Override
default String toCoordinates() {
IModule module = getContainingModule();
return String.format("%s:%s:%s",
return String.format("%s:%s-inline-definition:%s@%d",
module.getShortName(),
getModelType(),
getEffectiveName());
getModelType().toString().toLowerCase(Locale.ROOT),
getContainingDefinition().getName(),
hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;

import java.util.Locale;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;

Expand All @@ -39,6 +41,11 @@ public interface IFeatureDefinitionReferenceInstance<
@Override
DEFINITION getDefinition();

/**
* Get the instance this definition is combined with.
*
* @return the instance or {@code null} if the definition is not inline
*/
@Nullable
default INSTANCE getInlineInstance() {
return null;
Expand Down Expand Up @@ -107,7 +114,7 @@ default Object getEffectiveDefaultValue() {
* <li>model type</li>
* <li>name</li>
* <li>hash code</li>
* <li>the hash code of the definition</li>
* <li>the hash code of the referenced definition</li>
* </ul>
*
* @return the coordinate
Expand All @@ -116,11 +123,11 @@ default Object getEffectiveDefaultValue() {
@Override
default String toCoordinates() {
IDefinition definition = getDefinition();
return String.format("%s:%s:%s@%d(%d)",
return String.format("%s:%s-instance:%s@%d(%d)",
getContainingDefinition().getContainingModule().getShortName(),
getModelType(),
getModelType().toString().toLowerCase(Locale.ROOT),
definition.getName(),
hashCode(),
definition.isInline() ? 0 : definition.hashCode());
definition.hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import javax.xml.namespace.QName;

public interface IFieldInstance extends IField, INamedModelInstance, IValuedInstance {
boolean DEFAULT_FIELD_IN_XML_WRAPPED = true;

@Override
default String getXmlNamespace() {
return INamedModelInstance.super.getXmlNamespace();
Expand All @@ -47,6 +49,9 @@ default QName getXmlQName() {
*
* @return {@code true} if an XML wrapper is required, or {@code false}
* otherwise
* @see #DEFAULT_FIELD_IN_XML_WRAPPED
*/
boolean isInXmlWrapped();
default boolean isInXmlWrapped() {
return DEFAULT_FIELD_IN_XML_WRAPPED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

package gov.nist.secauto.metaschema.core.model;

// REFACTOR: check that instances cannot have a data type that allows unwrapped
public interface IFieldInstanceGrouped extends INamedModelInstanceGrouped, IFieldInstance {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

public interface IFlagInstance extends IFlag, IValuedInstance, IInstanceAbsolute {

boolean DEFAULT_FLAG_REQUIRED = false;

@Override
IContainerFlag getParentContainer();

Expand All @@ -57,6 +59,9 @@ default QName getXmlQName() {
* Determines if a flag value is required to be provided.
*
* @return {@code true} if a value is required, or {@code false} otherwise
* @see #DEFAULT_FLAG_REQUIRED
*/
boolean isRequired();
default boolean isRequired() {
return DEFAULT_FLAG_REQUIRED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,20 @@

public interface IGroupable extends IInstanceAbsolute, IKeyed {

int DEFAULT_GROUP_AS_MIN_OCCURS = 0;
int DEFAULT_GROUP_AS_MAX_OCCURS = 1;
@NonNull
JsonGroupAsBehavior DEFAULT_JSON_GROUP_AS_BEHAVIOR = JsonGroupAsBehavior.SINGLETON_OR_LIST;
@NonNull
XmlGroupAsBehavior DEFAULT_XML_GROUP_AS_BEHAVIOR = XmlGroupAsBehavior.UNGROUPED;

/**
* Get the minimum cardinality for this associated instance. This value must be
* less than or equal to the maximum cardinality returned by
* {@link #getMaxOccurs()}.
*
* @return {@code 0} or a positive integer value
* @see #DEFAULT_GROUP_AS_MIN_OCCURS
*/
int getMinOccurs();

Expand All @@ -53,6 +61,7 @@ public interface IGroupable extends IInstanceAbsolute, IKeyed {
* {@link #getMinOccurs()}, or {@code -1} if unbounded.
*
* @return a positive integer value or {@code -1} if unbounded
* @see #DEFAULT_GROUP_AS_MAX_OCCURS
*/
int getMaxOccurs();

Expand Down Expand Up @@ -118,9 +127,15 @@ default QName getEffectiveXmlGroupAsQName() {
/**
* Gets the configured JSON group-as strategy. A JSON group-as strategy is only
* required when {@link #getMaxOccurs()} &gt; 1.
* <p>
* The default for this method is {@link JsonGroupAsBehavior#NONE}, since the
* default behavior is to have no grouping. If {@link #getMaxOccurs()} is
* greater than {@code 1}, then the default behavior is
* {@code #DEFAULT_JSON_GROUP_AS_BEHAVIOR}.
*
* @return the JSON group-as strategy, or {@code JsonGroupAsBehavior#NONE} if
* {@link #getMaxOccurs()} = 1
* @see #DEFAULT_JSON_GROUP_AS_BEHAVIOR
*/
@NonNull
default JsonGroupAsBehavior getJsonGroupAsBehavior() {
Expand All @@ -133,10 +148,11 @@ default JsonGroupAsBehavior getJsonGroupAsBehavior() {
*
* @return the JSON group-as strategy, or {@code XmlGroupAsBehavior#UNGROUPED}
* if {@link #getMaxOccurs()} = 1
* @see #DEFAULT_XML_GROUP_AS_BEHAVIOR
*/
@NonNull
default XmlGroupAsBehavior getXmlGroupAsBehavior() {
return XmlGroupAsBehavior.UNGROUPED;
return DEFAULT_XML_GROUP_AS_BEHAVIOR;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,5 @@ default IModule getContainingModule() {
*/
@SuppressWarnings("null")
@Override
default String toCoordinates() {
IModule module = getContainingModule();

// TODO: revisit this to add more context i.e. the containing definition
return String.format("%s:%s",
module.getShortName(),
getModelType());
}
String toCoordinates();
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public interface IModelElement extends IDefaultable {
*
* @return the coordinates
*/
// REFACTOR: reduce implementations
@NonNull
String toCoordinates();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

public interface IModule {

String XML_NAMESPACE = "http://csrc.nist.gov/ns/oscal/metaschema/1.0";

/**
* Retrieves the location where the Metaschema module was loaded from.
*
Expand Down
Loading

0 comments on commit 1c2517a

Please sign in to comment.