Skip to content

Commit

Permalink
Adjusted the module interfaces to promote a cleaner, non-parameterize…
Browse files Browse the repository at this point in the history
…d API.
  • Loading branch information
david-waltermire committed Jan 5, 2024
1 parent 7a1afbc commit 77f5708
Show file tree
Hide file tree
Showing 56 changed files with 411 additions and 333 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ public IDocumentNodeItem newDocumentNodeItem(
}

@Override
public IModuleNodeItem newModuleNodeItem(
IModule<?, ?, ?, ?, ?> module) {
public IModuleNodeItem newModuleNodeItem(IModule module) {
return new ModuleNodeItemImpl(
module,
this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected Map<String, IFlagNodeItem> generateFlags(@NonNull IModelNodeItem<?, ?>
@Override
public Supplier<ModelContainer> newMetaschemaModelSupplier(@NonNull IModuleNodeItem item) {
return () -> {
IModule<?, ?, ?, ?, ?> module = item.getModule();
IModule module = item.getModule();

// build flags from Metaschema definitions
Map<String, IFlagNodeItem> flags = ObjectUtils.notNull(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public interface IModuleNodeItem extends IDocumentNodeItem {
* @return the Metaschema module
*/
@NonNull
IModule<?, ?, ?, ?, ?> getModule();
IModule getModule();

@Override
default URI getDocumentUri() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ IDocumentNodeItem newDocumentNodeItem(
* @return the new node item
*/
@NonNull
IModuleNodeItem newModuleNodeItem(@NonNull IModule<?, ?, ?, ?, ?> module);
IModuleNodeItem newModuleNodeItem(@NonNull IModule module);

/**
* Create a new {@link IFlagNodeItem}, with no associated value, based on the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@
class ModuleNodeItemImpl
implements IModuleNodeItem, IFeatureModelContainerItem {
@NonNull
private final IModule<?, ?, ?, ?, ?> module;
private final IModule module;

@NonNull
private final Lazy<ModelContainer> model;

public ModuleNodeItemImpl(
@NonNull IModule<?, ?, ?, ?, ?> module,
@NonNull IModule module,
@NonNull INodeItemGenerator generator) {
this.module = module;
this.model = ObjectUtils.notNull(Lazy.lazy(generator.newMetaschemaModelSupplier(this)));
}

@Override
public IModule<?, ?, ?, ?, ?> getModule() {
public IModule getModule() {
return module;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
*
* @param <M>
* the imported module Java type
* @param <C>
* the flag container Java type
* @param <D>
* the definition Java type
* @param <FL>
* the flag definition Java type
* @param <FI>
Expand All @@ -62,12 +62,12 @@
*/
@SuppressWarnings("PMD.CouplingBetweenObjects")
public abstract class AbstractModule<
M extends IModule<M, C, FL, FI, A>,
C extends IContainerFlag,
M extends IModuleExtended<M, D, FL, FI, A>,
D extends IModelDefinition,
FL extends IFlagDefinition,
FI extends IFieldDefinition,
A extends IAssemblyDefinition>
implements IModule<M, C, FL, FI, A> {
implements IModuleExtended<M, D, FL, FI, A> {
private static final Logger LOGGER = LogManager.getLogger(AbstractModule.class);

@NonNull
Expand Down Expand Up @@ -109,34 +109,6 @@ public M getImportedModuleByShortName(String name) {
return getImportedModulesByShortName().get(name);
}

@Override
public abstract Collection<A> getAssemblyDefinitions();

@Override
public abstract A getAssemblyDefinitionByName(String name);

@Override
public abstract Collection<FI> getFieldDefinitions();

@Override
public abstract FI getFieldDefinitionByName(String name);

@Override
public List<? extends C> getAssemblyAndFieldDefinitions() {
@SuppressWarnings("unchecked") Stream<? extends C> assemblies
= (Stream<? extends C>) getAssemblyDefinitions().stream();
@SuppressWarnings("unchecked") Stream<? extends C> fields = (Stream<? extends C>) getFieldDefinitions().stream();
return ObjectUtils.notNull(
Stream.concat(assemblies, fields)
.collect(Collectors.toList()));
}

@Override
public abstract Collection<FL> getFlagDefinitions();

@Override
public abstract FL getFlagDefinitionByName(String name);

@SuppressWarnings("null")
@Override
public Collection<FL> getExportedFlagDefinitions() {
Expand Down Expand Up @@ -193,10 +165,9 @@ private class Exports {
private final Map<String, A> exportedAssemblyDefinitions;

@SuppressWarnings("PMD.ConstructorCallsOverridableMethod")
public Exports(
@NonNull List<? extends M> importedModules) {
public Exports(@NonNull List<? extends M> importedModules) {
// Populate the stream with the definitions from this module
Predicate<IDefinition> filter = IModule.allNonLocalDefinitions();
Predicate<IDefinition> filter = IModuleExtended.allNonLocalDefinitions();
Stream<FL> flags = getFlagDefinitions().stream()
.filter(filter);
Stream<FI> fields = getFieldDefinitions().stream()
Expand Down Expand Up @@ -255,17 +226,17 @@ public Exports(

@NonNull
public Map<String, FL> getExportedFlagDefinitionMap() {
return exportedFlagDefinitions;
return this.exportedFlagDefinitions;
}

@NonNull
public Map<String, FI> getExportedFieldDefinitionMap() {
return exportedFieldDefinitions;
return this.exportedFieldDefinitions;
}

@NonNull
public Map<String, A> getExportedAssemblyDefinitionMap() {
return exportedAssemblyDefinitions;
return this.exportedAssemblyDefinitions;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
* the Java type of the Metaschema module loaded by this loader
*/
// REFACTOR: make an IModuleLoader interface
public abstract class AbstractModuleLoader<T, M extends IModule<M, ?, ?, ?, ?>>
public abstract class AbstractModuleLoader<T, M extends IModuleExtended<M, ?, ?, ?, ?>>
extends AbstractLoader<M>
implements IModuleLoader<M> {
@NonNull
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.NAMESPACE;
String DEFAULT_PROPERY_NAMESPACE = MetaschemaModelConstants.XML_NAMESPACE;

@NonNull
Map<Key, Set<String>> EMPTY = CollectionUtil.emptyMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public interface IInstance extends IModelElement {
IContainer getParentContainer();

@Override
default IModule<?, ?, ?, ?, ?> getContainingModule() {
default IModule getContainingModule() {
return getContainingDefinition().getContainingModule();
}

Expand All @@ -73,7 +73,7 @@ public interface IInstance extends IModelElement {
@SuppressWarnings("null")
@Override
default String toCoordinates() {
IModule<?, ?, ?, ?, ?> module = getContainingModule();
IModule module = getContainingModule();

// TODO: revisit this to add more context i.e. the containing definition
return String.format("%s:%s", module.getShortName(), getModelType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ public interface IModelElement extends IDefaultable {
*/
// REFACTOR: move to definition
@NonNull
IModule<?, ?, ?, ?, ?> getContainingModule();
IModule getContainingModule();
}
Loading

0 comments on commit 77f5708

Please sign in to comment.