diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/codetraceability/CodeTraceabilityState.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/codetraceability/CodeTraceabilityState.java index 046d5b857..98f26bb31 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/codetraceability/CodeTraceabilityState.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/codetraceability/CodeTraceabilityState.java @@ -8,8 +8,10 @@ import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.SadCodeTraceLink; import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.SamCodeTraceLink; import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.TransitiveTraceLink; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.data.PipelineStepData; +@Deterministic public interface CodeTraceabilityState extends PipelineStepData { String ID = "CodeTraceabilityState"; diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/connectiongenerator/ConnectionState.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/connectiongenerator/ConnectionState.java index 0239c7574..0a6933006 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/connectiongenerator/ConnectionState.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/connectiongenerator/ConnectionState.java @@ -10,12 +10,14 @@ import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.InstanceLink; import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.SadSamTraceLink; import edu.kit.kastel.mcse.ardoco.core.api.recommendationgenerator.RecommendedInstance; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.configuration.IConfigurable; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Claimant; /** * The Interface IConnectionState. */ +@Deterministic public interface ConnectionState extends IConfigurable { /** diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/ModelElement.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/ModelElement.java index f8bc7d1b5..8cdb6fc7d 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/ModelElement.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/ModelElement.java @@ -7,7 +7,7 @@ /** * A model element. Has an identifier. Two model elements are equal if and only if they have the same identifier. */ -public abstract class ModelElement { +public abstract class ModelElement implements Comparable { private final String id; @@ -38,4 +38,11 @@ public boolean equals(Object obj) { } return Objects.equals(id, other.id); } + + @Override + public int compareTo(ModelElement o) { + if (this.equals(o)) + return 0; + return this.id.compareTo(o.id); + } } diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/ModelExtractionState.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/ModelExtractionState.java index c7ac007d0..1cdc323ef 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/ModelExtractionState.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/ModelExtractionState.java @@ -1,10 +1,8 @@ /* Licensed under MIT 2021-2023. */ package edu.kit.kastel.mcse.ardoco.core.api.models; -import java.util.Set; - import org.eclipse.collections.api.list.ImmutableList; -import org.eclipse.collections.api.set.ImmutableSet; +import org.eclipse.collections.api.set.sorted.ImmutableSortedSet; import edu.kit.kastel.mcse.ardoco.core.configuration.IConfigurable; @@ -39,14 +37,14 @@ public interface ModelExtractionState extends IConfigurable { * * @return all instance types of this state */ - ImmutableSet getInstanceTypes(); + ImmutableSortedSet getInstanceTypes(); /** * Returns all names that are contained by this state. * * @return all names of this state */ - Set getNames(); + ImmutableSortedSet getNames(); /** * Returns all instances that are contained by this state. diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/ModelStates.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/ModelStates.java index 718f5e345..fa5851504 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/ModelStates.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/ModelStates.java @@ -1,9 +1,10 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.api.models; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.Model; import edu.kit.kastel.mcse.ardoco.core.data.PipelineStepData; @@ -11,8 +12,8 @@ public class ModelStates implements PipelineStepData { public static final String ID = "ModelStatesData"; - private transient Map modelExtractionStates = new HashMap<>(); - private transient Map models = new HashMap<>(); + private transient SortedMap modelExtractionStates = new TreeMap<>(); + private transient SortedMap models = new TreeMap<>(); /** * Constructor to create a {@link ModelStates} object that holds all {@link ModelExtractionState}s @@ -46,8 +47,8 @@ public void addModelExtractionState(String id, ModelExtractionState modelState) * * @return the IDs of all contained {@link ModelExtractionState ModelExtractionStates} */ - public Set extractionModelIds() { - return modelExtractionStates.keySet(); + public SortedSet extractionModelIds() { + return new TreeSet<>(modelExtractionStates.keySet()); } /** @@ -55,8 +56,8 @@ public Set extractionModelIds() { * * @return the IDs of all contained {@link Model Models} */ - public Set modelIds() { - return models.keySet(); + public SortedSet modelIds() { + return new TreeSet<>(models.keySet()); } /** diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/architecture/ArchitectureComponent.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/architecture/ArchitectureComponent.java index 061a27a70..ded830b22 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/architecture/ArchitectureComponent.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/architecture/ArchitectureComponent.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2023. */ package edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture; -import java.util.Set; +import java.util.SortedSet; /** * A representation of the model object Component from AMTL. Components @@ -12,13 +12,13 @@ */ public class ArchitectureComponent extends ArchitectureItem { - private final Set subcomponents; - private final Set providedInterfaces; + private final SortedSet subcomponents; + private final SortedSet providedInterfaces; - private final Set requiredInterfaces; + private final SortedSet requiredInterfaces; - public ArchitectureComponent(String name, String id, Set subcomponents, Set providedInterfaces, - Set requiredInterfaces) { + public ArchitectureComponent(String name, String id, SortedSet subcomponents, SortedSet providedInterfaces, + SortedSet requiredInterfaces) { super(name, id); this.subcomponents = subcomponents; this.providedInterfaces = providedInterfaces; @@ -30,7 +30,7 @@ public ArchitectureComponent(String name, String id, Set * * @return the subcomponents of this component */ - public Set getSubcomponents() { + public SortedSet getSubcomponents() { return subcomponents; } @@ -40,7 +40,7 @@ public Set getSubcomponents() { * * @return the provided interfaces of this component */ - public Set getProvidedInterfaces() { + public SortedSet getProvidedInterfaces() { return providedInterfaces; } @@ -50,7 +50,7 @@ public Set getProvidedInterfaces() { * * @return the required interfaces of this component */ - public Set getRequiredInterfaces() { + public SortedSet getRequiredInterfaces() { return requiredInterfaces; } diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/architecture/ArchitectureInterface.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/architecture/ArchitectureInterface.java index e04060e2a..b4ab36ece 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/architecture/ArchitectureInterface.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/architecture/ArchitectureInterface.java @@ -2,18 +2,18 @@ package edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture; import java.util.Objects; -import java.util.Set; +import java.util.SortedSet; public class ArchitectureInterface extends ArchitectureItem { - private final Set signatures; + private final SortedSet signatures; - public ArchitectureInterface(String name, String id, Set signatures) { + public ArchitectureInterface(String name, String id, SortedSet signatures) { super(name, id); this.signatures = signatures; } - public Set getSignatures() { + public SortedSet getSignatures() { return signatures; } diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/ClassUnit.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/ClassUnit.java index 167dcda61..3ff1ad8fb 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/ClassUnit.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/ClassUnit.java @@ -3,7 +3,7 @@ import java.util.ArrayList; import java.util.List; -import java.util.Set; +import java.util.SortedSet; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -20,7 +20,7 @@ private ClassUnit() { content = new ArrayList<>(); } - public ClassUnit(CodeItemRepository codeItemRepository, String name, Set content) { + public ClassUnit(CodeItemRepository codeItemRepository, String name, SortedSet content) { super(codeItemRepository, name); this.content = new ArrayList<>(); for (var codeItem : content) { diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeAssembly.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeAssembly.java index 960fe3677..ebc2d46a4 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeAssembly.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeAssembly.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2023. */ package edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code; -import java.util.Set; +import java.util.SortedSet; import com.fasterxml.jackson.annotation.JsonTypeName; @@ -12,7 +12,7 @@ private CodeAssembly() { // Jackson } - public CodeAssembly(CodeItemRepository codeItemRepository, String name, Set content) { + public CodeAssembly(CodeItemRepository codeItemRepository, String name, SortedSet content) { super(codeItemRepository, name, content); } } diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeCompilationUnit.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeCompilationUnit.java index e32d44ed4..5ff7aff47 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeCompilationUnit.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeCompilationUnit.java @@ -2,10 +2,10 @@ package edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Objects; -import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; @@ -29,8 +29,8 @@ private CodeCompilationUnit() { // Jackson } - public CodeCompilationUnit(CodeItemRepository codeItemRepository, String name, Set content, List pathElements, String extension, - ProgrammingLanguage language) { + public CodeCompilationUnit(CodeItemRepository codeItemRepository, String name, SortedSet content, List pathElements, + String extension, ProgrammingLanguage language) { super(codeItemRepository, name, content); this.pathElements = new ArrayList<>(pathElements); this.extension = extension; @@ -49,8 +49,8 @@ public List getAllDataTypes() { } @Override - public Set getAllCompilationUnits() { - Set result = new HashSet<>(); + public SortedSet getAllCompilationUnits() { + SortedSet result = new TreeSet<>(); result.add(this); return result; } diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeItem.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeItem.java index 2c74227b1..04ff2c66e 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeItem.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeItem.java @@ -2,10 +2,10 @@ package edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Objects; -import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonSubTypes; @@ -60,14 +60,14 @@ public List getAllDataTypes() { return new ArrayList<>(); } - public Set getAllDataTypesAndSelf() { - Set result = new HashSet<>(getAllDataTypes()); + public SortedSet getAllDataTypesAndSelf() { + SortedSet result = new TreeSet<>(getAllDataTypes()); result.add(this); return result; } - public Set getDeclaredMethods() { - Set methods = new HashSet<>(); + public SortedSet getDeclaredMethods() { + SortedSet methods = new TreeSet<>(); for (CodeItem codeItem : getContent()) { if (codeItem instanceof ControlElement codeMethod) { methods.add(codeMethod); @@ -76,11 +76,11 @@ public Set getDeclaredMethods() { return methods; } - public Set getAllCompilationUnits() { - return new HashSet<>(); + public SortedSet getAllCompilationUnits() { + return new TreeSet<>(); } - public Set getAllPackages() { - return new HashSet<>(); + public SortedSet getAllPackages() { + return new TreeSet<>(); } } diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeItemRepository.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeItemRepository.java index 0a34f3a14..3a777a8e8 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeItemRepository.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeItemRepository.java @@ -2,19 +2,19 @@ package edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code; import java.util.List; -import java.util.Map; import java.util.Objects; +import java.util.SortedMap; -import org.eclipse.collections.api.factory.Maps; +import org.eclipse.collections.api.factory.SortedMaps; import com.fasterxml.jackson.annotation.JsonProperty; public class CodeItemRepository { @JsonProperty - private final Map repository = Maps.mutable.empty(); + private final SortedMap repository = SortedMaps.mutable.empty(); - public Map getRepository() { + public SortedMap getRepository() { return repository; } @@ -27,6 +27,8 @@ boolean containsCodeItem(String id) { } CodeItem getCodeItem(String id) { + if (id == null) + return null; return repository.get(id); } diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeModel.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeModel.java index 1e9f0fe9c..ec40f5c3f 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeModel.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeModel.java @@ -2,15 +2,16 @@ package edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code; import java.util.ArrayList; -import java.util.HashSet; +import java.util.Comparator; import java.util.List; import java.util.Objects; -import java.util.Set; +import java.util.SortedSet; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import edu.kit.kastel.mcse.ardoco.core.api.models.Entity; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.Model; /** @@ -37,7 +38,7 @@ private CodeModel() { * * @param content the content of the code model */ - public CodeModel(CodeItemRepository codeItemRepository, Set content) { + public CodeModel(CodeItemRepository codeItemRepository, SortedSet content) { this.initialized = true; this.codeItemRepository = codeItemRepository; this.content = new ArrayList<>(); @@ -74,11 +75,18 @@ public List getEndpoints() { * * @return all code packages of this code model */ - public Set getAllPackages() { + public List getAllPackages() { if (!initialized) initialize(); - Set codePackages = new HashSet<>(); - getContent().forEach(c -> codePackages.addAll(c.getAllPackages())); + List codePackages = new ArrayList<>(); + for (CodeItem c : getContent()) { + for (CodePackage cp : c.getAllPackages()) { + if (!codePackages.contains(cp)) { + codePackages.add(cp); + } + } + } + codePackages.sort(Comparator.comparing(Entity::getName)); return codePackages; } diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeModule.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeModule.java index 10a0596e6..c1a68b2a3 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeModule.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodeModule.java @@ -2,10 +2,10 @@ package edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Objects; -import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -31,7 +31,7 @@ public class CodeModule extends CodeItem { // Jackson } - public CodeModule(CodeItemRepository codeItemRepository, String name, Set content) { + public CodeModule(CodeItemRepository codeItemRepository, String name, SortedSet content) { super(codeItemRepository, name); this.content = new ArrayList<>(); for (var codeItem : content) { @@ -85,15 +85,15 @@ public void setParent(CodeModule parent) { } @Override - public Set getAllCompilationUnits() { - Set result = new HashSet<>(); + public SortedSet getAllCompilationUnits() { + SortedSet result = new TreeSet<>(); getContent().forEach(c -> result.addAll(c.getAllCompilationUnits())); return result; } @Override - public Set getAllPackages() { - Set result = new HashSet<>(); + public SortedSet getAllPackages() { + SortedSet result = new TreeSet<>(); getContent().forEach(c -> result.addAll(c.getAllPackages())); return result; } diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodePackage.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodePackage.java index f67a8ccdd..4e3dccbec 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodePackage.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/CodePackage.java @@ -1,8 +1,8 @@ /* Licensed under MIT 2023. */ package edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code; -import java.util.HashSet; -import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import com.fasterxml.jackson.annotation.JsonTypeName; @@ -14,15 +14,15 @@ private CodePackage() { } public CodePackage(CodeItemRepository codeItemRepository, String name) { - super(codeItemRepository, name, new HashSet<>()); + super(codeItemRepository, name, new TreeSet<>()); } - public CodePackage(CodeItemRepository codeItemRepository, String name, Set content) { + public CodePackage(CodeItemRepository codeItemRepository, String name, SortedSet content) { super(codeItemRepository, name, content); } - public Set getSubpackages() { - Set codePackages = new HashSet<>(); + public SortedSet getSubpackages() { + SortedSet codePackages = new TreeSet<>(); for (CodeItem packageElement : getContent()) { if (packageElement instanceof CodePackage codePackage) { codePackages.add(codePackage); @@ -31,8 +31,8 @@ public Set getSubpackages() { return codePackages; } - public Set getCompilationUnits() { - Set compilationUnits = new HashSet<>(); + public SortedSet getCompilationUnits() { + SortedSet compilationUnits = new TreeSet<>(); for (CodeItem packageElement : getContent()) { if (packageElement instanceof CodeCompilationUnit compilationUnit) { compilationUnits.add(compilationUnit); @@ -42,8 +42,8 @@ public Set getCompilationUnits() { } @Override - public Set getAllPackages() { - Set result = new HashSet<>(); + public SortedSet getAllPackages() { + SortedSet result = new TreeSet<>(); result.add(this); getContent().forEach(c -> result.addAll(c.getAllPackages())); return result; diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/Datatype.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/Datatype.java index e18cc636c..169b9920c 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/Datatype.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/Datatype.java @@ -4,7 +4,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.stream.Collectors; import com.fasterxml.jackson.annotation.JsonProperty; @@ -45,7 +46,7 @@ public CodeCompilationUnit getCompilationUnit() { return null; } - public Set getExtendedTypes() { + public SortedSet getExtendedTypes() { return extendedDataTypesIds.stream().map(id -> { CodeItem codeItem = codeItemRepository.getCodeItem(id); if (codeItem instanceof Datatype datatype) { @@ -53,10 +54,10 @@ public Set getExtendedTypes() { } else { return null; } - }).filter(Objects::nonNull).collect(Collectors.toSet()); + }).filter(Objects::nonNull).collect(Collectors.toCollection(TreeSet::new)); } - public Set getImplementedTypes() { + public SortedSet getImplementedTypes() { return implementedDataTypesIds.stream().map(id -> { CodeItem codeItem = codeItemRepository.getCodeItem(id); if (codeItem instanceof Datatype datatype) { @@ -64,20 +65,20 @@ public Set getImplementedTypes() { } else { return null; } - }).filter(Objects::nonNull).collect(Collectors.toSet()); + }).filter(Objects::nonNull).collect(Collectors.toCollection(TreeSet::new)); } public void setCompilationUnit(CodeCompilationUnit compilationUnit) { this.compilationUnitId = compilationUnit.getId(); } - public void setExtendedTypes(Set extendedDatatypes) { + public void setExtendedTypes(SortedSet extendedDatatypes) { for (Datatype datatype : extendedDatatypes) { this.extendedDataTypesIds.add(datatype.getId()); } } - public void setImplementedTypes(Set implementedDatatypes) { + public void setImplementedTypes(SortedSet implementedDatatypes) { for (Datatype datatype : implementedDatatypes) { this.implementedDataTypesIds.add(datatype.getId()); } diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/InterfaceUnit.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/InterfaceUnit.java index 11cced320..d288ae998 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/InterfaceUnit.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/arcotl/code/InterfaceUnit.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import java.util.Set; +import java.util.SortedSet; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -20,7 +20,7 @@ private InterfaceUnit() { // Jackson } - public InterfaceUnit(CodeItemRepository codeItemRepository, String name, Set content) { + public InterfaceUnit(CodeItemRepository codeItemRepository, String name, SortedSet content) { super(codeItemRepository, name); this.content = new ArrayList<>(); for (var codeItem : content) { diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/tracelinks/InstanceLink.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/tracelinks/InstanceLink.java index 948da5855..7cc1205ba 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/tracelinks/InstanceLink.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/tracelinks/InstanceLink.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks; import java.util.Arrays; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Objects; import java.util.Set; @@ -12,6 +12,7 @@ import edu.kit.kastel.mcse.ardoco.core.api.models.ModelInstance; import edu.kit.kastel.mcse.ardoco.core.api.recommendationgenerator.RecommendedInstance; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.NounMapping; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.common.AggregationFunctions; import edu.kit.kastel.mcse.ardoco.core.data.Confidence; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Claimant; @@ -19,6 +20,7 @@ /** * An InstanceLink defines a link between an {@link RecommendedInstance} and an {@link ModelInstance}. */ +@Deterministic public class InstanceLink extends EndpointTuple { private final RecommendedInstance textualInstance; @@ -96,9 +98,9 @@ public boolean equals(Object obj) { @Override public String toString() { - Set names = new HashSet<>(); + Set names = new LinkedHashSet<>(); MutableList namePositions = Lists.mutable.empty(); - Set types = new HashSet<>(); + Set types = new LinkedHashSet<>(); MutableList typePositions = Lists.mutable.empty(); for (NounMapping nameMapping : textualInstance.getNameMappings()) { diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/tracelinks/SadSamTraceLink.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/tracelinks/SadSamTraceLink.java index a4a44101a..e0857dd5e 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/tracelinks/SadSamTraceLink.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/tracelinks/SadSamTraceLink.java @@ -11,7 +11,7 @@ * Represents a trace link. This is a convenience data class that takes the necessary info from {@link InstanceLink} and * the specific {@link ModelInstance} and {@link Word} that are used in this trace link. */ -public class SadSamTraceLink extends TraceLink implements Comparable { +public class SadSamTraceLink extends TraceLink { private final InstanceLink instanceLink; private final Word word; @@ -91,8 +91,4 @@ public int hashCode() { return Objects.hash(getModelElementUid(), getSentenceNumber()); } - @Override - public int compareTo(SadSamTraceLink o) { - return Integer.compare(this.getSentenceNumber(), o.getSentenceNumber()); - } } diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/recommendationgenerator/RecommendedInstance.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/recommendationgenerator/RecommendedInstance.java index 4752b0173..519974dd1 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/recommendationgenerator/RecommendedInstance.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/recommendationgenerator/RecommendedInstance.java @@ -2,7 +2,6 @@ package edu.kit.kastel.mcse.ardoco.core.api.recommendationgenerator; import org.eclipse.collections.api.list.ImmutableList; -import org.eclipse.collections.api.set.ImmutableSet; import org.eclipse.collections.api.set.sorted.ImmutableSortedSet; import edu.kit.kastel.mcse.ardoco.core.api.models.Entity; @@ -108,5 +107,5 @@ protected RecommendedInstance(String name, String id) { public abstract ImmutableSortedSet getSentenceNumbers(); - public abstract ImmutableSet getClaimants(); + public abstract ImmutableList getClaimants(); } diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/text/Phrase.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/text/Phrase.java index 54e466ed1..624659bd9 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/text/Phrase.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/text/Phrase.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.api.text; import org.eclipse.collections.api.list.ImmutableList; -import org.eclipse.collections.api.map.ImmutableMap; +import org.eclipse.collections.api.map.sorted.ImmutableSortedMap; public interface Phrase { int getSentenceNo(); @@ -19,5 +19,5 @@ public interface Phrase { boolean isSubPhraseOf(Phrase other); - ImmutableMap getPhraseVector(); + ImmutableSortedMap getPhraseVector(); } diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/text/Word.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/text/Word.java index 27960e693..8c72b6292 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/text/Word.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/text/Word.java @@ -84,6 +84,9 @@ public interface Word extends Comparable { @Override default int compareTo(Word o) { + if (this.equals(o)) + return 0; + int compareSentences = Integer.compare(this.getSentenceNo(), o.getSentenceNo()); if (compareSentences != 0) { return compareSentences; diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/textextraction/NounMapping.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/textextraction/NounMapping.java index d54adc4c1..519099b38 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/textextraction/NounMapping.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/textextraction/NounMapping.java @@ -2,8 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.api.textextraction; import org.eclipse.collections.api.list.ImmutableList; -import org.eclipse.collections.api.map.ImmutableMap; -import org.eclipse.collections.api.set.ImmutableSet; +import org.eclipse.collections.api.map.sorted.ImmutableSortedMap; import org.eclipse.collections.api.set.sorted.ImmutableSortedSet; import edu.kit.kastel.mcse.ardoco.core.api.text.Phrase; @@ -65,7 +64,7 @@ public interface NounMapping { */ ImmutableList getMappingSentenceNo(); - ImmutableSet getPhrases(); + ImmutableList getPhrases(); /** * Gets the probability for name. @@ -80,9 +79,9 @@ public interface NounMapping { * * @return the distribution */ - ImmutableMap getDistribution(); + ImmutableSortedMap getDistribution(); - ImmutableSet getClaimants(); + ImmutableList getClaimants(); /** * Adds the kind with probability. diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/textextraction/PhraseMapping.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/textextraction/PhraseMapping.java index c1360fe9c..1b1dec8db 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/textextraction/PhraseMapping.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/textextraction/PhraseMapping.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.api.textextraction; import org.eclipse.collections.api.list.ImmutableList; -import org.eclipse.collections.api.map.ImmutableMap; +import org.eclipse.collections.api.map.sorted.ImmutableSortedMap; import edu.kit.kastel.mcse.ardoco.core.api.text.Phrase; import edu.kit.kastel.mcse.ardoco.core.api.text.PhraseType; @@ -16,7 +16,7 @@ public interface PhraseMapping { PhraseType getPhraseType(); - ImmutableMap getPhraseVector(); + ImmutableSortedMap getPhraseVector(); void removePhrase(Phrase phrase); diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/textextraction/TextState.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/textextraction/TextState.java index fd0285dfb..b0f92f952 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/textextraction/TextState.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/textextraction/TextState.java @@ -3,8 +3,8 @@ import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.list.MutableList; -import org.eclipse.collections.api.map.MutableMap; -import org.eclipse.collections.api.set.ImmutableSet; +import org.eclipse.collections.api.map.sorted.ImmutableSortedMap; +import org.eclipse.collections.api.set.sorted.ImmutableSortedSet; import edu.kit.kastel.mcse.ardoco.core.api.text.Word; import edu.kit.kastel.mcse.ardoco.core.common.tuple.Pair; @@ -38,10 +38,10 @@ public interface TextState extends IConfigurable, PipelineStepData { */ NounMapping addNounMapping(Word word, MappingKind kind, Claimant claimant, double probability, ImmutableList surfaceForms); - NounMapping addNounMapping(ImmutableSet words, MappingKind kind, Claimant claimant, double probability, ImmutableList referenceWords, + NounMapping addNounMapping(ImmutableSortedSet words, MappingKind kind, Claimant claimant, double probability, ImmutableList referenceWords, ImmutableList surfaceForms, String reference); - NounMapping addNounMapping(ImmutableSet words, MutableMap distribution, ImmutableList referenceWords, + NounMapping addNounMapping(ImmutableSortedSet words, ImmutableSortedMap distribution, ImmutableList referenceWords, ImmutableList surfaceForms, String reference); /** diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/architecture/Deterministic.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/architecture/Deterministic.java new file mode 100644 index 000000000..082434828 --- /dev/null +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/architecture/Deterministic.java @@ -0,0 +1,8 @@ +/* Licensed under MIT 2023. */ +package edu.kit.kastel.mcse.ardoco.core.architecture; + +/** + * Mark a class as deterministic by user review. + */ +public @interface Deterministic { +} diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/architecture/NoHashCodeEquals.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/architecture/NoHashCodeEquals.java new file mode 100644 index 000000000..6bd3e6316 --- /dev/null +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/architecture/NoHashCodeEquals.java @@ -0,0 +1,8 @@ +/* Licensed under MIT 2023. */ +package edu.kit.kastel.mcse.ardoco.core.architecture; + +/** + * Disallow overriding equals and hashCode for a certain class because of contracts. + */ +public @interface NoHashCodeEquals { +} diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/Internal.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/Internal.java index 057f535cb..1d5b567bb 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/Internal.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/Internal.java @@ -1,7 +1,11 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.common; -import java.lang.annotation.*; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; /** * Marks a method or class as only for internal use. Classes and methods that are marked with this annotation are diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/CommonUtilities.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/CommonUtilities.java index 2fd8d5b0e..954951b66 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/CommonUtilities.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/CommonUtilities.java @@ -12,8 +12,9 @@ import java.util.Arrays; import java.util.List; import java.util.Scanner; -import java.util.Set; +import java.util.SortedSet; import java.util.StringJoiner; +import java.util.TreeSet; import java.util.stream.Collectors; import org.eclipse.collections.api.factory.Lists; @@ -232,14 +233,14 @@ public static ImmutableList getSimilarTypes(Word word, ModelExtractionSt * @param modelState the model state * @return Set of identifiers for existing types */ - public static Set getTypeIdentifiers(ModelExtractionState modelState) { - Set identifiers = modelState.getInstanceTypes() + public static SortedSet getTypeIdentifiers(ModelExtractionState modelState) { + SortedSet identifiers = modelState.getInstanceTypes() .stream() .map(CommonUtilities::splitSnakeAndKebabCase) .map(CommonUtilities::splitCamelCase) .map(type -> type.split(" ")) .flatMap(Arrays::stream) - .collect(Collectors.toSet()); + .collect(Collectors.toCollection(TreeSet::new)); identifiers.addAll(modelState.getInstanceTypes().toSet()); return identifiers; } diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/Comparators.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/Comparators.java new file mode 100644 index 000000000..84e71b3bf --- /dev/null +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/Comparators.java @@ -0,0 +1,28 @@ +/* Licensed under MIT 2023. */ +package edu.kit.kastel.mcse.ardoco.core.common.util; + +import java.util.Collection; + +import org.eclipse.collections.api.collection.ImmutableCollection; + +public final class Comparators { + private Comparators() { + throw new IllegalAccessError(); + } + + public static boolean collectionsEqualsAnyOrder(ImmutableCollection first, ImmutableCollection second) { + return collectionsEqualsAnyOrder(first.castToCollection(), second.castToCollection()); + } + + public static boolean collectionsEqualsAnyOrder(Collection first, Collection second) { + return first.size() == second.size() && first.containsAll(second) && second.containsAll(first); + } + + public static boolean collectionsIdentityAnyOrder(ImmutableCollection first, ImmutableCollection second) { + return collectionsIdentityAnyOrder(first.castToCollection(), second.castToCollection()); + } + + public static boolean collectionsIdentityAnyOrder(Collection first, Collection second) { + return first.size() == second.size() && first.stream().allMatch(f -> second.stream().anyMatch(s -> f == s)); + } +} diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/ElementWrapper.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/ElementWrapper.java deleted file mode 100644 index 35169ad14..000000000 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/ElementWrapper.java +++ /dev/null @@ -1,45 +0,0 @@ -/* Licensed under MIT 2022-2023. */ -package edu.kit.kastel.mcse.ardoco.core.common.util; - -import java.util.Objects; -import java.util.function.BiPredicate; -import java.util.function.Function; - -public final class ElementWrapper { - - private final Class elementType; - - private final E element; - - private final Function elementToHash; - - private final BiPredicate elementEquals; - - public ElementWrapper(Class elementType, E element, Function elementToHash, BiPredicate elementEquals) { - - this.elementType = Objects.requireNonNull(elementType); - this.element = element; - this.elementEquals = Objects.requireNonNull(elementEquals); - this.elementToHash = Objects.requireNonNull(elementToHash); - - } - - @Override - public int hashCode() { - return elementToHash.apply(element); - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - ElementWrapper that = (ElementWrapper) o; - return elementType.equals(that.elementType) && elementEquals.test(element, elementType.cast(that.element)); - } - - public E getElement() { - return element; - } -} diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/PhraseMappingAggregatorStrategy.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/PhraseMappingAggregatorStrategy.java index fc8dfebc4..48ee8c0aa 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/PhraseMappingAggregatorStrategy.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/PhraseMappingAggregatorStrategy.java @@ -7,20 +7,22 @@ import java.util.function.ToDoubleBiFunction; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.PhraseMapping; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; +@Deterministic public enum PhraseMappingAggregatorStrategy implements ToDoubleBiFunction { MAX_SIMILARITY((a, b) -> uniqueDot(a.getPhrases(), b.getPhrases()).stream() - .mapToDouble(p -> cosineSimilarity(p.first().getPhraseVector().toMap(), p.second().getPhraseVector().toMap())) + .mapToDouble(p -> cosineSimilarity(p.first().getPhraseVector().toSortedMap(), p.second().getPhraseVector().toSortedMap())) .max() .orElse(Double.NaN)), // MIN_SIMILARITY((a, b) -> uniqueDot(a.getPhrases(), b.getPhrases()).stream() - .mapToDouble(p -> cosineSimilarity(p.first().getPhraseVector().toMap(), p.second().getPhraseVector().toMap())) + .mapToDouble(p -> cosineSimilarity(p.first().getPhraseVector().toSortedMap(), p.second().getPhraseVector().toSortedMap())) .min() .orElse(Double.NaN)), // AVG_SIMILARITY((a, b) -> uniqueDot(a.getPhrases(), b.getPhrases()).stream() - .mapToDouble(p -> cosineSimilarity(p.first().getPhraseVector().toMap(), p.second().getPhraseVector().toMap())) + .mapToDouble(p -> cosineSimilarity(p.first().getPhraseVector().toSortedMap(), p.second().getPhraseVector().toSortedMap())) .average() .orElse(Double.NaN)); diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/SimilarityUtils.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/SimilarityUtils.java index e2bfdb75d..eb7126171 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/SimilarityUtils.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/SimilarityUtils.java @@ -10,7 +10,7 @@ import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.list.MutableList; -import org.eclipse.collections.api.map.MutableMap; +import org.eclipse.collections.api.map.sorted.ImmutableSortedMap; import edu.kit.kastel.mcse.ardoco.core.api.models.ModelInstance; import edu.kit.kastel.mcse.ardoco.core.api.recommendationgenerator.RecommendedInstance; @@ -19,12 +19,14 @@ import edu.kit.kastel.mcse.ardoco.core.api.textextraction.NounMapping; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.PhraseMapping; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.TextState; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.common.tuple.Pair; import edu.kit.kastel.mcse.ardoco.core.common.util.wordsim.WordSimUtils; /** * This class is a utility class. */ +@Deterministic public final class SimilarityUtils { private SimilarityUtils() { @@ -295,10 +297,10 @@ private static boolean checkRecommendedInstanceForSelection(ModelInstance instan private static boolean coversOtherPhraseVector(PhraseMapping phraseMapping1, PhraseMapping phraseMapping2) { - MutableMap phraseVector1 = phraseMapping1.getPhraseVector().toMap(); - MutableMap phraseVector2 = phraseMapping2.getPhraseVector().toMap(); + ImmutableSortedMap phraseVector1 = phraseMapping1.getPhraseVector(); + ImmutableSortedMap phraseVector2 = phraseMapping2.getPhraseVector(); - return phraseVector1.keySet().containsAll(phraseVector2.keySet()); + return phraseVector1.keysView().containsAll(phraseVector2.keysView().toSortedSet()); } private static boolean containsAllNounMappingsOfPhraseMapping(TextState textState, PhraseMapping phraseMapping1, PhraseMapping phraseMapping2) { diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/wordsim/vector/VectorBasedWordSimMeasure.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/wordsim/vector/VectorBasedWordSimMeasure.java index ed937a134..9238b39b4 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/wordsim/vector/VectorBasedWordSimMeasure.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/wordsim/vector/VectorBasedWordSimMeasure.java @@ -1,10 +1,11 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.common.util.wordsim.vector; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.common.util.wordsim.WordSimMeasure; /** @@ -12,12 +13,13 @@ * embeddings of passed words, a {@link WordVectorDataSource} is required. Instances of this class additionally manage a * cache to improve lookup speeds. */ +@Deterministic public abstract class VectorBasedWordSimMeasure implements WordSimMeasure { private static final float[] ZERO_VECTOR = new float[0]; private final WordVectorDataSource vectorDataSource; - private final Map vectorCache = new HashMap<>(); + private final Map vectorCache = new LinkedHashMap<>(); /** * Constructs a new {@link VectorBasedWordSimMeasure} instance diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/AbstractConfigurable.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/AbstractConfigurable.java index e369e0981..1e4abc67a 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/AbstractConfigurable.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/AbstractConfigurable.java @@ -6,13 +6,16 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; + +@Deterministic public abstract class AbstractConfigurable implements IConfigurable { protected final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -20,7 +23,7 @@ public abstract class AbstractConfigurable implements IConfigurable { public static final String KEY_VALUE_CONNECTOR = "="; public static final String LIST_SEPARATOR = ","; - private Map lastAppliedConfiguration = new HashMap<>(); + private SortedMap lastAppliedConfiguration = new TreeMap<>(); protected final List findByClassName(List selected, List instances) { List target = new ArrayList<>(0); @@ -35,20 +38,20 @@ protected final List findByClassName(List selected, List insta } @Override - public final void applyConfiguration(Map additionalConfiguration) { + public final void applyConfiguration(SortedMap additionalConfiguration) { applyConfiguration(additionalConfiguration, this.getClass()); delegateApplyConfigurationToInternalObjects(additionalConfiguration); - this.lastAppliedConfiguration = new HashMap<>(additionalConfiguration); + this.lastAppliedConfiguration = new TreeMap<>(additionalConfiguration); } @Override - public Map getLastAppliedConfiguration() { - return Collections.unmodifiableMap(lastAppliedConfiguration); + public SortedMap getLastAppliedConfiguration() { + return Collections.unmodifiableSortedMap(lastAppliedConfiguration); } - protected abstract void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration); + protected abstract void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration); - private void applyConfiguration(Map additionalConfiguration, Class currentClass) { + private void applyConfiguration(SortedMap additionalConfiguration, Class currentClass) { if (currentClass == Object.class || currentClass == AbstractConfigurable.class) return; diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/Configurable.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/Configurable.java index db2410c14..a719d6f3e 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/Configurable.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/Configurable.java @@ -1,7 +1,11 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.configuration; -import java.lang.annotation.*; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Documented diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/ConfigurationInstantiatorUtils.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/ConfigurationInstantiatorUtils.java index aa1a5676d..1fe8c33f4 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/ConfigurationInstantiatorUtils.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/ConfigurationInstantiatorUtils.java @@ -9,8 +9,10 @@ import java.util.Map; import java.util.function.Predicate; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; +@Deterministic public final class ConfigurationInstantiatorUtils { private ConfigurationInstantiatorUtils() { throw new IllegalAccessError(); diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/IConfigurable.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/IConfigurable.java index 1c0b9b093..1c21a6b9f 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/IConfigurable.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/IConfigurable.java @@ -1,10 +1,10 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.configuration; -import java.util.Map; +import java.util.SortedMap; public interface IConfigurable { - void applyConfiguration(Map additionalConfiguration); + void applyConfiguration(SortedMap additionalConfiguration); - Map getLastAppliedConfiguration(); + SortedMap getLastAppliedConfiguration(); } diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/data/AbstractState.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/data/AbstractState.java index 01a78835e..afa28ebdb 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/data/AbstractState.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/data/AbstractState.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.data; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.configuration.AbstractConfigurable; @@ -11,7 +11,7 @@ public abstract class AbstractState extends AbstractConfigurable implements PipelineStepData { @Override - protected void delegateApplyConfigurationToInternalObjects(Map map) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap map) { // empty } } diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/data/Confidence.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/data/Confidence.java index 30f7e4fd7..f19876002 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/data/Confidence.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/data/Confidence.java @@ -2,11 +2,13 @@ package edu.kit.kastel.mcse.ardoco.core.data; import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.common.AggregationFunctions; import edu.kit.kastel.mcse.ardoco.core.common.ICopyable; import edu.kit.kastel.mcse.ardoco.core.common.tuple.Triple; @@ -16,6 +18,7 @@ * This class represents a confidence for a certain (intermediate) result. * Different {@link Claimant Claimants} can add their confidences that get aggregated via one of the {@link AggregationFunctions} to a single confidence value. */ +@Deterministic public final class Confidence implements Comparable, ICopyable { private final AggregationFunctions confidenceAggregator; @@ -56,7 +59,10 @@ private Confidence(AggregationFunctions confidenceAggregator, List getClaimants() { - return this.agentConfidences.stream().map(Triple::first).collect(Collectors.toUnmodifiableSet()); + Set identitySet = new LinkedHashSet<>(); + for (var confidence : this.agentConfidences) + identitySet.add(confidence.first()); + return identitySet; } @Override @@ -87,6 +93,8 @@ private String getMethodInClaimant(Claimant claimant) { @Override public int compareTo(Confidence o) { + if (this.equals(o)) + return 0; return Double.compare(this.getConfidence(), o.getConfidence()); } diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/data/DataRepository.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/data/DataRepository.java index 017baa793..b7c2eb3a2 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/data/DataRepository.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/data/DataRepository.java @@ -1,9 +1,9 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.data; -import java.util.HashMap; -import java.util.Map; import java.util.Optional; +import java.util.SortedMap; +import java.util.TreeMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,10 +16,10 @@ public class DataRepository { private static final Logger logger = LoggerFactory.getLogger(DataRepository.class); - private final Map data; + private final SortedMap data; public DataRepository() { - this.data = new HashMap<>(); + this.data = new TreeMap<>(); } /** diff --git a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/pipeline/Pipeline.java b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/pipeline/Pipeline.java index ae662bc5b..bfb9aa3ac 100644 --- a/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/pipeline/Pipeline.java +++ b/framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/pipeline/Pipeline.java @@ -5,7 +5,7 @@ import java.time.Instant; import java.util.ArrayList; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; @@ -89,8 +89,8 @@ public final void run() { /** * This method is called at the start of running the pipeline. Within this method, the added PipelineSteps are prepared. * Sub-classes of Pipeline can override it with special cases. - * It is recommended that you apply the Map from {@link #getLastAppliedConfiguration()} via {@link #applyConfiguration(Map)} to each pipeline step. - * You can do that on your own if you need special treatment or by default call {@link #delegateApplyConfigurationToInternalObjects(Map)}. + * It is recommended that you apply the Map from {@link #getLastAppliedConfiguration()} via {@link #applyConfiguration(SortedMap)} to each pipeline step. + * You can do that on your own if you need special treatment or by default call {@link #delegateApplyConfigurationToInternalObjects(SortedMap)}. * The base version does apply the last configuration via the default call. */ protected void preparePipelineSteps() { @@ -98,7 +98,7 @@ protected void preparePipelineSteps() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { this.pipelineSteps.forEach(it -> it.applyConfiguration(additionalConfiguration)); } } diff --git a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/util/wordsim/measures/ngram/NgramMeasureTest.java b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/util/wordsim/measures/ngram/NgramMeasureTest.java index 4ef4d9061..6315b61ef 100644 --- a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/util/wordsim/measures/ngram/NgramMeasureTest.java +++ b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/util/wordsim/measures/ngram/NgramMeasureTest.java @@ -1,7 +1,10 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.common.util.wordsim.measures.ngram; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; diff --git a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/util/wordsim/vector/VectorUtilsTest.java b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/util/wordsim/vector/VectorUtilsTest.java index 86648819b..7abf6577f 100644 --- a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/util/wordsim/vector/VectorUtilsTest.java +++ b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/common/util/wordsim/vector/VectorUtilsTest.java @@ -1,7 +1,11 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.common.util.wordsim.vector; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; diff --git a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/pipeline/impl/ConcretePipelineStepOne.java b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/pipeline/impl/ConcretePipelineStepOne.java index bfdd9e253..b4b86005c 100644 --- a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/pipeline/impl/ConcretePipelineStepOne.java +++ b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/pipeline/impl/ConcretePipelineStepOne.java @@ -3,7 +3,7 @@ import java.util.Arrays; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import java.util.function.Predicate; import org.slf4j.Logger; @@ -41,7 +41,7 @@ public void run() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { // NOP } } diff --git a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/pipeline/impl/ConcretePipelineStepTwoOne.java b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/pipeline/impl/ConcretePipelineStepTwoOne.java index 7024a1570..fddb318bd 100644 --- a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/pipeline/impl/ConcretePipelineStepTwoOne.java +++ b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/pipeline/impl/ConcretePipelineStepTwoOne.java @@ -3,7 +3,7 @@ import java.util.ArrayList; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,7 +68,7 @@ private List getTokens() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { // NOP } } diff --git a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/pipeline/impl/ConcretePipelineStepTwoTwo.java b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/pipeline/impl/ConcretePipelineStepTwoTwo.java index 34ccac755..be379b002 100644 --- a/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/pipeline/impl/ConcretePipelineStepTwoTwo.java +++ b/framework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/pipeline/impl/ConcretePipelineStepTwoTwo.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.pipeline.impl; -import java.util.Map; +import java.util.SortedMap; import java.util.TreeMap; import java.util.stream.Collectors; @@ -44,7 +44,7 @@ public void run() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { // NOP } } diff --git a/pipeline/pipeline-core/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/output/ArDoCoResult.java b/pipeline/pipeline-core/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/output/ArDoCoResult.java index a83c9e948..1dbbe9921 100644 --- a/pipeline/pipeline-core/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/output/ArDoCoResult.java +++ b/pipeline/pipeline-core/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/output/ArDoCoResult.java @@ -1,7 +1,8 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.api.output; -import java.util.HashMap; +import java.util.Comparator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -11,6 +12,7 @@ import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.set.ImmutableSet; import org.eclipse.collections.api.set.MutableSet; +import org.eclipse.collections.api.set.sorted.ImmutableSortedSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,6 +35,7 @@ import edu.kit.kastel.mcse.ardoco.core.api.text.Sentence; import edu.kit.kastel.mcse.ardoco.core.api.text.Text; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.TextState; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; @@ -40,6 +43,7 @@ * This record represents the result of running ArDoCo. It is backed by a {@link DataRepository} and grabs data from it. Besides accessing all data from the * calculation steps, this record also provides some convenience methods to directly access results such as found trace links and detected inconsistencies. */ +@Deterministic public record ArDoCoResult(DataRepository dataRepository) { private static final Logger logger = LoggerFactory.getLogger(ArDoCoResult.class); @@ -72,9 +76,10 @@ public ImmutableSet getTraceLinksForModel(String modelId) { * @param modelId the ID of the model that should be traced * @return Trace links for the model with the given id as Strings */ - public ImmutableSet getTraceLinksForModelAsStrings(String modelId) { + public ImmutableSortedSet getTraceLinksForModelAsStrings(String modelId) { var formatString = "%s,%d"; - return getTraceLinksForModel(modelId).collect(tl -> String.format(formatString, tl.getModelElementUid(), tl.getSentenceNumber() + 1)); + return getTraceLinksForModel(modelId).collect(tl -> String.format(formatString, tl.getModelElementUid(), tl.getSentenceNumber() + 1)) + .toImmutableSortedSet(); } /** @@ -92,12 +97,13 @@ public ImmutableList getAllTraceLinks() { } /** - * Returns the set of {@link SadSamTraceLink}s as strings. The strings are beautified to have a human-readable format + * Returns the set of {@link SadSamTraceLink SadSamTraceLinks} as strings. The strings are beautified to have a human-readable format * * @return Trace links as Strings */ public List getAllTraceLinksAsBeautifiedStrings() { - return getAllTraceLinks().toSortedList(SadSamTraceLink::compareTo).collect(ArDoCoResult::formatTraceLinksHumanReadable); + return getAllTraceLinks().toSortedList(Comparator.comparingInt(SadSamTraceLink::getSentenceNumber)) + .collect(ArDoCoResult::formatTraceLinksHumanReadable); } private static String formatTraceLinksHumanReadable(SadSamTraceLink traceLink) { @@ -201,7 +207,7 @@ public ImmutableList getAllModelInconsistencies() { * @return all InconsistentSentences */ public ImmutableList getInconsistentSentences() { - Map incSentenceMap = new HashMap<>(); + Map incSentenceMap = new LinkedHashMap<>(); var inconsistencies = getAllTextInconsistencies(); for (var inconsistency : inconsistencies) { diff --git a/pipeline/pipeline-core/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/FilePrinter.java b/pipeline/pipeline-core/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/FilePrinter.java index caa0584b0..a1291e08a 100644 --- a/pipeline/pipeline-core/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/FilePrinter.java +++ b/pipeline/pipeline-core/src/main/java/edu/kit/kastel/mcse/ardoco/core/common/util/FilePrinter.java @@ -1,7 +1,11 @@ /* Licensed under MIT 2021-2023. */ package edu.kit.kastel.mcse.ardoco.core.common.util; -import static edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper.*; +import static edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper.getConnectionStates; +import static edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper.getInconsistencyStates; +import static edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper.getModelStatesData; +import static edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper.getRecommendationStates; +import static edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper.getTextState; import static java.nio.charset.StandardCharsets.UTF_8; import java.io.BufferedWriter; @@ -15,7 +19,6 @@ import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.util.Comparator; -import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.function.Supplier; @@ -46,10 +49,12 @@ import edu.kit.kastel.mcse.ardoco.core.api.textextraction.MappingKind; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.NounMapping; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.TextState; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; /** * The Class FilePrinter contains some helpers for stats. */ +@Deterministic public final class FilePrinter { private static final String DELIMITER = ","; @@ -334,7 +339,7 @@ private static ImmutableList getLinksAsDataLinesOfConnectionState(Conn dataLines.add(new String[] { "" }); dataLines.add(new String[] { "modelElementID", "sentence", "confidence" }); - Set tracelinks = new HashSet<>(connectionState.getTraceLinks().castToCollection()); + Set tracelinks = new java.util.LinkedHashSet<>(connectionState.getTraceLinks().castToCollection()); for (var tracelink : tracelinks) { var modelElementUid = tracelink.getModelElementUid(); // sentence offset is 1 because real sentences are 1-indexed diff --git a/pipeline/pipeline-core/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ConfigurationHelper.java b/pipeline/pipeline-core/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ConfigurationHelper.java index 74d18e5c6..44fae55d4 100644 --- a/pipeline/pipeline-core/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ConfigurationHelper.java +++ b/pipeline/pipeline-core/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ConfigurationHelper.java @@ -8,11 +8,11 @@ import java.lang.reflect.Modifier; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Scanner; +import java.util.SortedMap; import java.util.TreeMap; import java.util.stream.Collectors; @@ -20,10 +20,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.configuration.AbstractConfigurable; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.configuration.ConfigurationInstantiatorUtils; +@Deterministic public class ConfigurationHelper { private static final Logger logger = LoggerFactory.getLogger(ConfigurationHelper.class); @@ -37,8 +39,8 @@ private ConfigurationHelper() throws IllegalAccessException { * @param additionalConfigsFile the file containing the additional configurations * @return a Map with the additional configurations */ - public static Map loadAdditionalConfigs(File additionalConfigsFile) { - Map additionalConfigs = new HashMap<>(); + public static SortedMap loadAdditionalConfigs(File additionalConfigsFile) { + SortedMap additionalConfigs = new TreeMap<>(); if (additionalConfigsFile != null && (!additionalConfigsFile.exists() || !additionalConfigsFile.isFile())) { throw new IllegalArgumentException("File " + additionalConfigsFile + " is not a valid configuration file!"); } diff --git a/pipeline/pipeline-core/src/test/java/edu/kit/kastel/mcse/ardoco/core/execution/ConfigurationHelperTest.java b/pipeline/pipeline-core/src/test/java/edu/kit/kastel/mcse/ardoco/core/execution/ConfigurationHelperTest.java index 163477228..146220703 100644 --- a/pipeline/pipeline-core/src/test/java/edu/kit/kastel/mcse/ardoco/core/execution/ConfigurationHelperTest.java +++ b/pipeline/pipeline-core/src/test/java/edu/kit/kastel/mcse/ardoco/core/execution/ConfigurationHelperTest.java @@ -3,14 +3,17 @@ import java.util.List; import java.util.Map; +import java.util.SortedMap; import java.util.TreeMap; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.configuration.AbstractConfigurable; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; +@Deterministic class ConfigurationHelperTest { @Test @@ -27,7 +30,7 @@ void getDefaultConfigurationOptionsTest() { @Test void testBasicConfigurable() throws Exception { - Map configs = new TreeMap<>(); + SortedMap configs = new TreeMap<>(); ConfigurationHelper.processConfigurationOfClass(configs, TestConfigurable.class); Assertions.assertEquals(5, configs.size()); @@ -45,7 +48,7 @@ void testBasicConfigurable() throws Exception { Assertions.assertEquals(TestConfigurable.MyEnum.B, t.testEnumNo); //@formatter:off - configs = Map.of(// + configs = new TreeMap<>(Map.of(// TestConfigurable.class.getSimpleName() + AbstractConfigurable.CLASS_ATTRIBUTE_CONNECTOR + "testInt", "42", // TestConfigurable.class.getSimpleName() + AbstractConfigurable.CLASS_ATTRIBUTE_CONNECTOR + "testIntNo", "42", // TestConfigurable.class.getSimpleName() + AbstractConfigurable.CLASS_ATTRIBUTE_CONNECTOR + "testDouble", "48", // @@ -57,7 +60,7 @@ void testBasicConfigurable() throws Exception { TestConfigurable.class.getSimpleName() + AbstractConfigurable.CLASS_ATTRIBUTE_CONNECTOR + "testEnum", TestConfigurable.MyEnum.C.name(), // TestConfigurable.class.getSimpleName() + AbstractConfigurable.CLASS_ATTRIBUTE_CONNECTOR + "testEnumNo", TestConfigurable.MyEnum.C.name() - ); + )); //@formatter:on t.applyConfiguration(configs); @@ -98,7 +101,7 @@ public TestConfigurable() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { } private enum MyEnum { diff --git a/pipeline/pipeline-id/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/runner/ArDoCoForInconsistencyDetection.java b/pipeline/pipeline-id/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/runner/ArDoCoForInconsistencyDetection.java index fe79d4f73..b27fa5c6a 100644 --- a/pipeline/pipeline-id/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/runner/ArDoCoForInconsistencyDetection.java +++ b/pipeline/pipeline-id/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/runner/ArDoCoForInconsistencyDetection.java @@ -3,7 +3,7 @@ import java.io.File; import java.io.IOException; -import java.util.Map; +import java.util.SortedMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,8 +26,8 @@ public ArDoCoForInconsistencyDetection(String projectName) { super(projectName); } - public void setUp(File inputText, File inputModelArchitecture, ArchitectureModelType inputArchitectureModelType, Map additionalConfigs, - File outputDir) { + public void setUp(File inputText, File inputModelArchitecture, ArchitectureModelType inputArchitectureModelType, + SortedMap additionalConfigs, File outputDir) { try { definePipeline(inputText, inputModelArchitecture, inputArchitectureModelType, additionalConfigs); } catch (IOException e) { @@ -40,7 +40,7 @@ public void setUp(File inputText, File inputModelArchitecture, ArchitectureModel } public void setUp(String inputTextLocation, String inputArchitectureModelLocation, ArchitectureModelType architectureModelType, - Map additionalConfigs, String outputDirectory) { + SortedMap additionalConfigs, String outputDirectory) { setUp(new File(inputTextLocation), new File(inputArchitectureModelLocation), architectureModelType, additionalConfigs, new File(outputDirectory)); } @@ -53,8 +53,8 @@ public void setUp(String inputTextLocation, String inputArchitectureModelLocatio * @param additionalConfigs the additional configs * @throws IOException When one of the input files cannot be accessed/loaded */ - private void definePipeline(File inputText, File inputArchitectureModel, ArchitectureModelType architectureModelType, Map additionalConfigs) - throws IOException { + private void definePipeline(File inputText, File inputArchitectureModel, ArchitectureModelType architectureModelType, + SortedMap additionalConfigs) throws IOException { ArDoCo arDoCo = getArDoCo(); var dataRepository = arDoCo.getDataRepository(); var text = CommonUtilities.readInputText(inputText); diff --git a/pipeline/pipeline-lissa/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/runner/ArDoCoForLiSSA.java b/pipeline/pipeline-lissa/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/runner/ArDoCoForLiSSA.java index a797dc7ad..d652dd8d6 100644 --- a/pipeline/pipeline-lissa/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/runner/ArDoCoForLiSSA.java +++ b/pipeline/pipeline-lissa/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/runner/ArDoCoForLiSSA.java @@ -3,7 +3,7 @@ import java.io.File; import java.io.IOException; -import java.util.Map; +import java.util.SortedMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,7 +31,7 @@ public ArDoCoForLiSSA(String projectName) { } public void setUp(File diagramDirectory, File inputText, File inputModelArchitecture, ArchitectureModelType inputArchitectureModelType, - Map additionalConfigs, File outputDir) { + SortedMap additionalConfigs, File outputDir) { try { definePipeline(diagramDirectory, inputText, inputModelArchitecture, inputArchitectureModelType, additionalConfigs); } catch (IOException e) { @@ -44,7 +44,7 @@ public void setUp(File diagramDirectory, File inputText, File inputModelArchitec } public void setUp(String diagramDirectory, String inputTextLocation, String inputArchitectureModelLocation, ArchitectureModelType architectureModelType, - Map additionalConfigs, String outputDirectory) { + SortedMap additionalConfigs, String outputDirectory) { setUp(new File(diagramDirectory), new File(inputTextLocation), new File(inputArchitectureModelLocation), architectureModelType, additionalConfigs, new File(outputDirectory)); } @@ -60,7 +60,7 @@ public void setUp(String diagramDirectory, String inputTextLocation, String inpu * @throws IOException When one of the input files cannot be accessed/loaded */ private void definePipeline(File diagramDirectory, File inputText, File inputArchitectureModel, ArchitectureModelType architectureModelType, - Map additionalConfigs) throws IOException { + SortedMap additionalConfigs) throws IOException { ArDoCo arDoCo = getArDoCo(); var dataRepository = arDoCo.getDataRepository(); var text = CommonUtilities.readInputText(inputText); diff --git a/pipeline/pipeline-tlr/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ArDoCoForSadCodeTraceabilityLinkRecovery.java b/pipeline/pipeline-tlr/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ArDoCoForSadCodeTraceabilityLinkRecovery.java index f7c678d2d..e0613450a 100644 --- a/pipeline/pipeline-tlr/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ArDoCoForSadCodeTraceabilityLinkRecovery.java +++ b/pipeline/pipeline-tlr/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ArDoCoForSadCodeTraceabilityLinkRecovery.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.execution; import java.io.File; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.api.models.ArchitectureModelType; import edu.kit.kastel.mcse.ardoco.core.codetraceability.SadCodeTraceabilityLinkRecovery; @@ -23,7 +23,7 @@ public ArDoCoForSadCodeTraceabilityLinkRecovery(String projectName) { } public void setUp(File inputText, File inputArchitectureModel, ArchitectureModelType architectureModelType, File inputCode, - Map additionalConfigs, File outputDir) { + SortedMap additionalConfigs, File outputDir) { definePipeline(inputText, inputArchitectureModel, architectureModelType, inputCode, additionalConfigs); setOutputDirectory(outputDir); @@ -31,7 +31,7 @@ public void setUp(File inputText, File inputArchitectureModel, ArchitectureModel } private void definePipeline(File inputText, File inputArchitectureModel, ArchitectureModelType architectureModelType, File inputCode, - Map additionalConfigs) { + SortedMap additionalConfigs) { ArDoCo arDoCo = this.getArDoCo(); var dataRepository = arDoCo.getDataRepository(); diff --git a/pipeline/pipeline-tlr/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ArDoCoForSadSamCodeTraceabilityLinkRecovery.java b/pipeline/pipeline-tlr/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ArDoCoForSadSamCodeTraceabilityLinkRecovery.java index 0f3da2ddf..184ad1260 100644 --- a/pipeline/pipeline-tlr/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ArDoCoForSadSamCodeTraceabilityLinkRecovery.java +++ b/pipeline/pipeline-tlr/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ArDoCoForSadSamCodeTraceabilityLinkRecovery.java @@ -3,7 +3,7 @@ import java.io.File; import java.io.IOException; -import java.util.Map; +import java.util.SortedMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,7 +29,7 @@ public ArDoCoForSadSamCodeTraceabilityLinkRecovery(String projectName) { } public void setUp(File inputText, File inputArchitectureModel, ArchitectureModelType architectureModelType, File inputCode, - Map additionalConfigs, File outputDir) { + SortedMap additionalConfigs, File outputDir) { try { definePipeline(inputText, inputArchitectureModel, architectureModelType, inputCode, additionalConfigs); } catch (IOException e) { @@ -43,7 +43,7 @@ public void setUp(File inputText, File inputArchitectureModel, ArchitectureModel } private void definePipeline(File inputText, File inputArchitectureModel, ArchitectureModelType architectureModelType, File inputCode, - Map additionalConfigs) throws IOException { + SortedMap additionalConfigs) throws IOException { ArDoCo arDoCo = this.getArDoCo(); var dataRepository = arDoCo.getDataRepository(); diff --git a/pipeline/pipeline-tlr/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ArDoCoForSadSamTraceabilityLinkRecovery.java b/pipeline/pipeline-tlr/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ArDoCoForSadSamTraceabilityLinkRecovery.java index 7fa703635..63c3cfe88 100644 --- a/pipeline/pipeline-tlr/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ArDoCoForSadSamTraceabilityLinkRecovery.java +++ b/pipeline/pipeline-tlr/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ArDoCoForSadSamTraceabilityLinkRecovery.java @@ -3,7 +3,7 @@ import java.io.File; import java.io.IOException; -import java.util.Map; +import java.util.SortedMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,7 +25,7 @@ public ArDoCoForSadSamTraceabilityLinkRecovery(String projectName) { super(projectName); } - public void setUp(File inputText, File inputArchitectureModel, ArchitectureModelType architectureModelType, Map additionalConfigs, + public void setUp(File inputText, File inputArchitectureModel, ArchitectureModelType architectureModelType, SortedMap additionalConfigs, File outputDir) { try { definePipeline(inputText, inputArchitectureModel, architectureModelType, additionalConfigs); @@ -39,12 +39,12 @@ public void setUp(File inputText, File inputArchitectureModel, ArchitectureModel } public void setUp(String inputTextLocation, String inputArchitectureModelLocation, ArchitectureModelType architectureModelType, - Map additionalConfigs, String outputDirectory) { + SortedMap additionalConfigs, String outputDirectory) { setUp(new File(inputTextLocation), new File(inputArchitectureModelLocation), architectureModelType, additionalConfigs, new File(outputDirectory)); } - private void definePipeline(File inputText, File inputArchitectureModel, ArchitectureModelType architectureModelType, Map additionalConfigs) - throws IOException { + private void definePipeline(File inputText, File inputArchitectureModel, ArchitectureModelType architectureModelType, + SortedMap additionalConfigs) throws IOException { var dataRepository = this.getArDoCo().getDataRepository(); var text = CommonUtilities.readInputText(inputText); if (text.isBlank()) { diff --git a/pipeline/pipeline-tlr/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ArDoCoForSamCodeTraceabilityLinkRecovery.java b/pipeline/pipeline-tlr/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ArDoCoForSamCodeTraceabilityLinkRecovery.java index 84a73441e..f4efbd824 100644 --- a/pipeline/pipeline-tlr/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ArDoCoForSamCodeTraceabilityLinkRecovery.java +++ b/pipeline/pipeline-tlr/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ArDoCoForSamCodeTraceabilityLinkRecovery.java @@ -2,10 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.execution; import java.io.File; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.api.models.ArchitectureModelType; import edu.kit.kastel.mcse.ardoco.core.codetraceability.SamCodeTraceabilityLinkRecovery; @@ -13,13 +10,12 @@ import edu.kit.kastel.mcse.ardoco.core.models.ArCoTLModelProviderAgent; public class ArDoCoForSamCodeTraceabilityLinkRecovery extends ArDoCoRunner { - private static final Logger logger = LoggerFactory.getLogger(ArDoCoForSamCodeTraceabilityLinkRecovery.class); public ArDoCoForSamCodeTraceabilityLinkRecovery(String projectName) { super(projectName); } - public void setUp(File inputArchitectureModel, ArchitectureModelType architectureModelType, File inputCode, Map additionalConfigs, + public void setUp(File inputArchitectureModel, ArchitectureModelType architectureModelType, File inputCode, SortedMap additionalConfigs, File outputDir) { definePipeline(inputArchitectureModel, architectureModelType, inputCode, additionalConfigs); setOutputDirectory(outputDir); @@ -27,7 +23,7 @@ public void setUp(File inputArchitectureModel, ArchitectureModelType architectur } private void definePipeline(File inputArchitectureModel, ArchitectureModelType architectureModelType, File inputCode, - Map additionalConfigs) { + SortedMap additionalConfigs) { ArDoCo arDoCo = this.getArDoCo(); var dataRepository = arDoCo.getDataRepository(); diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/CodeTraceabilityStateImpl.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/CodeTraceabilityStateImpl.java index 9df837c70..cd3fc5d43 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/CodeTraceabilityStateImpl.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/CodeTraceabilityStateImpl.java @@ -2,16 +2,20 @@ package edu.kit.kastel.mcse.ardoco.core.codetraceability; import java.util.Collection; +import java.util.LinkedHashSet; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.set.ImmutableSet; +import org.eclipse.collections.impl.factory.Sets; import edu.kit.kastel.mcse.ardoco.core.api.codetraceability.CodeTraceabilityState; import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.SadCodeTraceLink; import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.SamCodeTraceLink; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.data.AbstractState; +@Deterministic public class CodeTraceabilityStateImpl extends AbstractState implements CodeTraceabilityState { private transient MutableList samCodeTraceLinks = Lists.mutable.empty(); @@ -29,7 +33,7 @@ public boolean addSamCodeTraceLinks(Collection traceLinks) { @Override public ImmutableSet getSamCodeTraceLinks() { - return this.samCodeTraceLinks.toImmutableSet(); + return Sets.immutable.withAll(new LinkedHashSet<>(this.samCodeTraceLinks)); } @Override diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SadCodeTraceabilityLinkRecovery.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SadCodeTraceabilityLinkRecovery.java index e8613a43d..a78010cb0 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SadCodeTraceabilityLinkRecovery.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SadCodeTraceabilityLinkRecovery.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.codetraceability; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.MutableList; @@ -30,7 +30,7 @@ public SadCodeTraceabilityLinkRecovery(DataRepository dataRepository) { enabledAgents = agents.collect(Agent::getId); } - public static SadCodeTraceabilityLinkRecovery get(Map additionalConfigs, DataRepository dataRepository) { + public static SadCodeTraceabilityLinkRecovery get(SortedMap additionalConfigs, DataRepository dataRepository) { var sadSamCodeTraceabilityLinkRecovery = new SadCodeTraceabilityLinkRecovery(dataRepository); sadSamCodeTraceabilityLinkRecovery.applyConfiguration(additionalConfigs); return sadSamCodeTraceabilityLinkRecovery; @@ -51,7 +51,7 @@ protected List getEnabledAgents() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { super.delegateApplyConfigurationToInternalObjects(additionalConfiguration); for (var agent : agents) { agent.applyConfiguration(additionalConfiguration); diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SadSamCodeTraceabilityLinkRecovery.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SadSamCodeTraceabilityLinkRecovery.java index b6e65385f..3e724f2d0 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SadSamCodeTraceabilityLinkRecovery.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SadSamCodeTraceabilityLinkRecovery.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.codetraceability; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.MutableList; @@ -30,7 +30,7 @@ public SadSamCodeTraceabilityLinkRecovery(DataRepository dataRepository) { enabledAgents = agents.collect(Agent::getId); } - public static SadSamCodeTraceabilityLinkRecovery get(Map additionalConfigs, DataRepository dataRepository) { + public static SadSamCodeTraceabilityLinkRecovery get(SortedMap additionalConfigs, DataRepository dataRepository) { var sadSamCodeTraceabilityLinkRecovery = new SadSamCodeTraceabilityLinkRecovery(dataRepository); sadSamCodeTraceabilityLinkRecovery.applyConfiguration(additionalConfigs); return sadSamCodeTraceabilityLinkRecovery; @@ -51,7 +51,7 @@ protected List getEnabledAgents() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { super.delegateApplyConfigurationToInternalObjects(additionalConfiguration); for (var agent : agents) { agent.applyConfiguration(additionalConfiguration); diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SamCodeTraceabilityLinkRecovery.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SamCodeTraceabilityLinkRecovery.java index 64d4b4dac..0ab48bab6 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SamCodeTraceabilityLinkRecovery.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/SamCodeTraceabilityLinkRecovery.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.codetraceability; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.MutableList; @@ -30,7 +30,7 @@ public SamCodeTraceabilityLinkRecovery(DataRepository dataRepository) { enabledAgents = agents.collect(Agent::getId); } - public static SamCodeTraceabilityLinkRecovery get(Map additionalConfigs, DataRepository dataRepository) { + public static SamCodeTraceabilityLinkRecovery get(SortedMap additionalConfigs, DataRepository dataRepository) { var samCodeTraceabilityLinkRecovery = new SamCodeTraceabilityLinkRecovery(dataRepository); samCodeTraceabilityLinkRecovery.applyConfiguration(additionalConfigs); return samCodeTraceabilityLinkRecovery; @@ -51,7 +51,7 @@ protected List getEnabledAgents() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { super.delegateApplyConfigurationToInternalObjects(additionalConfiguration); for (var agent : agents) { agent.applyConfiguration(additionalConfiguration); diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/ArchitectureLinkToCodeLinkTransformerAgent.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/ArchitectureLinkToCodeLinkTransformerAgent.java index c29198054..0f43401f1 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/ArchitectureLinkToCodeLinkTransformerAgent.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/ArchitectureLinkToCodeLinkTransformerAgent.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.codetraceability.agents; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.MutableList; @@ -40,7 +40,7 @@ protected List getEnabledPipelineSteps() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { informants.forEach(filter -> filter.applyConfiguration(additionalConfiguration)); } } diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/InitialCodeTraceabilityAgent.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/InitialCodeTraceabilityAgent.java index 4b6a4f650..1f1a51529 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/InitialCodeTraceabilityAgent.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/InitialCodeTraceabilityAgent.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.codetraceability.agents; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.MutableList; @@ -37,7 +37,7 @@ protected List getEnabledPipelineSteps() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { informants.forEach(filter -> filter.applyConfiguration(additionalConfiguration)); } } diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/TransitiveTraceabilityAgent.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/TransitiveTraceabilityAgent.java index 901756634..11f5b6471 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/TransitiveTraceabilityAgent.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/agents/TransitiveTraceabilityAgent.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.codetraceability.agents; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.MutableList; @@ -38,7 +38,7 @@ protected List getEnabledPipelineSteps() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { informants.forEach(filter -> filter.applyConfiguration(additionalConfiguration)); } } diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/ArCoTLInformant.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/ArCoTLInformant.java index b98b599fb..6fcf86082 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/ArCoTLInformant.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/ArCoTLInformant.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.codetraceability.informants; import java.util.Arrays; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.api.models.ArchitectureModelType; import edu.kit.kastel.mcse.ardoco.core.api.models.CodeModelType; @@ -49,7 +49,7 @@ private static boolean isAnArchitectureModel(String modelId) { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { // empty } diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/ArchitectureLinkToCodeLinkTransformerInformant.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/ArchitectureLinkToCodeLinkTransformerInformant.java index 05aae0ee0..4cef4436d 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/ArchitectureLinkToCodeLinkTransformerInformant.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/ArchitectureLinkToCodeLinkTransformerInformant.java @@ -3,7 +3,7 @@ import java.util.ArrayList; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Sets; import org.eclipse.collections.api.set.MutableSet; @@ -16,11 +16,13 @@ import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodeModel; import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.EndpointTuple; import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.SadCodeTraceLink; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.codetraceability.CodeTraceabilityStateImpl; import edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant; +@Deterministic public class ArchitectureLinkToCodeLinkTransformerInformant extends Informant { public ArchitectureLinkToCodeLinkTransformerInformant(DataRepository dataRepository) { @@ -94,7 +96,7 @@ private CodeModel findCodeModel(ModelStates models) { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { // empty } } diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/TraceLinkCombiner.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/TraceLinkCombiner.java index dc6fa60de..24a682607 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/TraceLinkCombiner.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/TraceLinkCombiner.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2023. */ package edu.kit.kastel.mcse.ardoco.core.codetraceability.informants; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Sets; import org.eclipse.collections.api.set.ImmutableSet; @@ -14,10 +14,12 @@ import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.SadSamTraceLink; import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.SamCodeTraceLink; import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.TransitiveTraceLink; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant; +@Deterministic public class TraceLinkCombiner extends Informant { public TraceLinkCombiner(DataRepository dataRepository) { @@ -64,7 +66,7 @@ private ImmutableSet combineToTransitiveTraceLinks(ImmutableSe } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { // empty } } diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/NameComparisonUtils.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/NameComparisonUtils.java index 027a7da5d..1bed7e4c2 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/NameComparisonUtils.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/NameComparisonUtils.java @@ -2,10 +2,10 @@ package edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Properties; -import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import edu.kit.kastel.mcse.ardoco.core.api.models.Entity; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodeCompilationUnit; @@ -82,7 +82,7 @@ private static boolean isContained(String a, List names, PreprocessingMe // - public static List removeWords(Entity namedEntity, Set wordsToRemove) { + public static List removeWords(Entity namedEntity, SortedSet wordsToRemove) { List words = NameComparisonUtils.getProcessedSplit(namedEntity.getName()); for (String word : wordsToRemove) { words.remove(NameComparisonUtils.preprocess(word)); @@ -90,8 +90,8 @@ public static List removeWords(Entity namedEntity, Set wordsToRe return words; } - public static Set removeWords(Set words, Entity namedEntity) { - Set result = new HashSet<>(); + public static SortedSet removeWords(SortedSet words, Entity namedEntity) { + SortedSet result = new TreeSet<>(); List wordsToRemove = NameComparisonUtils.getProcessedSplit(namedEntity.getName()); for (String word : words) { word = preprocess(word); diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/TraceLinkGenerator.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/TraceLinkGenerator.java index 6847fee5e..48a71c5ec 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/TraceLinkGenerator.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/TraceLinkGenerator.java @@ -1,22 +1,31 @@ /* Licensed under MIT 2023. */ package edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl; -import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureModel; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodeModel; import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.SamCodeTraceLink; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.computation.Computation; import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.computation.computationtree.Node; import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.aggregation.Filter; import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.aggregation.MatchBest; import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.aggregation.MatchSequentially; import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.aggregation.Maximum; -import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.heuristics.*; - +import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.heuristics.ComponentNameResemblance; +import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.heuristics.ComponentNameResemblanceTest; +import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.heuristics.InheritLinks; +import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.heuristics.MethodResemblance; +import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.heuristics.PackageResemblance; +import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.heuristics.PathResemblance; +import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.heuristics.ProvidedInterfaceCorrespondence; +import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.heuristics.Required; +import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.heuristics.SubpackageFilter; + +@Deterministic public final class TraceLinkGenerator { private static final Node interfaceName = new ComponentNameResemblance(ComponentNameResemblance.NameConfig.INTERFACE, @@ -48,7 +57,7 @@ public final class TraceLinkGenerator { private static final Node root = Filter.getFilterArchNode(maxCompInterface, new ProvidedInterfaceCorrespondence().getNode(maxCompInterface)); - private static final Map treeConfigs = new HashMap<>(); + private static final Map treeConfigs = new LinkedHashMap<>(); static { treeConfigs.put(interfaceName, "interfaceName"); @@ -111,7 +120,7 @@ public static Node getRoot(NameComparisonUtils.PreprocessingMethod preprocessCon public static Set generateTraceLinks(Node root, ArchitectureModel archModel, CodeModel codeModel) { if (archModel == null || codeModel == null) { - return new HashSet<>(); + return new java.util.LinkedHashSet<>(); } if (root == null) { root = getRoot(); diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/computation/Computation.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/computation/Computation.java index 1a16cf2dc..360be5f5d 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/computation/Computation.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/computation/Computation.java @@ -6,12 +6,14 @@ import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureModel; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodeModel; import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.SamCodeTraceLink; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.computation.computationtree.Node; /** * A computation. Calculates the {@link Confidence confidences} and trace links * for a computation tree. */ +@Deterministic public class Computation { private final Node root; diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/computation/ComputationResult.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/computation/ComputationResult.java index 89eed2198..8e879dba8 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/computation/ComputationResult.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/computation/ComputationResult.java @@ -1,14 +1,14 @@ /* Licensed under MIT 2023. */ package edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.computation; -import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.EndpointTuple; import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.SamCodeTraceLink; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.computation.computationtree.Node; /** @@ -16,6 +16,7 @@ * combination of computation node and endpoint tuple to exactly one * {@link Confidence confidence}. */ +@Deterministic public class ComputationResult { private final Map resultMap; @@ -25,7 +26,7 @@ public class ComputationResult { * still need to be added after they have been calculated. */ public ComputationResult() { - resultMap = new HashMap<>(); + resultMap = new LinkedHashMap<>(); } /** @@ -73,7 +74,7 @@ public NodeResult getNodeResult(Node node) { */ public Set getTraceLinks(Node node) { if (!exists(node)) { - return new HashSet<>(); + return new java.util.LinkedHashSet<>(); } NodeResult nodeResult = resultMap.get(node); return nodeResult.getTraceLinks(); @@ -130,7 +131,7 @@ public List getConfidenceStrings(Node node, EndpointTuple endpointTuple) } private Map getConfidenceStringsToLevelMap(Node node, EndpointTuple endpointTuple, int level) { - Map confidenceToLevel = new HashMap<>(); + Map confidenceToLevel = new LinkedHashMap<>(); Confidence confidence = getNodeResult(node).getConfidence(endpointTuple); String confidenceString = "Level " + level + ": " + node.toString() + ", Confidence: " + confidence; confidenceToLevel.put(confidenceString, level); diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/computation/EndpointTupleRepo.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/computation/EndpointTupleRepo.java index 78b4d2f08..4735115cd 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/computation/EndpointTupleRepo.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/computation/EndpointTupleRepo.java @@ -1,8 +1,8 @@ /* Licensed under MIT 2023. */ package edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.computation; -import java.util.HashSet; -import java.util.Set; +import java.util.ArrayList; +import java.util.List; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureModel; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodeModel; @@ -14,7 +14,7 @@ */ public class EndpointTupleRepo { - private Set endpointTuples; + private List endpointTuples; /** * Creates a new repository of endpoint tuples. Contains every possible @@ -27,7 +27,7 @@ public class EndpointTupleRepo { * repository */ public EndpointTupleRepo(ArchitectureModel archModel, CodeModel codeModel) { - endpointTuples = new HashSet<>(); + endpointTuples = new ArrayList<>(); for (var architectureEndpoint : archModel.getEndpoints()) { for (var codeEndpoint : codeModel.getEndpoints()) { endpointTuples.add(new SamCodeEndpointTuple(architectureEndpoint, codeEndpoint)); @@ -40,7 +40,7 @@ public EndpointTupleRepo(ArchitectureModel archModel, CodeModel codeModel) { * * @return all endpoint tuples */ - public Set getEndpointTuples() { - return endpointTuples; + public List getEndpointTuples() { + return new ArrayList<>(endpointTuples); } } diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/computation/NodeResult.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/computation/NodeResult.java index e2593f73e..41dc06dd5 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/computation/NodeResult.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/computation/NodeResult.java @@ -1,10 +1,12 @@ /* Licensed under MIT 2023. */ package edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.computation; -import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import edu.kit.kastel.mcse.ardoco.core.api.models.Entity; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureItem; @@ -13,11 +15,13 @@ import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodeModel; import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.EndpointTuple; import edu.kit.kastel.mcse.ardoco.core.api.models.tracelinks.SamCodeTraceLink; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; /** * The result of a computation node. A computation node's final result are the * calculated {@link Confidence confidences} of every endpoint tuple. */ +@Deterministic public class NodeResult { private final Map confidenceMap; @@ -28,11 +32,11 @@ public class NodeResult { * been calculated. */ public NodeResult() { - confidenceMap = new HashMap<>(); + confidenceMap = new LinkedHashMap<>(); } public NodeResult(ArchitectureModel archModel, CodeModel codeModel) { - confidenceMap = new HashMap<>(); + confidenceMap = new LinkedHashMap<>(); EndpointTupleRepo endpointTupleRepo = new EndpointTupleRepo(archModel, codeModel); for (SamCodeEndpointTuple endpointTuple : endpointTupleRepo.getEndpointTuples()) { add(endpointTuple, new Confidence()); @@ -76,8 +80,8 @@ public NodeResult getEndpointTuples(Entity endpoint, Confidence confidence) { return result; } - public Set getLinkedEndpoints(Entity endpoint) { - Set linkedEndpoints = new HashSet<>(); + public SortedSet getLinkedEndpoints(Entity endpoint) { + SortedSet linkedEndpoints = new TreeSet<>(); for (var entry : confidenceMap.entrySet()) { SamCodeEndpointTuple tuple = entry.getKey(); Confidence confidence = entry.getValue(); @@ -97,7 +101,7 @@ public Set getLinkedEndpoints(Entity endpoint) { * @return trace links for every endpoint tuple whose confidence has a value */ public Set getTraceLinks() { - Set traceLinks = new HashSet<>(); + Set traceLinks = new LinkedHashSet<>(); for (var entry : confidenceMap.entrySet()) { Confidence confidence = entry.getValue(); if (confidence.hasValue()) { diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/aggregation/Filter.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/aggregation/Filter.java index 6c0732995..49a395c79 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/aggregation/Filter.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/aggregation/Filter.java @@ -5,11 +5,13 @@ import java.util.List; import edu.kit.kastel.mcse.ardoco.core.api.models.Entity; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.computation.NodeResult; import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.computation.computationtree.AggregationNode; import edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.computation.computationtree.Node; // filter every node after the first from the first +@Deterministic public class Filter extends Matcher { private boolean filterAlways; diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/ComponentNameResemblanceTest.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/ComponentNameResemblanceTest.java index 05026b2d2..66423b30e 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/ComponentNameResemblanceTest.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/ComponentNameResemblanceTest.java @@ -1,9 +1,9 @@ /* Licensed under MIT 2023. */ package edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.heuristics; -import java.util.HashSet; import java.util.List; -import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import edu.kit.kastel.mcse.ardoco.core.api.models.Entity; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureComponent; @@ -17,7 +17,7 @@ public class ComponentNameResemblanceTest extends DependentHeuristic { - private static final Set commonWords = Set.of("Test", "Action", "Impl", "Factory", "Exception"); + private static final SortedSet commonWords = new TreeSet<>(List.of("Test", "Action", "Impl", "Factory", "Exception")); @Override protected Confidence calculateConfidence(ArchitectureComponent archComponent, CodeCompilationUnit compUnit) { @@ -36,16 +36,16 @@ private Confidence calculateNameResemblance(ArchitectureItem archEndpoint, CodeC if (getNodeResult().getConfidence(new EndpointTuple(archEndpoint, compUnit)).hasValue()) { return new Confidence(); } - Set filteredCommonWords = new HashSet<>(commonWords); + SortedSet filteredCommonWords = new TreeSet<>(commonWords); for (Entity ae : getArchModel().getEndpoints()) { filteredCommonWords = NameComparisonUtils.removeWords(filteredCommonWords, ae); } - Set items = compUnit.getAllDataTypesAndSelf(); - if (areSimilar(items, Set.of(archEndpoint), filteredCommonWords)) { + SortedSet items = compUnit.getAllDataTypesAndSelf(); + if (areSimilar(items, new TreeSet<>(List.of(archEndpoint)), filteredCommonWords)) { return new Confidence(1.0); } Confidence maxConfidence = new Confidence(); - Set linkedEndpoints = getNodeResult().getLinkedEndpoints(archEndpoint); + SortedSet linkedEndpoints = getNodeResult().getLinkedEndpoints(archEndpoint); for (Entity linkedEndpoint : linkedEndpoints) { CodeCompilationUnit linkedCompUnit = (CodeCompilationUnit) linkedEndpoint; if (InheritLinks.areInDifferentPackages(compUnit, linkedCompUnit) || !areSimilar(items, linkedCompUnit.getAllDataTypesAndSelf(), @@ -60,7 +60,7 @@ private Confidence calculateNameResemblance(ArchitectureItem archEndpoint, CodeC return maxConfidence; } - private static boolean areSimilar(Set entities1, Set entities2, Set filteredCommonWords) { + private static boolean areSimilar(SortedSet entities1, SortedSet entities2, SortedSet filteredCommonWords) { for (var entity1 : entities1) { for (var entity2 : entities2) { List words1 = NameComparisonUtils.removeWords(entity1, filteredCommonWords); diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/InheritLinks.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/InheritLinks.java index 2217c2ed0..2c72508d1 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/InheritLinks.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/InheritLinks.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2023. */ package edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.heuristics; -import java.util.Set; +import java.util.SortedSet; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureComponent; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureInterface; @@ -41,7 +41,7 @@ private Confidence inheritLinks(ArchitectureItem archEndpoint, CodeCompilationUn } private Confidence inheritLinks(ArchitectureItem archEndpoint, Datatype codeType) { - Set extendedTypes = MethodResemblance.getAllExtendedTypes(codeType); + SortedSet extendedTypes = MethodResemblance.getAllExtendedTypes(codeType); MethodResemblance.getAllImplementedInterfaces(codeType).forEach(i -> extendedTypes.addAll(MethodResemblance.getAllExtendedTypes(i))); Confidence maxConfidence = new Confidence(); diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/MethodResemblance.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/MethodResemblance.java index 8e64e28e9..063f53324 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/MethodResemblance.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/MethodResemblance.java @@ -1,8 +1,8 @@ /* Licensed under MIT 2023. */ package edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.heuristics; -import java.util.HashSet; -import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureInterface; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureMethod; @@ -21,7 +21,7 @@ protected Confidence calculateConfidence(ArchitectureInterface archInterface, Co return new Confidence(); } - Set firstMethods = compUnit.getDeclaredMethods(); + SortedSet firstMethods = compUnit.getDeclaredMethods(); for (Datatype datatype : compUnit.getAllDataTypes()) { for (ControlElement codeMethod : datatype.getDeclaredMethods()) { if (!isImplementedMethod(codeMethod, datatype) && !isExtendedMethod(codeMethod, datatype)) { @@ -53,22 +53,22 @@ protected Confidence calculateConfidence(ArchitectureInterface archInterface, Co } private boolean isImplementedMethod(ControlElement codeMethod, Datatype codeType) { - Set implMethods = new HashSet<>(); + SortedSet implMethods = new TreeSet<>(); getAllImplementedInterfaces(codeType).forEach(i -> getAllExtendedTypes(i).forEach(j -> implMethods.addAll(j.getDeclaredMethods()))); return implMethods.stream().anyMatch(implMethod -> implMethod.getName().equalsIgnoreCase(codeMethod.getName())); } private boolean isExtendedMethod(ControlElement codeMethod, Datatype codeType) { - Set extendedMethods = new HashSet<>(); - Set extendedTypes = getAllExtendedTypes(codeType); + SortedSet extendedMethods = new TreeSet<>(); + SortedSet extendedTypes = getAllExtendedTypes(codeType); extendedTypes.remove(codeType); extendedTypes.forEach(i -> extendedMethods.addAll(i.getDeclaredMethods())); return extendedMethods.stream().anyMatch(i -> i.getName().equalsIgnoreCase(codeMethod.getName())); } // returns extended types + type itself - public static Set getAllExtendedTypes(Datatype codeType) { - Set allExtendedTypes = new HashSet<>(); + public static SortedSet getAllExtendedTypes(Datatype codeType) { + SortedSet allExtendedTypes = new TreeSet<>(); allExtendedTypes.add(codeType); for (Datatype extendedType : codeType.getExtendedTypes()) { allExtendedTypes.add(extendedType); @@ -77,8 +77,8 @@ public static Set getAllExtendedTypes(Datatype codeType) { return allExtendedTypes; } - public static Set getAllImplementedInterfaces(Datatype codeType) { - Set allImplementedInterfaces = new HashSet<>(); + public static SortedSet getAllImplementedInterfaces(Datatype codeType) { + SortedSet allImplementedInterfaces = new TreeSet<>(); for (Datatype extendedType : getAllExtendedTypes(codeType)) { allImplementedInterfaces.addAll(extendedType.getImplementedTypes()); } diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/PathResemblance.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/PathResemblance.java index 4547b5785..97728fb9e 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/PathResemblance.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/PathResemblance.java @@ -1,9 +1,10 @@ /* Licensed under MIT 2023. */ package edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.heuristics; -import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import edu.kit.kastel.mcse.ardoco.core.api.models.Entity; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureComponent; @@ -41,9 +42,9 @@ private Confidence calculatePathResemblance(Entity archEndpoint, CodeCompilation return new Confidence(similarity); } - private Set getAllPackageNames() { - Set packages = getCodeModel().getAllPackages(); - Set allPackageNames = new HashSet<>(); + private SortedSet getAllPackageNames() { + List packages = getCodeModel().getAllPackages(); + SortedSet allPackageNames = new TreeSet<>(); for (CodePackage codePackage : packages) { allPackageNames.add(codePackage.getName()); } diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/ProvidedInterfaceCorrespondence.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/ProvidedInterfaceCorrespondence.java index 74a806fe8..7578f2817 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/ProvidedInterfaceCorrespondence.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/ProvidedInterfaceCorrespondence.java @@ -1,9 +1,9 @@ /* Licensed under MIT 2023. */ package edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.heuristics; -import java.util.HashSet; import java.util.List; -import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import edu.kit.kastel.mcse.ardoco.core.api.models.Entity; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureComponent; @@ -31,31 +31,31 @@ private Confidence calculateProvidedInterfaceCorrespondence(ArchitectureComponen return new Confidence(); } - Set interfaceLinks = new HashSet<>(); + SortedSet interfaceLinks = new TreeSet<>(); for (ArchitectureInterface providedInterface : archComponent.getProvidedInterfaces()) { interfaceLinks.addAll(getLinks(providedInterface)); } - Set componentPackage = getPackage(archComponent, compUnit); + SortedSet componentPackage = getPackage(archComponent, compUnit); if (containsAny(interfaceLinks, componentPackage)) { return new Confidence(); } - Set allPackages = getPackages(archComponent, getLinks(archComponent)); + SortedSet allPackages = getPackages(archComponent, getLinks(archComponent)); if (containsAny(interfaceLinks, allPackages)) { return new Confidence(1.0); } return new Confidence(); } - private boolean containsAny(Set interfaces, Set componentPackages) { + private boolean containsAny(SortedSet interfaces, SortedSet componentPackages) { if (componentPackages.isEmpty() || interfaces.isEmpty()) { return false; } return interfaces.stream().anyMatch(i -> componentPackages.stream().anyMatch(p -> overrides(p.getAllCompilationUnits(), i))); } - private boolean overrides(Set ces, Entity i) { + private boolean overrides(SortedSet ces, Entity i) { for (CodeCompilationUnit ce : ces) { if (getAllOverridenTypes(ce).contains(i)) { return true; @@ -64,9 +64,9 @@ private boolean overrides(Set ces, Entity i) { return false; } - private Set getAllOverridenTypes(CodeCompilationUnit ce) { - Set overridenCompUnits = new HashSet<>(); - Set overridenTypes = new HashSet<>(); + private SortedSet getAllOverridenTypes(CodeCompilationUnit ce) { + SortedSet overridenCompUnits = new TreeSet<>(); + SortedSet overridenTypes = new TreeSet<>(); for (Datatype codeType : ce.getAllDataTypes()) { overridenTypes.addAll(MethodResemblance.getAllExtendedTypes(codeType)); MethodResemblance.getAllImplementedInterfaces(codeType).forEach(i -> overridenTypes.addAll(MethodResemblance.getAllExtendedTypes(i))); @@ -75,30 +75,30 @@ private Set getAllOverridenTypes(CodeCompilationUnit ce) { return overridenCompUnits; } - private Set getLinks(Entity ae) { - Set ces = new HashSet<>(); - Set endpoints = getNodeResult().getLinkedEndpoints(ae); + private SortedSet getLinks(Entity ae) { + SortedSet ces = new TreeSet<>(); + SortedSet endpoints = getNodeResult().getLinkedEndpoints(ae); endpoints.forEach(endpoint -> ces.add((CodeCompilationUnit) endpoint)); return ces; } - private Set getPackages(Entity ae, Set ces) { - Set packages = new HashSet<>(); + private SortedSet getPackages(Entity ae, SortedSet ces) { + SortedSet packages = new TreeSet<>(); for (CodeCompilationUnit ce : ces) { packages.addAll(getPackage(ae, ce)); } return packages; } - private Set getPackage(Entity ae, CodeCompilationUnit ce) { + private SortedSet getPackage(Entity ae, CodeCompilationUnit ce) { List cePackages = NameComparisonUtils.getMatchedPackages(ae, ce); if (!cePackages.isEmpty()) { - return Set.of(cePackages.get(cePackages.size() - 1)); + return new TreeSet<>(List.of(cePackages.get(cePackages.size() - 1))); } if (ce.hasParent()) { - return Set.of(ce.getParent()); + return new TreeSet<>(List.of(ce.getParent())); } - return Set.of(); + return new TreeSet<>(List.of()); } @Override diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/Required.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/Required.java index d6e9896d0..25a71e8cb 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/Required.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/Required.java @@ -1,8 +1,8 @@ /* Licensed under MIT 2023. */ package edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.heuristics; -import java.util.HashSet; -import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import edu.kit.kastel.mcse.ardoco.core.api.models.Entity; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureComponent; @@ -22,8 +22,8 @@ private Confidence calculateReq(ArchitectureComponent archEndpoint, CodeCompilat if (!getNodeResult().getConfidence(new EndpointTuple(archEndpoint, compUnit)).hasValue()) { return new Confidence(); } - Set allLinks = new HashSet<>(); - Set linkedEndpoints = getNodeResult().getLinkedEndpoints(compUnit); + SortedSet allLinks = new TreeSet<>(); + SortedSet linkedEndpoints = getNodeResult().getLinkedEndpoints(compUnit); for (Entity linkedEndpoint : linkedEndpoints) { if (linkedEndpoint instanceof ArchitectureComponent comp) { allLinks.add(comp); @@ -39,7 +39,7 @@ private Confidence calculateReq(ArchitectureComponent archEndpoint, CodeCompilat } // requiresComp requires (at least one of) providesComp - private static boolean hasRequired(ArchitectureComponent requiresComp, Set providesComps) { + private static boolean hasRequired(ArchitectureComponent requiresComp, SortedSet providesComps) { for (ArchitectureComponent providesComp : providesComps) { if (isRequired(requiresComp, providesComp)) { return true; diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/SubpackageFilter.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/SubpackageFilter.java index 23b8a9721..4fe5366c2 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/SubpackageFilter.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/SubpackageFilter.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.heuristics; import java.util.List; -import java.util.Set; +import java.util.SortedSet; import edu.kit.kastel.mcse.ardoco.core.api.models.Entity; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureComponent; @@ -35,7 +35,7 @@ private Confidence calculateSubpackageFilter(ArchitectureItem archEndpoint, Code return new Confidence(); } List thisPackages = NameComparisonUtils.getMatchedPackages(archEndpoint, compUnit); - Set linkedArchitectureEndpoints = getNodeResult().getLinkedEndpoints(compUnit); + SortedSet linkedArchitectureEndpoints = getNodeResult().getLinkedEndpoints(compUnit); linkedArchitectureEndpoints.remove(archEndpoint); for (var linkedArchitectureEndpoint : linkedArchitectureEndpoints) { List otherPackages = NameComparisonUtils.getMatchedPackages(linkedArchitectureEndpoint, compUnit); diff --git a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/SubpackageFilter2.java b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/SubpackageFilter2.java index 4fd1476de..fa2fd123f 100644 --- a/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/SubpackageFilter2.java +++ b/stages/code-traceability/src/main/java/edu/kit/kastel/mcse/ardoco/core/codetraceability/informants/arcotl/functions/heuristics/SubpackageFilter2.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2023. */ package edu.kit.kastel.mcse.ardoco.core.codetraceability.informants.arcotl.functions.heuristics; -import java.util.Set; +import java.util.SortedSet; import edu.kit.kastel.mcse.ardoco.core.api.models.Entity; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureComponent; @@ -32,7 +32,7 @@ private Confidence calculateSubpackageFilter(ArchitectureItem archEndpoint, Code return new Confidence(); } int i = 0; - Set linkedArchEndpoints = getNodeResult().getLinkedEndpoints(compUnit); + SortedSet linkedArchEndpoints = getNodeResult().getLinkedEndpoints(compUnit); for (var linkedArchEndpoint : linkedArchEndpoints) { if (linkedArchEndpoint instanceof ArchitectureComponent) { i++; diff --git a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/ConnectionGenerator.java b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/ConnectionGenerator.java index 5f2f0e2ee..b1177dc2c 100644 --- a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/ConnectionGenerator.java +++ b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/ConnectionGenerator.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.connectiongenerator; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.MutableList; @@ -50,7 +50,7 @@ public ConnectionGenerator(DataRepository dataRepository) { * @param dataRepository the data repository * @return an instance of connectionGenerator */ - public static ConnectionGenerator get(Map additionalConfigs, DataRepository dataRepository) { + public static ConnectionGenerator get(SortedMap additionalConfigs, DataRepository dataRepository) { var connectionGenerator = new ConnectionGenerator(dataRepository); connectionGenerator.applyConfiguration(additionalConfigs); return connectionGenerator; @@ -68,7 +68,7 @@ protected List getEnabledAgents() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { super.delegateApplyConfigurationToInternalObjects(additionalConfiguration); for (var agent : agents) { agent.applyConfiguration(additionalConfiguration); diff --git a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/ConnectionStateImpl.java b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/ConnectionStateImpl.java index 1d5a92eed..d5384e45b 100644 --- a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/ConnectionStateImpl.java +++ b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/ConnectionStateImpl.java @@ -1,11 +1,9 @@ /* Licensed under MIT 2021-2023. */ package edu.kit.kastel.mcse.ardoco.core.connectiongenerator; -import java.util.HashSet; -import java.util.Set; - import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.ImmutableList; +import org.eclipse.collections.api.list.MutableList; import edu.kit.kastel.mcse.ardoco.core.api.connectiongenerator.ConnectionState; import edu.kit.kastel.mcse.ardoco.core.api.models.ModelInstance; @@ -20,13 +18,13 @@ */ public class ConnectionStateImpl extends AbstractState implements ConnectionState { - private transient Set instanceLinks; + private transient MutableList instanceLinks; /** * Creates a new connection state. */ public ConnectionStateImpl() { - instanceLinks = new HashSet<>(); + instanceLinks = Lists.mutable.empty(); } /** diff --git a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/ConnectionStatesImpl.java b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/ConnectionStatesImpl.java index d8120aed1..9c055dcc4 100644 --- a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/ConnectionStatesImpl.java +++ b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/ConnectionStatesImpl.java @@ -2,13 +2,12 @@ package edu.kit.kastel.mcse.ardoco.core.connectiongenerator; import java.util.EnumMap; -import java.util.Map; import edu.kit.kastel.mcse.ardoco.core.api.connectiongenerator.ConnectionStates; import edu.kit.kastel.mcse.ardoco.core.api.models.Metamodel; public class ConnectionStatesImpl implements ConnectionStates { - private Map connectionStates; + private final EnumMap connectionStates; private ConnectionStatesImpl() { connectionStates = new EnumMap<>(Metamodel.class); diff --git a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/InitialConnectionAgent.java b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/InitialConnectionAgent.java index 43a146143..67276d823 100644 --- a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/InitialConnectionAgent.java +++ b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/InitialConnectionAgent.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.connectiongenerator.agents; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.connectiongenerator.informants.ExtractionDependentOccurrenceInformant; @@ -38,7 +38,7 @@ protected List getEnabledPipelineSteps() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); } } diff --git a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/InstanceConnectionAgent.java b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/InstanceConnectionAgent.java index c1bb5f362..3aa16d7c9 100644 --- a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/InstanceConnectionAgent.java +++ b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/InstanceConnectionAgent.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.connectiongenerator.agents; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.connectiongenerator.informants.InstantConnectionInformant; @@ -37,7 +37,7 @@ protected List getEnabledPipelineSteps() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); } } diff --git a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/ProjectNameFilterAgent.java b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/ProjectNameFilterAgent.java index b2a4e5f43..c4875f30f 100644 --- a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/ProjectNameFilterAgent.java +++ b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/ProjectNameFilterAgent.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.connectiongenerator.agents; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.api.recommendationgenerator.RecommendedInstance; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; @@ -40,7 +40,7 @@ protected List getEnabledPipelineSteps() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); } } diff --git a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/ReferenceAgent.java b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/ReferenceAgent.java index 933857ea4..d565227f2 100644 --- a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/ReferenceAgent.java +++ b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/agents/ReferenceAgent.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.connectiongenerator.agents; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.connectiongenerator.informants.ReferenceInformant; @@ -39,7 +39,7 @@ protected List getEnabledPipelineSteps() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); } } diff --git a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/informants/ExtractionDependentOccurrenceInformant.java b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/informants/ExtractionDependentOccurrenceInformant.java index ddfc5e26c..3f1d9af7d 100644 --- a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/informants/ExtractionDependentOccurrenceInformant.java +++ b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/informants/ExtractionDependentOccurrenceInformant.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2021-2023. */ package edu.kit.kastel.mcse.ardoco.core.connectiongenerator.informants; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.api.models.ModelExtractionState; import edu.kit.kastel.mcse.ardoco.core.api.models.ModelStates; @@ -82,7 +82,7 @@ private void searchForType(ModelExtractionState modelState, TextState textState, } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { // handle additional config } } diff --git a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/informants/InstantConnectionInformant.java b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/informants/InstantConnectionInformant.java index 8d87b9473..3c95c9dfa 100644 --- a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/informants/InstantConnectionInformant.java +++ b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/informants/InstantConnectionInformant.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.connectiongenerator.informants; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.api.connectiongenerator.ConnectionState; import edu.kit.kastel.mcse.ardoco.core.api.models.Metamodel; @@ -68,7 +68,7 @@ private void createLinksForEqualOrSimilarRecommendedInstances(ModelExtractionSta } @Override - protected void delegateApplyConfigurationToInternalObjects(Map map) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap map) { // empty } } diff --git a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/informants/NameTypeConnectionInformant.java b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/informants/NameTypeConnectionInformant.java index 344c32229..e1239acf7 100644 --- a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/informants/NameTypeConnectionInformant.java +++ b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/informants/NameTypeConnectionInformant.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.connectiongenerator.informants; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.ImmutableList; @@ -210,7 +210,7 @@ private ModelInstance tryToIdentify(TextState textExtractionState, ImmutableList } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { // handle additional configuration } diff --git a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/informants/ProjectNameInformant.java b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/informants/ProjectNameInformant.java index 82e12435f..a6313d9e0 100644 --- a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/informants/ProjectNameInformant.java +++ b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/informants/ProjectNameInformant.java @@ -1,8 +1,8 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.connectiongenerator.informants; -import java.util.Map; import java.util.Objects; +import java.util.SortedMap; import java.util.function.BinaryOperator; import java.util.function.UnaryOperator; @@ -144,7 +144,7 @@ private static String getEditedProjectName(String projectName) { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map map) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap map) { // handle additional configuration } } diff --git a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/informants/ReferenceInformant.java b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/informants/ReferenceInformant.java index 8923d2565..3dcf99786 100644 --- a/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/informants/ReferenceInformant.java +++ b/stages/connection-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/connectiongenerator/informants/ReferenceInformant.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.connectiongenerator.informants; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.list.ImmutableList; @@ -61,7 +61,7 @@ private ImmutableList getSimilarNounMappings(ModelInstance instance } @Override - protected void delegateApplyConfigurationToInternalObjects(Map map) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap map) { // empty } } diff --git a/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/DiagramRecognition.kt b/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/DiagramRecognition.kt index ad3753977..95fa353d9 100644 --- a/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/DiagramRecognition.kt +++ b/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/DiagramRecognition.kt @@ -8,6 +8,7 @@ import edu.kit.kastel.mcse.ardoco.core.pipeline.AbstractExecutionStage import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent import edu.kit.kastel.mcse.ardoco.lissa.diagramrecognition.agents.DiagramRecognitionAgent import edu.kit.kastel.mcse.ardoco.lissa.diagramrecognition.model.DiagramImpl +import java.util.* class DiagramRecognition : AbstractExecutionStage { @@ -22,7 +23,7 @@ class DiagramRecognition : AbstractExecutionStage { * @return a DiagramRecognition with the provided diagrams */ @JvmStatic - fun get(additionalConfigs: Map?, dataRepository: DataRepository?): DiagramRecognition? { + fun get(additionalConfigs: SortedMap?, dataRepository: DataRepository?): DiagramRecognition? { val diagramDetection = DiagramRecognition(dataRepository!!) diagramDetection.applyConfiguration(additionalConfigs) return diagramDetection @@ -58,7 +59,7 @@ class DiagramRecognition : AbstractExecutionStage { return findByClassName(enabledAgents, agents) } - override fun delegateApplyConfigurationToInternalObjects(additionalConfiguration: Map) { + override fun delegateApplyConfigurationToInternalObjects(additionalConfiguration: SortedMap) { super.delegateApplyConfigurationToInternalObjects(additionalConfiguration) for (agent in agents) { agent.applyConfiguration(additionalConfiguration) diff --git a/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/agents/DiagramRecognitionAgent.kt b/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/agents/DiagramRecognitionAgent.kt index 500903423..224de510b 100644 --- a/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/agents/DiagramRecognitionAgent.kt +++ b/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/agents/DiagramRecognitionAgent.kt @@ -8,6 +8,7 @@ import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.PipelineAgent import edu.kit.kastel.mcse.ardoco.lissa.diagramrecognition.informants.ObjectDetectionInformant import edu.kit.kastel.mcse.ardoco.lissa.diagramrecognition.informants.OcrInformant import edu.kit.kastel.mcse.ardoco.lissa.diagramrecognition.informants.RecognitionCombinatorInformant +import java.util.* /** * This agent uses the [DiagramRecognitionState] to extract the diagrams and sketches from images. @@ -29,7 +30,7 @@ class DiagramRecognitionAgent(dataRepository: DataRepository) : PipelineAgent(ID override fun getEnabledPipelineSteps(): MutableList = findByClassName(enabledInformants, informants) - override fun delegateApplyConfigurationToInternalObjects(additionalConfiguration: Map?) { + override fun delegateApplyConfigurationToInternalObjects(additionalConfiguration: SortedMap?) { informants.forEach { it.applyConfiguration(additionalConfiguration) } } } diff --git a/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/informants/DockerInformant.kt b/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/informants/DockerInformant.kt index 16d5ff6eb..678cf838c 100644 --- a/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/informants/DockerInformant.kt +++ b/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/informants/DockerInformant.kt @@ -10,7 +10,6 @@ import org.apache.hc.client5.http.classic.methods.HttpGet import org.apache.hc.client5.http.impl.classic.BasicHttpClientResponseHandler import org.apache.hc.client5.http.impl.classic.HttpClients import java.io.IOException -import java.util.* import java.util.stream.IntStream abstract class DockerInformant : Informant { diff --git a/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/informants/ObjectDetectionInformant.kt b/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/informants/ObjectDetectionInformant.kt index 3415505c1..4a7dade90 100644 --- a/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/informants/ObjectDetectionInformant.kt +++ b/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/informants/ObjectDetectionInformant.kt @@ -11,6 +11,7 @@ import org.apache.hc.core5.http.ContentType import org.apache.hc.core5.http.HttpEntity import java.io.ByteArrayInputStream import java.io.InputStream +import java.util.* class ObjectDetectionInformant(dataRepository: DataRepository) : ImageProcessingDockerInformant( DOCKER_SKETCH_RECOGNITION, @@ -28,7 +29,7 @@ class ObjectDetectionInformant(dataRepository: DataRepository) : ImageProcessing const val ID = "ObjectDetectionInformant" } - override fun delegateApplyConfigurationToInternalObjects(additionalConfiguration: MutableMap?) { + override fun delegateApplyConfigurationToInternalObjects(additionalConfiguration: SortedMap?) { // Not needed } diff --git a/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/informants/OcrInformant.kt b/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/informants/OcrInformant.kt index 51c562f61..d347ba544 100644 --- a/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/informants/OcrInformant.kt +++ b/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/informants/OcrInformant.kt @@ -15,6 +15,7 @@ import org.apache.hc.core5.net.URIBuilder import java.io.ByteArrayInputStream import java.io.InputStream import java.net.URI +import java.util.* class OcrInformant(dataRepository: DataRepository) : ImageProcessingDockerInformant( DOCKER_OCR, @@ -34,7 +35,7 @@ class OcrInformant(dataRepository: DataRepository) : ImageProcessingDockerInform const val EXPANSION_IN_PX = 5 } - override fun delegateApplyConfigurationToInternalObjects(additionalConfiguration: MutableMap?) { + override fun delegateApplyConfigurationToInternalObjects(additionalConfiguration: SortedMap?) { // Not needed } diff --git a/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/informants/RecognitionCombinatorInformant.kt b/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/informants/RecognitionCombinatorInformant.kt index 8d3418d0a..892ec6341 100644 --- a/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/informants/RecognitionCombinatorInformant.kt +++ b/stages/diagram-recognition/src/main/kotlin/edu/kit/kastel/mcse/ardoco/lissa/diagramrecognition/informants/RecognitionCombinatorInformant.kt @@ -9,6 +9,7 @@ import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Informant import edu.kit.kastel.mcse.ardoco.lissa.diagramrecognition.boundingBox import java.awt.image.BufferedImage import java.io.ByteArrayInputStream +import java.util.* import java.util.stream.IntStream import javax.imageio.ImageIO @@ -17,7 +18,7 @@ class RecognitionCombinatorInformant(dataRepository: DataRepository) : Informant const val ID = "RecognitionCombinatorInformant" } - override fun delegateApplyConfigurationToInternalObjects(additionalConfiguration: MutableMap?) { + override fun delegateApplyConfigurationToInternalObjects(additionalConfiguration: SortedMap?) { // Not needed } diff --git a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/InconsistencyChecker.java b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/InconsistencyChecker.java index e81579146..be570c17e 100644 --- a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/InconsistencyChecker.java +++ b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/InconsistencyChecker.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.inconsistency; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.MutableList; @@ -39,7 +39,7 @@ public InconsistencyChecker(DataRepository dataRepository) { * @param dataRepository the data repository * @return an instance of InconsistencyChecker */ - public static InconsistencyChecker get(Map additionalConfigs, DataRepository dataRepository) { + public static InconsistencyChecker get(SortedMap additionalConfigs, DataRepository dataRepository) { var inconsistencyChecker = new InconsistencyChecker(dataRepository); inconsistencyChecker.applyConfiguration(additionalConfigs); return inconsistencyChecker; @@ -57,7 +57,7 @@ protected List getEnabledAgents() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { super.delegateApplyConfigurationToInternalObjects(additionalConfiguration); for (var agent : agents) { agent.applyConfiguration(additionalConfiguration); diff --git a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/InconsistencyStatesImpl.java b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/InconsistencyStatesImpl.java index cc6042ab6..7add27f92 100644 --- a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/InconsistencyStatesImpl.java +++ b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/InconsistencyStatesImpl.java @@ -2,14 +2,13 @@ package edu.kit.kastel.mcse.ardoco.core.inconsistency; import java.util.EnumMap; -import java.util.Map; import edu.kit.kastel.mcse.ardoco.core.api.inconsistency.InconsistencyState; import edu.kit.kastel.mcse.ardoco.core.api.inconsistency.InconsistencyStates; import edu.kit.kastel.mcse.ardoco.core.api.models.Metamodel; public class InconsistencyStatesImpl implements InconsistencyStates { - private Map inconsistencyStates; + private EnumMap inconsistencyStates; private InconsistencyStatesImpl() { inconsistencyStates = new EnumMap<>(Metamodel.class); diff --git a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/MissingElementInconsistencyCandidate.java b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/MissingElementInconsistencyCandidate.java index 6e810475a..4f0b7f3b5 100644 --- a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/MissingElementInconsistencyCandidate.java +++ b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/MissingElementInconsistencyCandidate.java @@ -3,15 +3,15 @@ import java.util.Objects; -import org.eclipse.collections.api.factory.Sets; -import org.eclipse.collections.api.set.MutableSet; +import org.eclipse.collections.api.factory.SortedSets; +import org.eclipse.collections.api.set.sorted.MutableSortedSet; import edu.kit.kastel.mcse.ardoco.core.api.recommendationgenerator.RecommendedInstance; public class MissingElementInconsistencyCandidate { private final RecommendedInstance recommendedInstance; - private final MutableSet supports = Sets.mutable.empty(); + private final MutableSortedSet supports = SortedSets.mutable.empty(); public MissingElementInconsistencyCandidate(RecommendedInstance recommendedInstance, MissingElementSupport support) { this.recommendedInstance = recommendedInstance; diff --git a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/InitialInconsistencyAgent.java b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/InitialInconsistencyAgent.java index 22477947f..82d54d01d 100644 --- a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/InitialInconsistencyAgent.java +++ b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/InitialInconsistencyAgent.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.inconsistency.agents; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.MutableList; @@ -53,7 +53,7 @@ protected List getEnabledPipelineSteps() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { filters.forEach(filter -> filter.applyConfiguration(additionalConfiguration)); } } diff --git a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/MissingModelElementInconsistencyAgent.java b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/MissingModelElementInconsistencyAgent.java index 457cbe839..bb993bd9f 100644 --- a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/MissingModelElementInconsistencyAgent.java +++ b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/MissingModelElementInconsistencyAgent.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.inconsistency.agents; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; @@ -30,7 +30,7 @@ protected List getEnabledPipelineSteps() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); } } diff --git a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/UndocumentedModelElementInconsistencyAgent.java b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/UndocumentedModelElementInconsistencyAgent.java index e96f0d8ae..11f7931e9 100644 --- a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/UndocumentedModelElementInconsistencyAgent.java +++ b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/agents/UndocumentedModelElementInconsistencyAgent.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.inconsistency.agents; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; @@ -34,7 +34,7 @@ protected List getEnabledPipelineSteps() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); } } diff --git a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/ComputerScienceWordsFilter.java b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/ComputerScienceWordsFilter.java deleted file mode 100644 index d649e3213..000000000 --- a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/ComputerScienceWordsFilter.java +++ /dev/null @@ -1,157 +0,0 @@ -/* Licensed under MIT 2022-2023. */ -package edu.kit.kastel.mcse.ardoco.core.inconsistency.informants; - -import java.io.IOException; -import java.io.InputStream; -import java.util.*; -import java.util.stream.Collectors; - -import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.list.ImmutableList; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -import edu.kit.kastel.mcse.ardoco.core.api.inconsistency.InconsistencyState; -import edu.kit.kastel.mcse.ardoco.core.api.recommendationgenerator.RecommendedInstance; -import edu.kit.kastel.mcse.ardoco.core.api.textextraction.NounMapping; -import edu.kit.kastel.mcse.ardoco.core.common.util.SimilarityUtils; -import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; -import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; - -/** - * This Filter checks for common computer science words and filters them. Unfortunately, this is very rigorous and filters a lot of words that we actually want - * to cover. - * Examples include "facade" and "database". This is because inconsistencies (missing elements) that we want to find share wording with common CS words. - * We have to analyze how we want to deal with this. One idea is to not fully filter them but take care in another way. - */ -public class ComputerScienceWordsFilter extends Filter { - - private static final String WIKI = "WIKI"; - private static final String ISO24765 = "ISO24765"; - private static final String STANDARD_GLOSSARY = "STANDARD_GLOSSARY"; - - @Configurable - private List sources = List.of(STANDARD_GLOSSARY); - - @Configurable - private List additionalWords = List.of(); - - private final ImmutableList commonCSWords; - - public ComputerScienceWordsFilter(DataRepository data) { - super(ComputerScienceWordsFilter.class.getSimpleName(), data); - this.commonCSWords = loadWords(); - } - - @Override - protected void filterRecommendedInstances(InconsistencyState inconsistencyState) { - var originalRecommendedInstances = inconsistencyState.getRecommendedInstances(); - var recommendedInstancesToKeep = Lists.mutable.empty(); - var recommendedInstancesToDismiss = Lists.mutable.empty(); - - for (var recommendedInstance : originalRecommendedInstances) { - boolean shallBeFiltered = checkRecommendedInstance(recommendedInstance); - if (!shallBeFiltered) - recommendedInstancesToKeep.add(recommendedInstance); - else - recommendedInstancesToDismiss.add(recommendedInstance); - } - - inconsistencyState.setRecommendedInstances(recommendedInstancesToKeep); - } - - private boolean checkRecommendedInstance(RecommendedInstance recommendedInstance) { - for (var nounMapping : recommendedInstance.getNameMappings()) { - if (checkNounMapping(nounMapping)) - return true; - } - return false; - } - - private boolean checkNounMapping(NounMapping nounMapping) { - return this.commonCSWords.stream().anyMatch(commonWord -> match(nounMapping, commonWord)); - } - - private boolean match(NounMapping nounMapping, String csWord) { - // this uses a simple version to match NounMapping and a common CS word by just comparing the reference to the cs word - // There is another implementation in the class ComputerScienceWordsInformant that checks more thoroughly but also has more "false positives" - var reference = nounMapping.getReference(); - return SimilarityUtils.areWordsSimilar(reference.toLowerCase(), csWord.toLowerCase()); - } - - private ImmutableList loadWords() { - Set result = new HashSet<>(); - loadDBPedia(result); - loadISO24765(result); - loadStandardGlossary(result); - result.addAll(additionalWords); - // Remove after bracket ( - result = result.stream().map(e -> e.split("\\(", -1)[0].trim()).collect(Collectors.toSet()); - return Lists.immutable.withAll(result.stream().map(w -> w.trim().toLowerCase()).toList()); - } - - private void loadDBPedia(Set result) { - if (!this.sources.contains(WIKI)) - return; - - int before = result.size(); - logger.debug("Loading words from DBPedia"); - - for (String name : List.of("design", "engineering")) { - JsonNode tree; - try (InputStream data = this.getClass().getResourceAsStream("/dbpedia/" + name + ".json")) { - ObjectMapper oom = new ObjectMapper(); - tree = oom.readTree(data); - } catch (IOException e) { - throw new IllegalStateException(e); - } - - tree = tree.get("results").get("bindings"); - tree.spliterator().forEachRemaining(n -> result.add(n.get("alabel").get("value").textValue())); - } - result.removeIf(Objects::isNull); - // Check that word has a type - result.removeIf(w -> !w.contains("(")); - logger.debug("Found {} words by adding DBPedia", result.size() - before); - } - - private void loadISO24765(Set result) { - if (!this.sources.contains(ISO24765)) - return; - - int before = result.size(); - logger.debug("Loading words from ISO24765"); - List words = loadWordsFromResource("/pdfs/24765-2017.pdf.words.txt"); - result.addAll(words); - logger.debug("Found {} words by adding ISO24765", result.size() - before); - } - - private void loadStandardGlossary(Set result) { - if (!this.sources.contains(STANDARD_GLOSSARY)) - return; - - int before = result.size(); - logger.debug("Loading words from STANDARD_GLOSSARY"); - List words = loadWordsFromResource("/pdfs/Standard_glossary_of_terms_used_in_Software_Engineering_1.0.pdf.words.txt"); - result.addAll(words); - logger.debug("Found {} words by adding STANDARD_GLOSSARY", result.size() - before); - } - - private List loadWordsFromResource(String path) { - try (InputStream data = this.getClass().getResourceAsStream(path)) { - ObjectMapper oom = new ObjectMapper(); - return oom.readValue(data, new TypeReference<>() { - }); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - protected void delegateApplyConfigurationToInternalObjects(Map map) { - // empty - } - -} diff --git a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/MissingModelElementInconsistencyInformant.java b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/MissingModelElementInconsistencyInformant.java index c5e7d8ab6..65a45bf14 100644 --- a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/MissingModelElementInconsistencyInformant.java +++ b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/MissingModelElementInconsistencyInformant.java @@ -1,13 +1,11 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.inconsistency.informants; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.factory.Sets; import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.list.MutableList; -import org.eclipse.collections.api.set.MutableSet; import edu.kit.kastel.mcse.ardoco.core.api.connectiongenerator.ConnectionStates; import edu.kit.kastel.mcse.ardoco.core.api.inconsistency.InconsistencyState; @@ -54,7 +52,7 @@ private void findMissingModelElementInconsistencies(ConnectionStates connectionS var inconsistencyState = inconsistencyStates.getInconsistencyState(metamodel); var connectionState = connectionStates.getConnectionState(metamodel); - var candidates = Sets.mutable.empty(); + var candidates = Lists.mutable.empty(); var candidateElements = Lists.mutable.ofAll(inconsistencyState.getRecommendedInstances()); var linkedRecommendedInstances = connectionState.getInstanceLinks().collect(InstanceLink::getTextualInstance); @@ -94,7 +92,7 @@ private void filterCandidatesCoveredByRecommendedInstance(MutableList candidates, RecommendedInstance recommendedInstance, + private void addToCandidates(MutableList candidates, RecommendedInstance recommendedInstance, MissingElementSupport support) { for (var candidate : candidates) { var candidateRecommendedInstance = candidate.getRecommendedInstance(); @@ -116,7 +114,7 @@ private void addToCandidates(MutableSet ca candidates.add(candidate); } - private void createInconsistencies(MutableSet candidates, InconsistencyState inconsistencyState) { + private void createInconsistencies(MutableList candidates, InconsistencyState inconsistencyState) { for (var candidate : candidates) { var support = candidate.getAmountOfSupport(); if (support >= minSupport) { @@ -132,7 +130,7 @@ private void createInconsistencies(MutableSet map) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap map) { // empty } } diff --git a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/OccasionFilter.java b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/OccasionFilter.java index fe8cb5401..c03f918a8 100644 --- a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/OccasionFilter.java +++ b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/OccasionFilter.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.inconsistency.informants; import java.util.Comparator; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Lists; @@ -74,7 +74,7 @@ private int countSurfaceForms(RecommendedInstance recommendedInstance) { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { // handle additional config } diff --git a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/RecommendedInstanceProbabilityFilter.java b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/RecommendedInstanceProbabilityFilter.java index 36f5ba9d9..f466867ab 100644 --- a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/RecommendedInstanceProbabilityFilter.java +++ b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/RecommendedInstanceProbabilityFilter.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.inconsistency.informants; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.bag.sorted.MutableSortedBag; import org.eclipse.collections.api.factory.Lists; @@ -78,8 +78,8 @@ private double analyzeProbabilitiesofRecommendedInstances(MutableList typeMappings } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { // handle additional config } diff --git a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/UndocumentedModelElementInconsistencyInformant.java b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/UndocumentedModelElementInconsistencyInformant.java index b6983bf2f..119fb3b69 100644 --- a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/UndocumentedModelElementInconsistencyInformant.java +++ b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/UndocumentedModelElementInconsistencyInformant.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.inconsistency.informants; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import java.util.regex.Pattern; import org.eclipse.collections.api.factory.Lists; @@ -110,7 +110,7 @@ private void createInconsistencies(MutableList candidateModelInst } @Override - protected void delegateApplyConfigurationToInternalObjects(Map map) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap map) { // empty } } diff --git a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/UnwantedWordsFilter.java b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/UnwantedWordsFilter.java index cbb8bccd3..e1c16a730 100644 --- a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/UnwantedWordsFilter.java +++ b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/informants/UnwantedWordsFilter.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.util.Collections; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -111,7 +111,7 @@ private boolean referenceEndsWithFileEnding(NounMapping nounMapping) { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map map) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap map) { // nothing } diff --git a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/types/MissingModelInstanceInconsistency.java b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/types/MissingModelInstanceInconsistency.java index bd9259db8..0424f7129 100644 --- a/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/types/MissingModelInstanceInconsistency.java +++ b/stages/inconsistency-detection/src/main/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/types/MissingModelInstanceInconsistency.java @@ -5,8 +5,8 @@ import java.util.Objects; import org.eclipse.collections.api.collection.ImmutableCollection; -import org.eclipse.collections.api.factory.Sets; -import org.eclipse.collections.api.set.MutableSet; +import org.eclipse.collections.api.factory.Lists; +import org.eclipse.collections.api.list.MutableList; import edu.kit.kastel.mcse.ardoco.core.api.inconsistency.TextInconsistency; @@ -27,7 +27,7 @@ public int getSentenceNumber() { @Override public ImmutableCollection toFileOutput() { - MutableSet entries = Sets.mutable.empty(); + MutableList entries = Lists.mutable.empty(); var sentenceNoString = "" + sentence; String[] entry = { getType(), sentenceNoString, name, Integer.toString(sentence), Double.toString(confidence) }; diff --git a/stages/inconsistency-detection/src/test/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/types/AbstractInconsistencyTypeTest.java b/stages/inconsistency-detection/src/test/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/types/AbstractInconsistencyTypeTest.java index e888810d1..6b5790502 100644 --- a/stages/inconsistency-detection/src/test/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/types/AbstractInconsistencyTypeTest.java +++ b/stages/inconsistency-detection/src/test/java/edu/kit/kastel/mcse/ardoco/core/inconsistency/types/AbstractInconsistencyTypeTest.java @@ -146,6 +146,18 @@ public boolean equals(Object obj) { return getPosition() == other.getPosition() && getSentenceNo() == other.getSentenceNo() && Objects.equals(getText(), other.getText()); } + + @Override + public int compareTo(Word o) { + if (this.equals(o)) + return 0; + + int compareSentences = Integer.compare(this.getSentenceNo(), o.getSentenceNo()); + if (compareSentences != 0) { + return compareSentences; + } + return Integer.compare(this.getPosition(), o.getPosition()); + } } } diff --git a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/ArCoTLModelProviderAgent.java b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/ArCoTLModelProviderAgent.java index 60ba10ff5..5c4a5db4e 100644 --- a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/ArCoTLModelProviderAgent.java +++ b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/ArCoTLModelProviderAgent.java @@ -4,7 +4,7 @@ import java.io.File; import java.util.ArrayList; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.api.models.ArchitectureModelType; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodeItemRepository; @@ -42,7 +42,7 @@ public ArCoTLModelProviderAgent(DataRepository data, List extractors) } public static ArCoTLModelProviderAgent get(File inputArchitectureModel, ArchitectureModelType architectureModelType, File inputCode, - Map additionalConfigs, DataRepository dataRepository) { + SortedMap additionalConfigs, DataRepository dataRepository) { ArchitectureExtractor architectureExtractor = switch (architectureModelType) { case PCM -> new PcmExtractor(inputArchitectureModel.getAbsolutePath()); case UML -> new UmlExtractor(inputArchitectureModel.getAbsolutePath()); @@ -55,7 +55,7 @@ public static ArCoTLModelProviderAgent get(File inputArchitectureModel, Architec } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { // empty } diff --git a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/ModelExtractionStateImpl.java b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/ModelExtractionStateImpl.java index 598c82411..eecb87c12 100644 --- a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/ModelExtractionStateImpl.java +++ b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/ModelExtractionStateImpl.java @@ -2,13 +2,12 @@ package edu.kit.kastel.mcse.ardoco.core.models; import java.util.Objects; -import java.util.Set; import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.factory.Sets; +import org.eclipse.collections.api.factory.SortedSets; import org.eclipse.collections.api.list.ImmutableList; -import org.eclipse.collections.api.set.ImmutableSet; -import org.eclipse.collections.api.set.MutableSet; +import org.eclipse.collections.api.set.sorted.ImmutableSortedSet; +import org.eclipse.collections.api.set.sorted.MutableSortedSet; import edu.kit.kastel.mcse.ardoco.core.api.models.Metamodel; import edu.kit.kastel.mcse.ardoco.core.api.models.ModelExtractionState; @@ -23,8 +22,8 @@ public class ModelExtractionStateImpl extends AbstractState implements ModelExtr private final String modelId; private final Metamodel metamodelType; - private final MutableSet instanceTypes; - private final MutableSet names; + private final MutableSortedSet instanceTypes; + private final MutableSortedSet names; private transient ImmutableList instances; // For generation of configuration @@ -46,8 +45,8 @@ public ModelExtractionStateImpl(String modelId, Metamodel metamodelType, Immutab this.modelId = Objects.requireNonNull(modelId); this.metamodelType = metamodelType; this.instances = instances; - instanceTypes = Sets.mutable.empty(); - names = Sets.mutable.empty(); + instanceTypes = SortedSets.mutable.empty(); + names = SortedSets.mutable.empty(); collectTypesAndNames(); } @@ -89,7 +88,7 @@ public ImmutableList getInstancesOfType(String type) { * @return all instance types of this state */ @Override - public ImmutableSet getInstanceTypes() { + public ImmutableSortedSet getInstanceTypes() { return instanceTypes.toImmutable(); } @@ -99,8 +98,8 @@ public ImmutableSet getInstanceTypes() { * @return all names of this state */ @Override - public Set getNames() { - return names; + public ImmutableSortedSet getNames() { + return names.toImmutable(); } /** @@ -116,7 +115,7 @@ public ImmutableList getInstances() { @Override public void addAllOf(ModelExtractionState other) { instanceTypes.addAll(other.getInstanceTypes().toSet()); - names.addAll(other.getNames()); + names.addAll(other.getNames().castToCollection()); var mergedInstances = Lists.mutable.ofAll(instances); mergedInstances.addAll(other.getInstances().toList()); diff --git a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/ModelProviderAgent.java b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/ModelProviderAgent.java index d6ba818ab..1437e659f 100644 --- a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/ModelProviderAgent.java +++ b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/ModelProviderAgent.java @@ -5,7 +5,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.api.models.ArchitectureModelType; import edu.kit.kastel.mcse.ardoco.core.api.models.ModelConnector; @@ -68,7 +68,7 @@ public static ModelProviderAgent getCodeProvider(DataRepository dataRepository) } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); } diff --git a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/architecture/pcm/PcmExtractor.java b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/architecture/pcm/PcmExtractor.java index 523864bf7..3776734e7 100644 --- a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/architecture/pcm/PcmExtractor.java +++ b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/architecture/pcm/PcmExtractor.java @@ -3,9 +3,9 @@ import java.io.File; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import edu.kit.kastel.mcse.ardoco.core.api.models.ArchitectureModelType; import edu.kit.kastel.mcse.ardoco.core.api.models.ModelType; @@ -14,6 +14,7 @@ import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureItem; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureMethod; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureModel; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.models.connectors.generators.architecture.ArchitectureExtractor; import edu.kit.kastel.mcse.ardoco.core.models.connectors.generators.architecture.pcm.parser.PcmComponent; import edu.kit.kastel.mcse.ardoco.core.models.connectors.generators.architecture.pcm.parser.PcmInterface; @@ -25,6 +26,7 @@ /** * An extractor for PCM. Extracts an AMTL instance. */ +@Deterministic public final class PcmExtractor extends ArchitectureExtractor { public PcmExtractor(String path) { @@ -55,7 +57,7 @@ public ModelType getModelType() { private static List extractInterfaces(PcmModel originalModel) { List interfaces = new ArrayList<>(); for (PcmInterface originalInterface : originalModel.getRepository().getInterfaces()) { - Set signatures = new HashSet<>(); + SortedSet signatures = new TreeSet<>(); for (PcmSignature originalMethod : originalInterface.getMethods()) { ArchitectureMethod signature = new ArchitectureMethod(originalMethod.getEntityName()); signatures.add(signature); @@ -69,9 +71,9 @@ private static List extractInterfaces(PcmModel originalMo private static List extractComponents(PcmModel originalModel, List interfaces) { List components = new ArrayList<>(); for (PcmComponent originalComponent : originalModel.getRepository().getComponents()) { - Set subcomponents = new HashSet<>(); - Set providedInterfaces = new HashSet<>(); - Set requiredInterfaces = new HashSet<>(); + SortedSet subcomponents = new TreeSet<>(); + SortedSet providedInterfaces = new TreeSet<>(); + SortedSet requiredInterfaces = new TreeSet<>(); for (PcmInterface providedInterface : originalComponent.getProvided()) { ArchitectureInterface modelInterface = findInterface(providedInterface.getId(), interfaces); providedInterfaces.add(modelInterface); diff --git a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/architecture/uml/UmlExtractor.java b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/architecture/uml/UmlExtractor.java index 346045b21..05dde90af 100644 --- a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/architecture/uml/UmlExtractor.java +++ b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/architecture/uml/UmlExtractor.java @@ -3,9 +3,9 @@ import java.io.File; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import edu.kit.kastel.mcse.ardoco.core.api.models.ArchitectureModelType; import edu.kit.kastel.mcse.ardoco.core.api.models.ModelType; @@ -14,6 +14,7 @@ import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureItem; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureMethod; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureModel; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.models.connectors.generators.architecture.ArchitectureExtractor; import edu.kit.kastel.mcse.ardoco.core.models.connectors.generators.architecture.uml.parser.UmlComponent; import edu.kit.kastel.mcse.ardoco.core.models.connectors.generators.architecture.uml.parser.UmlInterface; @@ -23,6 +24,7 @@ /** * An extractor for UML. Extracts an AMTL instance. */ +@Deterministic public final class UmlExtractor extends ArchitectureExtractor { public UmlExtractor(String path) { @@ -53,7 +55,7 @@ public ModelType getModelType() { private static List extractInterfaces(UmlModel originalModel) { List interfaces = new ArrayList<>(); for (UmlInterface originalInterface : originalModel.getModel().getInterfaces()) { - Set signatures = new HashSet<>(); + SortedSet signatures = new TreeSet<>(); for (OwnedOperation originalMethod : originalInterface.getOperations()) { ArchitectureMethod signature = new ArchitectureMethod(originalMethod.getName()); signatures.add(signature); @@ -67,9 +69,9 @@ private static List extractInterfaces(UmlModel originalMo private static List extractComponents(UmlModel originalModel, List interfaces) { List components = new ArrayList<>(); for (UmlComponent originalComponent : originalModel.getModel().getComponents()) { - Set subcomponents = new HashSet<>(); - Set providedInterfaces = new HashSet<>(); - Set requiredInterfaces = new HashSet<>(); + SortedSet subcomponents = new TreeSet<>(); + SortedSet providedInterfaces = new TreeSet<>(); + SortedSet requiredInterfaces = new TreeSet<>(); for (UmlInterface providedInterface : originalComponent.getProvided()) { ArchitectureInterface modelInterface = findInterface(providedInterface.getId(), interfaces); providedInterfaces.add(modelInterface); diff --git a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/AllLanguagesExtractor.java b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/AllLanguagesExtractor.java index 58feea1ad..2186371cf 100644 --- a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/AllLanguagesExtractor.java +++ b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/AllLanguagesExtractor.java @@ -2,18 +2,20 @@ package edu.kit.kastel.mcse.ardoco.core.models.connectors.generators.code; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodeItem; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodeItemRepository; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodeModel; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.ProgrammingLanguage; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.models.connectors.generators.code.java.JavaExtractor; import edu.kit.kastel.mcse.ardoco.core.models.connectors.generators.code.shell.ShellExtractor; +@Deterministic public final class AllLanguagesExtractor extends CodeExtractor { private final Map codeExtractors; @@ -34,7 +36,7 @@ public synchronized CodeModel extractModel() { var model = extractor.extractModel(); models.add(model); } - Set codeEndpoints = new HashSet<>(); + SortedSet codeEndpoints = new TreeSet<>(); for (CodeModel model : models) { codeEndpoints.addAll(model.getContent()); } diff --git a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/java/JavaExtractor.java b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/java/JavaExtractor.java index 568a0655c..552083093 100644 --- a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/java/JavaExtractor.java +++ b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/java/JavaExtractor.java @@ -7,8 +7,9 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; -import java.util.HashMap; import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; import java.util.stream.Stream; import org.eclipse.core.runtime.NullProgressMonitor; @@ -22,11 +23,13 @@ import edu.kit.kastel.mcse.ardoco.core.api.models.ModelType; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodeItemRepository; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodeModel; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.models.connectors.generators.code.CodeExtractor; /** * An extractor for Java. Extracts a CMTL instance. */ +@Deterministic public final class JavaExtractor extends CodeExtractor { private CodeModel extractedModel = null; @@ -44,7 +47,7 @@ public JavaExtractor(CodeItemRepository codeItemRepository, String path) { public synchronized CodeModel extractModel() { if (extractedModel == null) { Path directoryPath = Path.of(path); - Map compUnitMap = parseDirectory(directoryPath); + SortedMap compUnitMap = parseDirectory(directoryPath); JavaModel javaModel = new JavaModel(codeItemRepository, compUnitMap); this.extractedModel = javaModel.getCodeModel(); } @@ -56,12 +59,12 @@ public ModelType getModelType() { return CodeModelType.CODE_MODEL; } - private static Map parseDirectory(Path dir) { + private static SortedMap parseDirectory(Path dir) { ASTParser parser = getJavaParser(); final String[] sources = getEntries(dir, ".java"); final String[] encodings = new String[sources.length]; Arrays.fill(encodings, StandardCharsets.UTF_8.toString()); - final Map compilationUnits = new HashMap<>(); + final SortedMap compilationUnits = new TreeMap<>(); parser.setEnvironment(new String[0], new String[0], new String[0], false); parser.createASTs(sources, encodings, new String[0], new FileASTRequestor() { @Override diff --git a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/java/JavaModel.java b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/java/JavaModel.java index 60692e498..f990cf083 100644 --- a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/java/JavaModel.java +++ b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/java/JavaModel.java @@ -4,21 +4,48 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.TreeSet; import org.apache.commons.io.FilenameUtils; -import org.eclipse.jdt.core.dom.*; - -import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.*; +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; +import org.eclipse.jdt.core.dom.BodyDeclaration; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.EnumDeclaration; +import org.eclipse.jdt.core.dom.ITypeBinding; +import org.eclipse.jdt.core.dom.MethodDeclaration; +import org.eclipse.jdt.core.dom.Name; +import org.eclipse.jdt.core.dom.PackageDeclaration; +import org.eclipse.jdt.core.dom.QualifiedName; +import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.core.dom.Type; +import org.eclipse.jdt.core.dom.TypeDeclaration; + +import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.ClassUnit; +import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodeCompilationUnit; +import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodeItem; +import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodeItemRepository; +import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodeModel; +import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodeModule; +import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodePackage; +import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.ControlElement; +import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.Datatype; +import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.InterfaceUnit; +import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.ProgrammingLanguage; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.kit.kastel.mcse.ardoco.core.models.connectors.generators.code.java.finder.EnumDeclarationFinder; import edu.kit.kastel.mcse.ardoco.core.models.connectors.generators.code.java.finder.MethodDeclarationFinder; import edu.kit.kastel.mcse.ardoco.core.models.connectors.generators.code.java.finder.TypeDeclarationFinder; import edu.kit.kastel.mcse.ardoco.core.models.connectors.generators.code.java.finder.TypeFinder; +@Deterministic public final class JavaModel { private final CodeItemRepository codeItemRepository; @@ -27,11 +54,11 @@ public final class JavaModel { private Set javaInterfaces; private CodeModel codeModel; - public JavaModel(CodeItemRepository codeItemRepository, Map compUnitMap) { + public JavaModel(CodeItemRepository codeItemRepository, SortedMap compUnitMap) { this.codeItemRepository = codeItemRepository; - javaTypes = new HashSet<>(); - javaClassifiers = new HashSet<>(); - javaInterfaces = new HashSet<>(); + javaTypes = new LinkedHashSet<>(); + javaClassifiers = new LinkedHashSet<>(); + javaInterfaces = new LinkedHashSet<>(); initModel(compUnitMap); } @@ -86,7 +113,7 @@ private void initImplementedInterfaces() { .findFirst() .orElseThrow()) .toList(); - Set codeImplInterfaces = new HashSet<>(); + SortedSet codeImplInterfaces = new TreeSet<>(); javaImplInterfaces.forEach(javaImplInterface -> codeImplInterfaces.add(javaImplInterface.codeInterface())); javaClassifier.codeClassifier().setImplementedTypes(codeImplInterfaces); } @@ -102,7 +129,7 @@ private void initExtendedInterfaces() { .findFirst() .orElseThrow()) .toList(); - Set codeExtendedInterfaces = new HashSet<>(); + SortedSet codeExtendedInterfaces = new TreeSet<>(); javaExtendedInterfaces.forEach(javaExtendedInterface -> codeExtendedInterfaces.add(javaExtendedInterface.codeInterface())); javaInterface.codeInterface().setExtendedTypes(codeExtendedInterfaces); } @@ -119,7 +146,7 @@ private void initSuperclasses() { .filter(otherJavaClass -> otherJavaClass.binding().getErasure().isEqualTo(superclassBinding.getErasure())) .findFirst() .orElseThrow(); - Set superclasses = new HashSet<>(); + SortedSet superclasses = new TreeSet<>(); superclasses.add(javaSuperclass.codeClassifier()); javaClassifier.codeClassifier().setExtendedTypes(superclasses); } @@ -142,10 +169,10 @@ private static List getReferencedBindings(AbstractTypeDeclaration // - private void initModel(Map compUnitMap) { - Set modelContent = new HashSet<>(); - Set codePackages = new HashSet<>(); - Set codeCompilationUnits = new HashSet<>(); + private void initModel(SortedMap compUnitMap) { + SortedSet modelContent = new TreeSet<>(); + SortedSet codePackages = new TreeSet<>(); + SortedSet codeCompilationUnits = new TreeSet<>(); for (var entry : compUnitMap.entrySet()) { CompilationUnit compilationUnit = entry.getValue(); @@ -163,7 +190,7 @@ private void initModel(Map compUnitMap) { Name fullName = packageDeclaration.getName(); packageNames = getPackageNames(fullName); } - CodeCompilationUnit codeCompilationUnit = new CodeCompilationUnit(codeItemRepository, fileNameWithoutExtension, new HashSet<>(), pathElements, + CodeCompilationUnit codeCompilationUnit = new CodeCompilationUnit(codeItemRepository, fileNameWithoutExtension, new TreeSet<>(), pathElements, extension, ProgrammingLanguage.JAVA); codeCompilationUnits.add(codeCompilationUnit); if (null != packageDeclaration) { @@ -202,7 +229,7 @@ private List extractTypes(CompilationUnit compilationUnit) { private ClassUnit processEnumDeclaration(EnumDeclaration enumDeclaration) { String name = enumDeclaration.getName().getIdentifier(); - Set declaredMethods = extractMethods(enumDeclaration); + SortedSet declaredMethods = extractMethods(enumDeclaration); ClassUnit codeClassifier = new ClassUnit(codeItemRepository, name, declaredMethods); addClassifier(codeClassifier, enumDeclaration); return codeClassifier; @@ -210,7 +237,7 @@ private ClassUnit processEnumDeclaration(EnumDeclaration enumDeclaration) { private Datatype processTypeDeclaration(TypeDeclaration typeDeclaration) { String name = typeDeclaration.getName().getIdentifier(); - Set declaredMethods = extractMethods(typeDeclaration); + SortedSet declaredMethods = extractMethods(typeDeclaration); Datatype codeType; if (typeDeclaration.isInterface()) { InterfaceUnit codeInterface = new InterfaceUnit(codeItemRepository, name, declaredMethods); @@ -224,8 +251,8 @@ private Datatype processTypeDeclaration(TypeDeclaration typeDeclaration) { return codeType; } - private Set extractMethods(ASTNode node) { - Set declaredMethods = new HashSet<>(); + private SortedSet extractMethods(ASTNode node) { + SortedSet declaredMethods = new TreeSet<>(); Set methodDeclarations = MethodDeclarationFinder.find(node); for (MethodDeclaration methodDeclaration : methodDeclarations) { declaredMethods.add(extractMethod(methodDeclaration)); @@ -269,7 +296,7 @@ private CodePackage getPackage(List packageNames, CodeCompilationUnit co } private static Set mergePackages(Set packages) { - Map packageMap = new HashMap<>(); + Map packageMap = new LinkedHashMap<>(); List packageList = new ArrayList<>(packages); for (CodePackage codePackage : packageList) { if (packageMap.containsKey(codePackage.getName())) { @@ -286,6 +313,6 @@ private static Set mergePackages(Set packages) { mergedPackageElements.forEach(packageElement -> packageElement.setParent(codePackage)); codePackage.setContent(mergedPackageElements); } - return new HashSet<>(packageMap.values()); + return new LinkedHashSet<>(packageMap.values()); } } diff --git a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/java/finder/EnumDeclarationFinder.java b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/java/finder/EnumDeclarationFinder.java index da6434425..aaa46a4b4 100644 --- a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/java/finder/EnumDeclarationFinder.java +++ b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/java/finder/EnumDeclarationFinder.java @@ -1,16 +1,19 @@ /* Licensed under MIT 2023. */ package edu.kit.kastel.mcse.ardoco.core.models.connectors.generators.code.java.finder; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ASTVisitor; import org.eclipse.jdt.core.dom.EnumDeclaration; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; + +@Deterministic public class EnumDeclarationFinder extends ASTVisitor { - private Set enumDeclarations = new HashSet<>(); + private Set enumDeclarations = new LinkedHashSet<>(); public static Set find(ASTNode node) { EnumDeclarationFinder finder = new EnumDeclarationFinder(); diff --git a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/java/finder/MethodDeclarationFinder.java b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/java/finder/MethodDeclarationFinder.java index 8824c7ed4..ae29807a2 100644 --- a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/java/finder/MethodDeclarationFinder.java +++ b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/java/finder/MethodDeclarationFinder.java @@ -1,16 +1,19 @@ /* Licensed under MIT 2023. */ package edu.kit.kastel.mcse.ardoco.core.models.connectors.generators.code.java.finder; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ASTVisitor; import org.eclipse.jdt.core.dom.MethodDeclaration; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; + +@Deterministic public class MethodDeclarationFinder extends ASTVisitor { - private Set methodDeclarations = new HashSet<>(); + private Set methodDeclarations = new LinkedHashSet<>(); public static Set find(ASTNode node) { MethodDeclarationFinder finder = new MethodDeclarationFinder(); diff --git a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/java/finder/TypeDeclarationFinder.java b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/java/finder/TypeDeclarationFinder.java index f718d187b..3e063cf55 100644 --- a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/java/finder/TypeDeclarationFinder.java +++ b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/java/finder/TypeDeclarationFinder.java @@ -1,16 +1,19 @@ /* Licensed under MIT 2023. */ package edu.kit.kastel.mcse.ardoco.core.models.connectors.generators.code.java.finder; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ASTVisitor; import org.eclipse.jdt.core.dom.TypeDeclaration; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; + +@Deterministic public class TypeDeclarationFinder extends ASTVisitor { - private Set typeDeclarations = new HashSet<>(); + private Set typeDeclarations = new LinkedHashSet<>(); public static Set find(ASTNode node) { TypeDeclarationFinder finder = new TypeDeclarationFinder(); diff --git a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/shell/ShellVisitor.java b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/shell/ShellVisitor.java index c87aa5303..61d94fec8 100644 --- a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/shell/ShellVisitor.java +++ b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/connectors/generators/code/shell/ShellVisitor.java @@ -9,9 +9,9 @@ import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; @@ -28,13 +28,13 @@ public class ShellVisitor implements FileVisitor { private static final Logger logger = LoggerFactory.getLogger(ShellVisitor.class); private final Path startingDir; - private final Set codeEndpoints; + private final SortedSet codeEndpoints; private final CodeItemRepository codeItemRepository; public ShellVisitor(CodeItemRepository codeItemRepository, Path startingDir) { this.codeItemRepository = codeItemRepository; this.startingDir = startingDir; - codeEndpoints = new HashSet<>(); + codeEndpoints = new TreeSet<>(); } public CodeModel getCodeModel() { @@ -81,7 +81,7 @@ public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IO for (int i = 0; i < relativePath.getNameCount() - 1; i++) { pathElements.add(relativePath.getName(i).toString()); } - CodeCompilationUnit sourceFile = new CodeCompilationUnit(codeItemRepository, fileNameWithoutExtension, new HashSet<>(), pathElements, extension, + CodeCompilationUnit sourceFile = new CodeCompilationUnit(codeItemRepository, fileNameWithoutExtension, new TreeSet<>(), pathElements, extension, ProgrammingLanguage.SHELL); codeEndpoints.add(sourceFile); return FileVisitResult.CONTINUE; diff --git a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/informants/ArCoTLModelProviderInformant.java b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/informants/ArCoTLModelProviderInformant.java index fe56477f6..e7455b2d0 100644 --- a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/informants/ArCoTLModelProviderInformant.java +++ b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/informants/ArCoTLModelProviderInformant.java @@ -1,8 +1,8 @@ /* Licensed under MIT 2021-2023. */ package edu.kit.kastel.mcse.ardoco.core.models.informants; -import java.util.Map; import java.util.Optional; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.api.models.ModelConnector; import edu.kit.kastel.mcse.ardoco.core.api.models.ModelStates; @@ -73,7 +73,7 @@ private void addModelStateToDataRepository(String modelId, Model model) { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map map) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap map) { // empty } } diff --git a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/informants/LegacyCodeModelInformant.java b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/informants/LegacyCodeModelInformant.java index 23b69cd4f..7ffc9d22f 100644 --- a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/informants/LegacyCodeModelInformant.java +++ b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/informants/LegacyCodeModelInformant.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Lists; @@ -30,7 +30,7 @@ public LegacyCodeModelInformant(DataRepository dataRepository) { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { // empty } diff --git a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/informants/ModelProviderInformant.java b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/informants/ModelProviderInformant.java index d50d5294c..79e6c3744 100644 --- a/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/informants/ModelProviderInformant.java +++ b/stages/model-provider/src/main/java/edu/kit/kastel/mcse/ardoco/core/models/informants/ModelProviderInformant.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2021-2023. */ package edu.kit.kastel.mcse.ardoco.core.models.informants; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.list.ImmutableList; @@ -60,7 +60,7 @@ private void addModelStateToDataRepository() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map map) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap map) { // empty } } diff --git a/stages/model-provider/src/test/java/edu/kit/kastel/mcse/ardoco/core/models/generators/ArchitectureExtractorTest.java b/stages/model-provider/src/test/java/edu/kit/kastel/mcse/ardoco/core/models/generators/ArchitectureExtractorTest.java index ecf828c83..09a42c532 100644 --- a/stages/model-provider/src/test/java/edu/kit/kastel/mcse/ardoco/core/models/generators/ArchitectureExtractorTest.java +++ b/stages/model-provider/src/test/java/edu/kit/kastel/mcse/ardoco/core/models/generators/ArchitectureExtractorTest.java @@ -14,7 +14,9 @@ import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureInterface; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureItem; import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureModel; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; +@Deterministic public class ArchitectureExtractorTest { private static final Logger logger = LoggerFactory.getLogger(ArchitectureExtractorTest.class); diff --git a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/RecommendationGenerator.java b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/RecommendationGenerator.java index 9a0c95f9d..13c461bf5 100644 --- a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/RecommendationGenerator.java +++ b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/RecommendationGenerator.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.recommendationgenerator; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.MutableList; @@ -48,7 +48,7 @@ public RecommendationGenerator(DataRepository dataRepository) { * @param dataRepository the data repository * @return an instance of {@link RecommendationGenerator} */ - public static RecommendationGenerator get(Map additionalConfigs, DataRepository dataRepository) { + public static RecommendationGenerator get(SortedMap additionalConfigs, DataRepository dataRepository) { var recommendationGenerator = new RecommendationGenerator(dataRepository); recommendationGenerator.applyConfiguration(additionalConfigs); return recommendationGenerator; @@ -66,7 +66,7 @@ protected List getEnabledAgents() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { super.delegateApplyConfigurationToInternalObjects(additionalConfiguration); for (var agent : agents) { agent.applyConfiguration(additionalConfiguration); diff --git a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/RecommendationStateImpl.java b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/RecommendationStateImpl.java index 4dd6530fb..f1c4e8ee3 100644 --- a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/RecommendationStateImpl.java +++ b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/RecommendationStateImpl.java @@ -1,8 +1,6 @@ /* Licensed under MIT 2021-2023. */ package edu.kit.kastel.mcse.ardoco.core.recommendationgenerator; -import java.util.HashSet; - import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.list.MutableList; @@ -65,9 +63,7 @@ public void addRecommendedInstance(String name, Claimant claimant, double probab @Override public RecommendedInstance addRecommendedInstance(String name, String type, Claimant claimant, double probability, ImmutableList nameMappings, ImmutableList typeMappings) { - var recommendedInstance = new RecommendedInstanceImpl(name, type, claimant, probability, // - Lists.immutable.withAll(new HashSet<>(nameMappings.castToCollection())), Lists.immutable.withAll(new HashSet<>(typeMappings - .castToCollection()))); + var recommendedInstance = new RecommendedInstanceImpl(name, type, claimant, probability, nameMappings, typeMappings); this.addRecommendedInstance(recommendedInstance); return recommendedInstance; diff --git a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/RecommendationStatesImpl.java b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/RecommendationStatesImpl.java index 50f58b66d..0b820b308 100644 --- a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/RecommendationStatesImpl.java +++ b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/RecommendationStatesImpl.java @@ -2,13 +2,12 @@ package edu.kit.kastel.mcse.ardoco.core.recommendationgenerator; import java.util.EnumMap; -import java.util.Map; import edu.kit.kastel.mcse.ardoco.core.api.models.Metamodel; import edu.kit.kastel.mcse.ardoco.core.api.recommendationgenerator.RecommendationStates; public class RecommendationStatesImpl implements RecommendationStates { - private Map recommendationStates; + private final EnumMap recommendationStates; private RecommendationStatesImpl() { recommendationStates = new EnumMap<>(Metamodel.class); diff --git a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/RecommendedInstanceImpl.java b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/RecommendedInstanceImpl.java index b5cd0b521..b61fdca58 100644 --- a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/RecommendedInstanceImpl.java +++ b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/RecommendedInstanceImpl.java @@ -2,20 +2,15 @@ package edu.kit.kastel.mcse.ardoco.core.recommendationgenerator; import java.util.ArrayList; -import java.util.Collections; -import java.util.IdentityHashMap; import java.util.List; import java.util.Objects; -import java.util.Set; import java.util.UUID; import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.factory.Sets; import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.list.MutableList; -import org.eclipse.collections.api.set.ImmutableSet; -import org.eclipse.collections.api.set.MutableSet; import org.eclipse.collections.api.set.sorted.ImmutableSortedSet; +import org.eclipse.collections.api.set.sorted.MutableSortedSet; import edu.kit.kastel.mcse.ardoco.core.api.recommendationgenerator.RecommendedInstance; import edu.kit.kastel.mcse.ardoco.core.api.text.Word; @@ -46,16 +41,16 @@ public class RecommendedInstanceImpl extends RecommendedInstance implements Clai private String type; private String name; private Confidence internalConfidence; - private final Set typeMappings; - private final Set nameMappings; + private final MutableList typeMappings; + private final MutableList nameMappings; private RecommendedInstanceImpl(String name, String type) { super(name, UUID.randomUUID().toString()); this.type = type; this.name = name; this.internalConfidence = new Confidence(AggregationFunctions.AVERAGE); - nameMappings = Collections.newSetFromMap(new IdentityHashMap<>()); - typeMappings = Collections.newSetFromMap(new IdentityHashMap<>()); + nameMappings = Lists.mutable.empty(); + typeMappings = Lists.mutable.empty(); } @Override @@ -155,8 +150,6 @@ public double getProbability() { public void addMappings(NounMapping nameMapping, NounMapping typeMapping) { addName(nameMapping); addType(typeMapping); - nameMapping.registerChangeListener(this); - typeMapping.registerChangeListener(this); } /** @@ -169,9 +162,6 @@ public void addMappings(NounMapping nameMapping, NounMapping typeMapping) { public void addMappings(ImmutableList nameMapping, ImmutableList typeMapping) { nameMapping.forEach(this::addName); typeMapping.forEach(this::addType); - - nameMapping.forEach(nm -> nm.registerChangeListener(this)); - typeMapping.forEach(nm -> nm.registerChangeListener(this)); } /** @@ -181,6 +171,8 @@ public void addMappings(ImmutableList nameMapping, ImmutableList getSentenceNumbers() { - MutableSet sentenceNos = getNameMappings().flatCollect(nm -> nm.getWords().collect(Word::getSentenceNo)).toSet(); + MutableSortedSet sentenceNos = getNameMappings().flatCollect(nm -> nm.getWords().collect(Word::getSentenceNo)).toSortedSet(); return sentenceNos.toImmutableSortedSet(); } @@ -280,8 +274,8 @@ public boolean equals(Object obj) { } @Override - public ImmutableSet getClaimants() { - return Sets.immutable.withAll(this.internalConfidence.getClaimants()); + public ImmutableList getClaimants() { + return Lists.immutable.withAll(this.internalConfidence.getClaimants()); } } diff --git a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/agents/InitialRecommendationAgent.java b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/agents/InitialRecommendationAgent.java index 751433490..b4194eed8 100644 --- a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/agents/InitialRecommendationAgent.java +++ b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/agents/InitialRecommendationAgent.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.recommendationgenerator.agents; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; @@ -32,7 +32,7 @@ protected List getEnabledPipelineSteps() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); } } diff --git a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/agents/PhraseRecommendationAgent.java b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/agents/PhraseRecommendationAgent.java index bcc6d770d..3b36f47c6 100644 --- a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/agents/PhraseRecommendationAgent.java +++ b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/agents/PhraseRecommendationAgent.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.recommendationgenerator.agents; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; @@ -30,7 +30,7 @@ protected List getEnabledPipelineSteps() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); } } diff --git a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/informants/CompoundRecommendationInformant.java b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/informants/CompoundRecommendationInformant.java index 4499f6c3b..a52e2586c 100644 --- a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/informants/CompoundRecommendationInformant.java +++ b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/informants/CompoundRecommendationInformant.java @@ -1,13 +1,13 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.recommendationgenerator.informants; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.factory.Sets; +import org.eclipse.collections.api.factory.SortedSets; import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.list.MutableList; -import org.eclipse.collections.api.set.MutableSet; +import org.eclipse.collections.api.set.sorted.MutableSortedSet; import edu.kit.kastel.mcse.ardoco.core.api.models.ModelExtractionState; import edu.kit.kastel.mcse.ardoco.core.api.recommendationgenerator.RecommendationState; @@ -111,7 +111,7 @@ private void addRecommendedInstance(NounMapping nounMapping, ImmutableList getSimilarModelTypes(ImmutableList typeMappings, ModelExtractionState modelState) { - MutableSet similarModelTypes = Sets.mutable.empty(); + MutableSortedSet similarModelTypes = SortedSets.mutable.empty(); var typeIdentifiers = CommonUtilities.getTypeIdentifiers(modelState); for (var typeMapping : typeMappings) { var currSimilarTypes = Lists.immutable.fromStream(typeIdentifiers.stream() @@ -162,7 +162,7 @@ private static ImmutableList getCompoundWordsFromNounMapping(NounMapping n } @Override - protected void delegateApplyConfigurationToInternalObjects(Map map) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap map) { // empty } } diff --git a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/informants/NameTypeInformant.java b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/informants/NameTypeInformant.java index f4a38e434..992842334 100644 --- a/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/informants/NameTypeInformant.java +++ b/stages/recommendation-generator/src/main/java/edu/kit/kastel/mcse/ardoco/core/recommendationgenerator/informants/NameTypeInformant.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.recommendationgenerator.informants; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.api.models.ModelExtractionState; import edu.kit.kastel.mcse.ardoco.core.api.models.ModelStates; @@ -157,7 +157,7 @@ private void addRecommendedInstanceIfNameOrTypeAfterType(TextState textExtractio } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { // handle additional config } diff --git a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/DefaultTextStateStrategy.java b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/DefaultTextStateStrategy.java index e12031931..739b62c52 100644 --- a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/DefaultTextStateStrategy.java +++ b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/DefaultTextStateStrategy.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.textextraction; -import org.eclipse.collections.api.factory.Sets; +import org.eclipse.collections.api.factory.SortedSets; import org.eclipse.collections.api.list.MutableList; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.NounMapping; @@ -42,7 +42,7 @@ public NounMapping mergeNounMappings(NounMapping nounMapping, MutableList { +@Deterministic +@NoHashCodeEquals +public final class NounMappingImpl implements NounMapping { + private static final AtomicLong CREATION_TIME_COUNTER = new AtomicLong(0); private static final AggregationFunctions DEFAULT_AGGREGATOR = AVERAGE; private final Long earliestCreationTime; private final ImmutableSortedSet words; - private final MutableMap distribution; + private final MutableSortedMap distribution; private final ImmutableList referenceWords; private final ImmutableList surfaceForms; private final String reference; private boolean isDefinedAsCompound; private final Set changeListeners; + /** + * Instantiates a new noun mapping. A new creation time will be generated. + * + * @param words the list of words for this nounmapping + * @param kind the kind of mapping + * @param claimant the claimant that created this mapping + * @param probability the confidence + * @param referenceWords the reference words + * @param surfaceForms the surface forms + */ + public NounMappingImpl(ImmutableSortedSet words, MappingKind kind, Claimant claimant, double probability, ImmutableList referenceWords, + ImmutableList surfaceForms) { + this(CREATION_TIME_COUNTER.incrementAndGet(), words, kind, claimant, probability, referenceWords, surfaceForms); + } + + /** + * Constructor. A new creation time will be generated. + * + * @param words the words + * @param distribution the distribution map (kind to confidence) + * @param referenceWords the reference words + * @param surfaceForms the surface forms + * @param reference the String reference + */ + + public NounMappingImpl(ImmutableSortedSet words, ImmutableSortedMap distribution, ImmutableList referenceWords, + ImmutableList surfaceForms, String reference) { + this(CREATION_TIME_COUNTER.incrementAndGet(), words, distribution, referenceWords, surfaceForms, reference); + } + /** * Constructor * @@ -55,11 +88,11 @@ public final class NounMappingImpl implements NounMapping, Comparable words, MutableMap distribution, + public NounMappingImpl(Long earliestCreationTime, ImmutableSortedSet words, ImmutableSortedMap distribution, ImmutableList referenceWords, ImmutableList surfaceForms, String reference) { this.earliestCreationTime = earliestCreationTime; this.words = words; - this.distribution = distribution; + this.distribution = distribution.toSortedMap(); this.referenceWords = referenceWords; this.surfaceForms = surfaceForms; this.reference = reference; @@ -78,9 +111,10 @@ public NounMappingImpl(Long earliestCreationTime, ImmutableSortedSet words * @param referenceWords the reference words * @param surfaceForms the surface forms */ - public NounMappingImpl(Long earliestCreationTime, ImmutableSet words, MappingKind kind, Claimant claimant, double probability, + public NounMappingImpl(Long earliestCreationTime, ImmutableSortedSet words, MappingKind kind, Claimant claimant, double probability, ImmutableList referenceWords, ImmutableList surfaceForms) { - this(earliestCreationTime, words.toSortedSet().toImmutable(), Maps.mutable.empty(), referenceWords, surfaceForms, calculateReference(referenceWords)); + this(earliestCreationTime, words.toSortedSet().toImmutable(), SortedMaps.immutable.empty(), referenceWords, surfaceForms, calculateReference( + referenceWords)); Objects.requireNonNull(claimant); this.distribution.putIfAbsent(MappingKind.NAME, new Confidence(DEFAULT_AGGREGATOR)); @@ -127,9 +161,11 @@ public final ImmutableList getMappingSentenceNo() { } @Override - public ImmutableSet getPhrases() { - MutableSet phrases = Sets.mutable.empty(); + public ImmutableList getPhrases() { + MutableList phrases = Lists.mutable.empty(); for (Word word : this.words) { + if (phrases.contains(word.getPhrase())) + continue; phrases.add(word.getPhrase()); } return phrases.toImmutable(); @@ -143,7 +179,7 @@ public void addKindWithProbability(MappingKind kind, Claimant claimant, double p } @Override - public ImmutableMap getDistribution() { + public ImmutableSortedMap getDistribution() { return distribution.toImmutable(); } @@ -169,33 +205,13 @@ public boolean isCompound() { @Override public String toString() { - return "NounMapping [" + "distribution=" + distribution.entrySet() - .stream() - .map(entry -> entry.getKey() + ":" + entry.getValue()) - .collect(Collectors.joining(",")) + // + return "NounMapping [" + "distribution=" + distribution.keyValuesView().collect(entry -> entry.getOne() + ":" + entry.getTwo()).makeString(",") + // ", reference=" + getReference() + // ", node=" + String.join(", ", surfaceForms) + // ", position=" + String.join(", ", getWords().collect(word -> String.valueOf(word.getPosition()))) + // ", probability=" + getProbability() + ", isCompound=" + isCompound() + "]"; } - @Override - public int hashCode() { - return Objects.hash(getReference()); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof NounMappingImpl)) { - return false; - } - var other = (NounMapping) obj; - return Objects.equals(getReference(), other.getReference()); - } - @Override public double getProbabilityForKind(MappingKind mappingKind) { return distribution.get(mappingKind).getConfidence(); @@ -207,8 +223,11 @@ public ImmutableList getSurfaceForms() { } @Override - public ImmutableSet getClaimants() { - return this.distribution.valuesView().flatCollect(Confidence::getClaimants).toImmutableSet(); + public ImmutableList getClaimants() { + Set identitySet = new LinkedHashSet<>(); + for (var claimant : this.distribution.valuesView().flatCollect(Confidence::getClaimants)) + identitySet.add(claimant); + return Lists.immutable.withAll(identitySet); } public static Long earliestCreationTime(NounMapping... nounMappings) { @@ -220,11 +239,6 @@ public static Long earliestCreationTime(NounMapping... nounMappings) { return earliest == Long.MAX_VALUE ? null : earliest; } - @Override - public int compareTo(NounMappingImpl o) { - return Long.compare(this.earliestCreationTime, o.earliestCreationTime); - } - public Long earliestCreationTime() { return earliestCreationTime; } @@ -233,7 +247,7 @@ public ImmutableSortedSet words() { return words; } - public MutableMap distribution() { + public MutableSortedMap distribution() { return distribution; } diff --git a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/OriginalTextStateStrategy.java b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/OriginalTextStateStrategy.java index f84d0a40c..aa1474cc9 100644 --- a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/OriginalTextStateStrategy.java +++ b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/OriginalTextStateStrategy.java @@ -2,34 +2,26 @@ package edu.kit.kastel.mcse.ardoco.core.textextraction; import java.util.Arrays; -import java.util.Objects; -import java.util.function.BiPredicate; import java.util.function.Function; import java.util.stream.Collectors; import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.factory.Maps; -import org.eclipse.collections.api.factory.Sets; +import org.eclipse.collections.api.factory.SortedMaps; +import org.eclipse.collections.api.factory.SortedSets; import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.list.MutableList; -import org.eclipse.collections.api.map.MutableMap; -import org.eclipse.collections.api.set.MutableSet; +import org.eclipse.collections.api.map.sorted.MutableSortedMap; +import org.eclipse.collections.api.set.sorted.MutableSortedSet; import edu.kit.kastel.mcse.ardoco.core.api.text.Word; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.MappingKind; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.NounMapping; -import edu.kit.kastel.mcse.ardoco.core.common.util.ElementWrapper; import edu.kit.kastel.mcse.ardoco.core.common.util.SimilarityUtils; import edu.kit.kastel.mcse.ardoco.core.data.Confidence; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Claimant; public class OriginalTextStateStrategy extends DefaultTextStateStrategy { - private static final Function NOUN_MAPPING_HASH = nm -> Objects.hash(nm.getReferenceWords().toSet(), nm.getWords()); - private static final BiPredicate NOUN_MAPPING_EQUALS = (nm1, nm2) -> Objects.equals(nm1.getReferenceWords().toSet(), nm2 - .getReferenceWords() - .toSet()) && Objects.equals(nm1.getWords(), nm2.getWords()); - OriginalTextStateStrategy(TextStateImpl textState) { super.setTextState(textState); } @@ -37,8 +29,8 @@ public class OriginalTextStateStrategy extends DefaultTextStateStrategy { @Override public NounMapping addOrExtendNounMapping(Word word, MappingKind kind, Claimant claimant, double probability, ImmutableList surfaceForms) { - NounMapping disposableNounMapping = new NounMappingImpl(System.currentTimeMillis(), Sets.immutable.with(word), kind, claimant, probability, - Lists.immutable.with(word), surfaceForms); + NounMapping disposableNounMapping = new NounMappingImpl(SortedSets.immutable.with(word), kind, claimant, probability, Lists.immutable.with(word), + surfaceForms); for (var existingNounMapping : super.getTextState().getNounMappings()) { if (SimilarityUtils.areNounMappingsSimilar(disposableNounMapping, existingNounMapping)) { @@ -52,28 +44,22 @@ public NounMapping addOrExtendNounMapping(Word word, MappingKind kind, Claimant return disposableNounMapping; } - @Override - public ElementWrapper wrap(NounMapping nounMapping) { - - return new ElementWrapper<>(NounMapping.class, nounMapping, NOUN_MAPPING_HASH, NOUN_MAPPING_EQUALS); - } - @Override public NounMapping mergeNounMappings(NounMapping firstNounMapping, NounMapping secondNounMapping, ImmutableList referenceWords, String reference, MappingKind mappingKind, Claimant claimant, double probability) { - MutableSet mergedWords = firstNounMapping.getWords().toSet(); + MutableSortedSet mergedWords = firstNounMapping.getWords().toSortedSet(); mergedWords.add(secondNounMapping.getReferenceWords().get(0)); //This makes only sense under specific conditions, since it is sequentially dependent. It might be fixed in future versions - var existingNounMappingDistribution = firstNounMapping.getDistribution().toMap(); - var disposableNounMappingDistribution = secondNounMapping.getDistribution().toMap(); + var existingNounMappingDistribution = firstNounMapping.getDistribution(); + var disposableNounMappingDistribution = secondNounMapping.getDistribution(); var mergedRawMap = Arrays.stream(MappingKind.values()) .collect(Collectors.toMap( // kind -> kind, // kind -> putAllConfidencesTogether(existingNounMappingDistribution.get(kind), disposableNounMappingDistribution.get(kind)) // )); - MutableMap mergedDistribution = Maps.mutable.withMap(mergedRawMap); + MutableSortedMap mergedDistribution = SortedMaps.mutable.withSortedMap(mergedRawMap); MutableList mergedSurfaceForms = firstNounMapping.getSurfaceForms().toList(); for (var surface : secondNounMapping.getSurfaceForms()) { @@ -87,7 +73,7 @@ public NounMapping mergeNounMappings(NounMapping firstNounMapping, NounMapping s String mergedReference = mergedReferenceWords.collect(Word::getText).makeString(" "); NounMapping mergedNounMapping = new NounMappingImpl(NounMappingImpl.earliestCreationTime(firstNounMapping, secondNounMapping), mergedWords.toSortedSet() - .toImmutable(), mergedDistribution, mergedReferenceWords.toImmutable(), mergedSurfaceForms.toImmutable(), mergedReference); + .toImmutable(), mergedDistribution.toImmutable(), mergedReferenceWords.toImmutable(), mergedSurfaceForms.toImmutable(), mergedReference); this.getTextState().removeNounMappingFromState(firstNounMapping, mergedNounMapping); this.getTextState().removeNounMappingFromState(secondNounMapping, mergedNounMapping); diff --git a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/PhraseConcerningTextStateStrategy.java b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/PhraseConcerningTextStateStrategy.java index 757d7103a..58072d6cf 100644 --- a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/PhraseConcerningTextStateStrategy.java +++ b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/PhraseConcerningTextStateStrategy.java @@ -2,47 +2,35 @@ package edu.kit.kastel.mcse.ardoco.core.textextraction; import java.util.Arrays; -import java.util.Objects; -import java.util.function.BiPredicate; import java.util.function.Function; import java.util.stream.Collectors; import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.factory.Maps; -import org.eclipse.collections.api.factory.Sets; +import org.eclipse.collections.api.factory.SortedMaps; +import org.eclipse.collections.api.factory.SortedSets; import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.list.MutableList; -import org.eclipse.collections.api.map.MutableMap; -import org.eclipse.collections.api.set.ImmutableSet; -import org.eclipse.collections.api.set.MutableSet; +import org.eclipse.collections.api.map.sorted.MutableSortedMap; +import org.eclipse.collections.api.set.sorted.ImmutableSortedSet; +import org.eclipse.collections.api.set.sorted.MutableSortedSet; import edu.kit.kastel.mcse.ardoco.core.api.text.Word; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.MappingKind; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.NounMapping; -import edu.kit.kastel.mcse.ardoco.core.common.util.ElementWrapper; import edu.kit.kastel.mcse.ardoco.core.data.Confidence; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Claimant; public class PhraseConcerningTextStateStrategy extends DefaultTextStateStrategy { - private static final Function NOUN_MAPPING_HASH = nm -> Objects.hash(nm.getReference(), nm.getPhrases()); - private static final BiPredicate NOUN_MAPPING_EQUALS = (nm1, nm2) -> (Objects.equals(nm1.getPhrases(), nm2 - .getPhrases()) && Objects.equals(nm1.getReference(), nm2.getReference())); - public PhraseConcerningTextStateStrategy(TextStateImpl textState) { super.setTextState(textState); } - @Override - public ElementWrapper wrap(NounMapping nounMapping) { - return new ElementWrapper<>(NounMapping.class, nounMapping, NOUN_MAPPING_HASH, NOUN_MAPPING_EQUALS); - } - @Override public NounMapping addOrExtendNounMapping(Word word, MappingKind kind, Claimant claimant, double probability, ImmutableList surfaceForms) { var nounMappingsWithWord = super.getTextState().getNounMappings().select(nm -> nm.getWords().contains(word)); - if (nounMappingsWithWord.size() > 0) { + if (!nounMappingsWithWord.isEmpty()) { NounMapping nounMapping = nounMappingsWithWord.get(0); if (surfaceForms == null || surfaceForms.equals(nounMapping.getSurfaceForms())) { nounMapping.addKindWithProbability(kind, claimant, probability); @@ -51,11 +39,11 @@ public NounMapping addOrExtendNounMapping(Word word, MappingKind kind, Claimant } else if (nounMappingsWithWord.size() > 1) { throw new IllegalStateException("The word '" + word.getText() + "' occurs several times in the text state."); } - ImmutableSet words = Sets.immutable.with(word); + ImmutableSortedSet words = SortedSets.immutable.with(word); if (surfaceForms == null) { surfaceForms = Lists.immutable.with(word.getText()); } - NounMapping nounMapping = new NounMappingImpl(System.currentTimeMillis(), words, kind, claimant, probability, words.toImmutableList(), surfaceForms); + NounMapping nounMapping = new NounMappingImpl(words, kind, claimant, probability, words.toImmutableList(), surfaceForms); super.getTextState().addNounMappingAddPhraseMapping(nounMapping); return nounMapping; } @@ -64,17 +52,17 @@ public NounMapping addOrExtendNounMapping(Word word, MappingKind kind, Claimant public NounMapping mergeNounMappings(NounMapping firstNounMapping, NounMapping secondNounMapping, ImmutableList referenceWords, String reference, MappingKind mappingKind, Claimant claimant, double probability) { - MutableSet mergedWords = firstNounMapping.getWords().toSet(); + MutableSortedSet mergedWords = firstNounMapping.getWords().toSortedSet(); mergedWords.addAllIterable(secondNounMapping.getWords()); - var distribution1 = firstNounMapping.getDistribution().toMap(); - var distribution2 = secondNounMapping.getDistribution().toMap(); + var distribution1 = firstNounMapping.getDistribution(); + var distribution2 = secondNounMapping.getDistribution(); var mergedRawMap = Arrays.stream(MappingKind.values()) .collect(Collectors.toMap( // kind -> kind, // kind -> putAllConfidencesTogether(distribution1.get(kind), distribution2.get(kind)) // )); - MutableMap mergedDistribution = Maps.mutable.withMap(mergedRawMap); + MutableSortedMap mergedDistribution = SortedMaps.mutable.withSortedMap(mergedRawMap); MutableList mergedSurfaceForms = firstNounMapping.getSurfaceForms().toList(); for (var surface : secondNounMapping.getSurfaceForms()) { @@ -104,7 +92,8 @@ public NounMapping mergeNounMappings(NounMapping firstNounMapping, NounMapping s } NounMapping mergedNounMapping = new NounMappingImpl(NounMappingImpl.earliestCreationTime(firstNounMapping, secondNounMapping), mergedWords - .toImmutableSortedSet(), mergedDistribution, mergedReferenceWords.toImmutable(), mergedSurfaceForms.toImmutable(), mergedReference); + .toImmutableSortedSet(), mergedDistribution.toImmutable(), mergedReferenceWords.toImmutable(), mergedSurfaceForms.toImmutable(), + mergedReference); mergedNounMapping.addKindWithProbability(mappingKind, claimant, probability); this.getTextState().removeNounMappingFromState(firstNounMapping, mergedNounMapping); diff --git a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/PhraseMappingImpl.java b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/PhraseMappingImpl.java index 127027f90..b4d087c54 100644 --- a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/PhraseMappingImpl.java +++ b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/PhraseMappingImpl.java @@ -1,19 +1,16 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.textextraction; -import java.util.Collection; -import java.util.Collections; -import java.util.IdentityHashMap; -import java.util.Objects; +import java.util.LinkedHashSet; import java.util.Set; import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.factory.Maps; -import org.eclipse.collections.api.factory.Sets; +import org.eclipse.collections.api.factory.SortedMaps; +import org.eclipse.collections.api.factory.SortedSets; import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.list.MutableList; -import org.eclipse.collections.api.map.ImmutableMap; -import org.eclipse.collections.api.map.MutableMap; +import org.eclipse.collections.api.map.sorted.ImmutableSortedMap; +import org.eclipse.collections.api.map.sorted.MutableSortedMap; import edu.kit.kastel.mcse.ardoco.core.api.text.Phrase; import edu.kit.kastel.mcse.ardoco.core.api.text.PhraseType; @@ -22,25 +19,27 @@ import edu.kit.kastel.mcse.ardoco.core.api.textextraction.PhraseMapping; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.PhraseMappingChangeListener; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.TextState; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; +import edu.kit.kastel.mcse.ardoco.core.architecture.NoHashCodeEquals; +@Deterministic +@NoHashCodeEquals public final class PhraseMappingImpl implements PhraseMapping { - /** * Phrases encapsulated in the mapping. */ - private final Set phrases; + private final MutableList phrases; - private final Set changeListeners = Collections.newSetFromMap(new IdentityHashMap<>()); + private final Set changeListeners = new LinkedHashSet<>(); - public PhraseMappingImpl(Collection phrases) { - this.phrases = Collections.newSetFromMap(new IdentityHashMap<>()); - this.phrases.addAll(phrases); + public PhraseMappingImpl(ImmutableList phrases) { + this.phrases = Lists.mutable.withAll(phrases); } @Override public ImmutableList getNounMappings(TextState textState) { - var allContainedWords = Sets.mutable.fromStream(phrases.stream().flatMap(phrase -> phrase.getContainedWords().stream())); - return textState.getNounMappings().select(nm -> Sets.mutable.withAll(nm.getWords()).equals(allContainedWords)); + var allContainedWords = SortedSets.mutable.withAll(phrases.stream().flatMap(phrase -> phrase.getContainedWords().stream()).toList()); + return textState.getNounMappings().select(nm -> SortedSets.mutable.withAll(nm.getWords()).equals(allContainedWords)); } @Override @@ -63,35 +62,20 @@ public PhraseType getPhraseType() { } @Override - public ImmutableMap getPhraseVector() { + public ImmutableSortedMap getPhraseVector() { MutableList words = Lists.mutable.empty(); for (Phrase phrase : phrases) { words.addAllIterable(phrase.getContainedWords()); } - MutableMap phraseVector = Maps.mutable.empty(); + MutableSortedMap phraseVector = SortedMaps.mutable.empty(); var grouped = words.groupBy(Word::getText).toMap(); grouped.forEach((key, value) -> phraseVector.put(value.getAny(), value.size())); return phraseVector.toImmutable(); } - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - PhraseMappingImpl that = (PhraseMappingImpl) o; - return Objects.equals(phrases, that.phrases); - } - - @Override - public int hashCode() { - return Objects.hash(phrases); - } - @Override public String toString() { return "PhraseMapping{" + "phrases=" + phrases + '}'; diff --git a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/TextExtraction.java b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/TextExtraction.java index e565fda94..6f0798308 100644 --- a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/TextExtraction.java +++ b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/TextExtraction.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.textextraction; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.MutableList; @@ -44,7 +44,7 @@ public TextExtraction(DataRepository dataRepository) { * @param dataRepository the data repository * @return an instance of InconsistencyChecker */ - public static TextExtraction get(Map additionalConfigs, DataRepository dataRepository) { + public static TextExtraction get(SortedMap additionalConfigs, DataRepository dataRepository) { var textExtractor = new TextExtraction(dataRepository); textExtractor.applyConfiguration(additionalConfigs); return textExtractor; @@ -66,7 +66,7 @@ protected List getEnabledAgents() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { super.delegateApplyConfigurationToInternalObjects(additionalConfiguration); for (var agent : agents) { agent.applyConfiguration(additionalConfiguration); diff --git a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/TextStateImpl.java b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/TextStateImpl.java index 25706d8ab..4a98c3aca 100644 --- a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/TextStateImpl.java +++ b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/TextStateImpl.java @@ -4,20 +4,19 @@ import static edu.kit.kastel.mcse.ardoco.core.common.AggregationFunctions.AVERAGE; import java.util.Comparator; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import java.util.SortedMap; import java.util.function.Function; import org.eclipse.collections.api.block.predicate.Predicate; import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.factory.Maps; -import org.eclipse.collections.api.factory.Sets; +import org.eclipse.collections.api.factory.SortedMaps; +import org.eclipse.collections.api.factory.SortedSets; import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.list.MutableList; -import org.eclipse.collections.api.map.MutableMap; -import org.eclipse.collections.api.set.ImmutableSet; -import org.eclipse.collections.api.set.MutableSet; +import org.eclipse.collections.api.map.sorted.ImmutableSortedMap; +import org.eclipse.collections.api.map.sorted.MutableSortedMap; +import org.eclipse.collections.api.set.sorted.ImmutableSortedSet; +import org.eclipse.collections.api.set.sorted.MutableSortedSet; import edu.kit.kastel.mcse.ardoco.core.api.text.Phrase; import edu.kit.kastel.mcse.ardoco.core.api.text.Word; @@ -27,7 +26,7 @@ import edu.kit.kastel.mcse.ardoco.core.api.textextraction.TextState; import edu.kit.kastel.mcse.ardoco.core.common.AggregationFunctions; import edu.kit.kastel.mcse.ardoco.core.common.tuple.Pair; -import edu.kit.kastel.mcse.ardoco.core.common.util.ElementWrapper; +import edu.kit.kastel.mcse.ardoco.core.common.util.Comparators; import edu.kit.kastel.mcse.ardoco.core.common.util.SimilarityUtils; import edu.kit.kastel.mcse.ardoco.core.data.AbstractState; import edu.kit.kastel.mcse.ardoco.core.data.Confidence; @@ -40,17 +39,15 @@ public class TextStateImpl extends AbstractState implements TextState { private static final AggregationFunctions DEFAULT_AGGREGATOR = AVERAGE; - private static final Comparator> ORDER_NOUNMAPPING = (n1, n2) -> { + private static final Comparator ORDER_NOUNMAPPING = (n1, n2) -> { if (n1.equals(n2)) return 0; - var nm1 = (NounMappingImpl) n1.getElement(); - var nm2 = (NounMappingImpl) n2.getElement(); + var nm1 = (NounMappingImpl) n1; + var nm2 = (NounMappingImpl) n2; int compare = Long.compare(nm1.earliestCreationTime(), nm2.earliestCreationTime()); if (compare != 0) return compare; - - // Not equal but at same time -> order by something .. e.g., hash .. - return Integer.compare(n1.hashCode(), n2.hashCode()); + throw new IllegalStateException("NounMappings are not equal but have same creation time"); }; /** @@ -59,8 +56,8 @@ public class TextStateImpl extends AbstractState implements TextState { * @see #getMappingsThatCouldBeOfKind(Word, MappingKind) */ private static final double MAPPING_KIND_MAX_DIFF = 0.1; - private MutableList> nounMappings; - private MutableSet phraseMappings; + private MutableList nounMappings; + private MutableList phraseMappings; private final transient TextStateStrategy strategy; /** @@ -72,7 +69,7 @@ public TextStateImpl() { public TextStateImpl(Function constructor) { nounMappings = Lists.mutable.empty(); - phraseMappings = Sets.mutable.empty(); + phraseMappings = Lists.mutable.empty(); strategy = constructor.apply(this); } @@ -87,35 +84,33 @@ public NounMapping addNounMapping(Word word, MappingKind kind, Claimant claimant } @Override - public NounMapping addNounMapping(ImmutableSet words, MappingKind kind, Claimant claimant, double probability, ImmutableList referenceWords, - ImmutableList surfaceForms, String reference) { - MutableMap distribution = Maps.mutable.empty(); + public NounMapping addNounMapping(ImmutableSortedSet words, MappingKind kind, Claimant claimant, double probability, + ImmutableList referenceWords, ImmutableList surfaceForms, String reference) { + MutableSortedMap distribution = SortedMaps.mutable.empty(); distribution.put(MappingKind.NAME, new Confidence(DEFAULT_AGGREGATOR)); distribution.put(MappingKind.TYPE, new Confidence(DEFAULT_AGGREGATOR)); - NounMapping nounMapping = new NounMappingImpl(System.currentTimeMillis(), words.toSortedSet().toImmutable(), distribution, referenceWords, surfaceForms, - reference); + NounMapping nounMapping = new NounMappingImpl(words.toSortedSet().toImmutable(), distribution.toImmutable(), referenceWords, surfaceForms, reference); nounMapping.addKindWithProbability(kind, claimant, probability); addNounMappingAddPhraseMapping(nounMapping); return nounMapping; } @Override - public NounMapping addNounMapping(ImmutableSet words, MutableMap distribution, ImmutableList referenceWords, - ImmutableList surfaceForms, String reference) { + public NounMapping addNounMapping(ImmutableSortedSet words, ImmutableSortedMap distribution, + ImmutableList referenceWords, ImmutableList surfaceForms, String reference) { if (reference == null) { reference = calculateNounMappingReference(referenceWords); } - NounMapping nounMapping = new NounMappingImpl(System.currentTimeMillis(), words.toSortedSet().toImmutable(), distribution, referenceWords, surfaceForms, - reference); + NounMapping nounMapping = new NounMappingImpl(words.toSortedSet().toImmutable(), distribution, referenceWords, surfaceForms, reference); addNounMappingAddPhraseMapping(nounMapping); return nounMapping; } @Override public ImmutableList getNounMappings() { - return this.nounMappings.toImmutableList().collect(ElementWrapper::getElement); + return this.nounMappings.toImmutableList(); } @@ -138,14 +133,14 @@ public ImmutableList getPhraseMappingsByNounMapping(NounMapping n @Override public PhraseMapping getPhraseMappingByNounMapping(NounMapping nounMapping) { ImmutableList phraseMappingsByNounMapping = getPhraseMappingsByNounMapping(nounMapping); - assert (phraseMappingsByNounMapping.size() >= 1) : "Every noun mapping should be connected to a phrase mapping"; + assert (!phraseMappingsByNounMapping.isEmpty()) : "Every noun mapping should be connected to a phrase mapping"; return phraseMappingsByNounMapping.get(0); } @Override public ImmutableList getNounMappingsByPhraseMapping(PhraseMapping phraseMapping) { - return getNounMappings().select(nm -> phraseMapping.getPhrases().toImmutableSet().equals(nm.getPhrases())); + return getNounMappings().select(nm -> Comparators.collectionsEqualsAnyOrder(phraseMapping.getPhrases().castToList(), nm.getPhrases().castToList())); } /** @@ -174,8 +169,8 @@ public void mergeNounMappings(NounMapping nounMapping, NounMapping otherNounMapp @Override public NounMapping setReferenceOfNounMapping(NounMapping nounMapping, ImmutableList referenceWords, String reference) { - return this.addNounMapping(nounMapping.getWords().toImmutableSet(), nounMapping.getDistribution().toMap(), referenceWords, nounMapping - .getSurfaceForms(), reference); + return this.addNounMapping(nounMapping.getWords().toImmutableSortedSet(), nounMapping.getDistribution(), referenceWords, nounMapping.getSurfaceForms(), + reference); } @@ -252,10 +247,10 @@ public void mergePhraseMappingsAndNounMappings(PhraseMapping phraseMapping, Phra @Override public PhraseMapping mergePhraseMappings(PhraseMapping phraseMapping, PhraseMapping similarPhraseMapping) { - MutableSet mergedPhrases = phraseMapping.getPhrases().toSet(); + MutableList mergedPhrases = phraseMapping.getPhrases().toList(); mergedPhrases.addAll(similarPhraseMapping.getPhrases().toList()); - PhraseMapping mergedPhraseMapping = new PhraseMappingImpl(mergedPhrases); + PhraseMapping mergedPhraseMapping = new PhraseMappingImpl(mergedPhrases.toImmutable()); this.phraseMappings.add(mergedPhraseMapping); @@ -269,7 +264,7 @@ public NounMapping getNounMappingByWord(Word word) { var result = getNounMappings().select(nMapping -> nMapping.getWords().contains(word)).toImmutable(); assert (result.size() <= 1) : "A word should only contained by one noun mapping"; - if (result.size() == 0) { + if (result.isEmpty()) { return null; } return result.get(0); @@ -282,7 +277,7 @@ public NounMapping getNounMappingByWord(Word word) { */ @Override public ImmutableList getListOfReferences(MappingKind kind) { - Set referencesOfKind = new HashSet<>(); + MutableSortedSet referencesOfKind = SortedSets.mutable.empty(); var kindMappings = getNounMappingsOfKind(kind); for (NounMapping nnm : kindMappings) { referencesOfKind.add(nnm.getReference()); @@ -296,7 +291,9 @@ private Predicate nounMappingIsOfKind(MappingKind mappingKi void addNounMappingAddPhraseMapping(NounMapping nounMapping) { addNounMappingToState(nounMapping); - phraseMappings.add(new PhraseMappingImpl(nounMapping.getPhrases().castToSet())); + if (phraseMappings.anySatisfy(it -> Comparators.collectionsIdentityAnyOrder(it.getPhrases(), nounMapping.getPhrases()))) + return; + phraseMappings.add(new PhraseMappingImpl(nounMapping.getPhrases())); } @Override @@ -305,7 +302,6 @@ public void removeNounMapping(NounMapping nounMapping, NounMapping replacement) var otherNounMappings = getNounMappingsThatBelongToTheSamePhraseMapping(nounMapping); if (!otherNounMappings.isEmpty()) { - var phrases = nounMapping.getPhrases().select(p -> !otherNounMappings.flatCollect(NounMapping::getPhrases).contains(p)); phrases.forEach(phraseMapping::removePhrase); } @@ -325,10 +321,10 @@ String calculateNounMappingReference(ImmutableList referenceWords) { } private void addNounMappingToState(NounMapping nounMapping) { - if (this.nounMappings.contains(wrap(nounMapping))) { + if (this.nounMappings.contains(nounMapping)) { throw new IllegalArgumentException("Nounmapping was already in state"); } - this.nounMappings.add(wrap(nounMapping)); + this.nounMappings.add(nounMapping); this.nounMappings.sortThis(ORDER_NOUNMAPPING); } @@ -338,21 +334,17 @@ void removePhraseMappingFromState(PhraseMapping phraseMapping, PhraseMapping rep } void removeNounMappingFromState(NounMapping nounMapping, NounMapping replacement) { - this.nounMappings.remove(wrap(nounMapping)); + this.nounMappings.remove(nounMapping); nounMapping.onDelete(replacement); } - private ElementWrapper wrap(NounMapping nounMapping) { - return strategy.wrap(nounMapping); - } - @Override public String toString() { return "TextExtractionState [NounMappings: \n" + getNounMappings() + "\n PhraseMappings: \n" + getPhraseMappings() + "]"; } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { // handle additional configuration } diff --git a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/TextStateStrategy.java b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/TextStateStrategy.java index 4429f8ec4..e9f3d8d6e 100644 --- a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/TextStateStrategy.java +++ b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/TextStateStrategy.java @@ -8,7 +8,6 @@ import edu.kit.kastel.mcse.ardoco.core.api.text.Word; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.MappingKind; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.NounMapping; -import edu.kit.kastel.mcse.ardoco.core.common.util.ElementWrapper; import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Claimant; /** @@ -18,8 +17,6 @@ public interface TextStateStrategy { NounMapping addOrExtendNounMapping(Word word, MappingKind kind, Claimant claimant, double probability, ImmutableList surfaceForms); - ElementWrapper wrap(NounMapping nounMapping); - NounMapping mergeNounMappings(NounMapping firstNounMapping, NounMapping secondNounMapping, ImmutableList referenceWords, String reference, MappingKind mappingKind, Claimant claimant, double probability); diff --git a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/InitialTextAgent.java b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/InitialTextAgent.java index 32b733028..c3d3316b3 100644 --- a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/InitialTextAgent.java +++ b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/InitialTextAgent.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.textextraction.agents; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; @@ -36,7 +36,7 @@ public InitialTextAgent(DataRepository data) { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); } diff --git a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/MappingCombiner.java b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/MappingCombiner.java index ad407667c..8bad57fe6 100644 --- a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/MappingCombiner.java +++ b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/MappingCombiner.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.textextraction.agents; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; @@ -30,7 +30,7 @@ protected List getEnabledPipelineSteps() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); } } diff --git a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/PhraseAgent.java b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/PhraseAgent.java index b70046fd3..027b13aba 100644 --- a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/PhraseAgent.java +++ b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/PhraseAgent.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.textextraction.agents; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.NounMapping; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; @@ -39,7 +39,7 @@ protected List getEnabledPipelineSteps() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); } diff --git a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/CompoundAgentInformant.java b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/CompoundAgentInformant.java index 910ce226a..bdf16cebd 100644 --- a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/CompoundAgentInformant.java +++ b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/CompoundAgentInformant.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.textextraction.informants; -import java.util.Map; +import java.util.SortedMap; import java.util.StringJoiner; import org.eclipse.collections.api.factory.Lists; @@ -71,7 +71,7 @@ private void addCompoundNounMapping(ImmutableList compoundWords, TextState var similarReferenceNounMappings = textState.getNounMappingsWithSimilarReference(reference); if (similarReferenceNounMappings.isEmpty()) { - var nounMapping = textState.addNounMapping(compoundWords.toImmutableSet(), MappingKind.NAME, this, compoundConfidence, compoundWords + var nounMapping = textState.addNounMapping(compoundWords.toImmutableSortedSet(), MappingKind.NAME, this, compoundConfidence, compoundWords .toImmutableList(), compoundWords.collect(Word::getText).toImmutableList(), createReferenceForCompound(compoundWords)); ((NounMappingImpl) nounMapping).setIsDefinedAsCompound(true); } else { @@ -79,10 +79,10 @@ private void addCompoundNounMapping(ImmutableList compoundWords, TextState textState.removeNounMapping(nounMapping, null); - var newWords = nounMapping.getWords().toSet(); + var newWords = nounMapping.getWords().toSortedSet(); newWords.addAllIterable(compoundWords); - var compoundMapping = textState.addNounMapping(newWords.toImmutable(), nounMapping.getDistribution().toMap(), nounMapping.getReferenceWords(), + var compoundMapping = textState.addNounMapping(newWords.toImmutable(), nounMapping.getDistribution(), nounMapping.getReferenceWords(), nounMapping.getSurfaceForms(), nounMapping.getReference()); nounMapping.onDelete(compoundMapping); ((NounMappingImpl) compoundMapping).setIsDefinedAsCompound(true); @@ -107,7 +107,7 @@ private void createNounMappingIfSpecialNamedEntity(Word word, TextState textStat } @Override - protected void delegateApplyConfigurationToInternalObjects(Map map) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap map) { // none } } diff --git a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/InDepArcsInformant.java b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/InDepArcsInformant.java index e335ebe55..a2d078edc 100644 --- a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/InDepArcsInformant.java +++ b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/InDepArcsInformant.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2021-2023. */ package edu.kit.kastel.mcse.ardoco.core.textextraction.informants; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.api.text.DependencyTag; import edu.kit.kastel.mcse.ardoco.core.api.text.Word; @@ -81,7 +81,7 @@ private static boolean hasNameOrTypeDependencies(DependencyTag depTag) { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { // emtpy } } diff --git a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/MappingCombinerInformant.java b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/MappingCombinerInformant.java index 433329b97..b3f39fc74 100644 --- a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/MappingCombinerInformant.java +++ b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/MappingCombinerInformant.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.textextraction.informants; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.ImmutableList; @@ -12,6 +12,7 @@ import edu.kit.kastel.mcse.ardoco.core.api.textextraction.PhraseMapping; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.TextState; import edu.kit.kastel.mcse.ardoco.core.common.tuple.Pair; +import edu.kit.kastel.mcse.ardoco.core.common.util.Comparators; import edu.kit.kastel.mcse.ardoco.core.common.util.DataRepositoryHelper; import edu.kit.kastel.mcse.ardoco.core.common.util.PhraseMappingAggregatorStrategy; import edu.kit.kastel.mcse.ardoco.core.common.util.SimilarityUtils; @@ -41,6 +42,11 @@ private void combineSimilarPhraseMappings(TextState textState) { for (PhraseMapping phraseMapping : phraseMappings) { ImmutableList similarPhraseMappings = phraseMappings.select(p -> SimilarityUtils.getPhraseMappingSimilarity(textState, phraseMapping, p, PhraseMappingAggregatorStrategy.MAX_SIMILARITY) > minCosineSimilarity); + + // Remove the phrase mapping from the list of similar phrase mappings + // Comment: This would break the logic but seems to be logical .. + // similarPhraseMappings = similarPhraseMappings.newWithout(phraseMapping); + processPhraseMappingForSimilarPhraseMappings(textState, similarPhraseMappings, phraseMapping); } @@ -54,7 +60,8 @@ private void processPhraseMappingForSimilarPhraseMappings(TextState textState, I ImmutableList nounMappingsOfSimilarPhraseMapping = textState.getNounMappingsByPhraseMapping(similarPhraseMapping); - if (similarPhraseMapping.getPhrases().collect(Phrase::getText).equals(phraseMapping.getPhrases().collect(Phrase::getText))) { + if (Comparators.collectionsEqualsAnyOrder(similarPhraseMapping.getPhrases().collect(Phrase::getText), phraseMapping.getPhrases() + .collect(Phrase::getText))) { processSimilarPhraseMappingWhenEqualPhraseText(textState, phraseMapping, nounMappingsOfSimilarPhraseMapping); continue; } @@ -78,9 +85,11 @@ private void processSimilarPhraseMappingWhenEquallySized(TextState textState, Im } } - if (!((similarNounMappings.size() != nounMappingsOfPhraseMapping.size()) || (similarPhraseMappings.size() != similarNounMappings.collect(Pair::second) - .distinct() - .size() * 2))) { + boolean merge = true; + merge &= similarNounMappings.size() == nounMappingsOfPhraseMapping.size(); + merge &= similarPhraseMappings.size() == similarNounMappings.collect(Pair::second).distinct().size() * 2; + + if (merge) { textState.mergePhraseMappingsAndNounMappings(phraseMapping, similarPhraseMapping, similarNounMappings, this); } } @@ -119,7 +128,7 @@ private NounMapping getMostSimilarNounMappingOverThreshold(NounMapping nounMappi } @Override - protected void delegateApplyConfigurationToInternalObjects(Map map) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap map) { //none } } diff --git a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/NounInformant.java b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/NounInformant.java index 4520fb39f..8630bd8ac 100644 --- a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/NounInformant.java +++ b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/NounInformant.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2021-2023. */ package edu.kit.kastel.mcse.ardoco.core.textextraction.informants; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.list.ImmutableList; @@ -61,7 +61,7 @@ private void findSingleNouns(TextState textState, Word word) { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { // empty } } diff --git a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/OutDepArcsInformant.java b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/OutDepArcsInformant.java index deef9b276..cf872121d 100644 --- a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/OutDepArcsInformant.java +++ b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/OutDepArcsInformant.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2021-2023. */ package edu.kit.kastel.mcse.ardoco.core.textextraction.informants; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.api.text.DependencyTag; import edu.kit.kastel.mcse.ardoco.core.api.text.Word; @@ -70,7 +70,7 @@ private void examineOutgoingDepArcs(TextState textState, Word word) { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { // emtpy } diff --git a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/SeparatedNamesInformant.java b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/SeparatedNamesInformant.java index 5cfaa29b6..01e5a5e46 100644 --- a/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/SeparatedNamesInformant.java +++ b/stages/text-extraction/src/main/java/edu/kit/kastel/mcse/ardoco/core/textextraction/informants/SeparatedNamesInformant.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2021-2023. */ package edu.kit.kastel.mcse.ardoco.core.textextraction.informants; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.api.text.POSTag; import edu.kit.kastel.mcse.ardoco.core.api.text.Word; @@ -59,7 +59,7 @@ private void checkForSeparatedNode(TextState textState, Word word) { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { // emtpy } diff --git a/stages/text-extraction/src/test/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/MappingCombinerTest.java b/stages/text-extraction/src/test/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/MappingCombinerTest.java index 5d93fcf0b..3d32c272b 100644 --- a/stages/text-extraction/src/test/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/MappingCombinerTest.java +++ b/stages/text-extraction/src/test/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/MappingCombinerTest.java @@ -4,7 +4,6 @@ import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.list.MutableList; -import org.eclipse.collections.api.set.MutableSet; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -17,7 +16,6 @@ import edu.kit.kastel.mcse.ardoco.core.api.textextraction.NounMapping; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.PhraseMapping; import edu.kit.kastel.mcse.ardoco.core.api.textextraction.TextState; -import edu.kit.kastel.mcse.ardoco.core.common.util.ElementWrapper; import edu.kit.kastel.mcse.ardoco.core.common.util.PhraseMappingAggregatorStrategy; import edu.kit.kastel.mcse.ardoco.core.common.util.SimilarityUtils; import edu.kit.kastel.mcse.ardoco.core.data.DataRepository; @@ -449,11 +447,11 @@ private void mockWord(Word word, String text, String lemma, int sentenceNumber, private TextState createCopy(TextState textState) { TextStateImpl newTextState = new TextStateImpl(); - MutableList> nounMappings = getField(textState, "nounMappings"); - MutableSet phraseMappings = getField(textState, "phraseMappings"); + MutableList nounMappings = getField(textState, "nounMappings"); + MutableList phraseMappings = getField(textState, "phraseMappings"); - MutableList> newNounMappings = getField(newTextState, "nounMappings"); - MutableSet newPhraseMappings = getField(newTextState, "phraseMappings"); + MutableList newNounMappings = getField(newTextState, "nounMappings"); + MutableList newPhraseMappings = getField(newTextState, "phraseMappings"); newNounMappings.addAll(nounMappings); newPhraseMappings.addAll(phraseMappings); diff --git a/stages/text-extraction/src/test/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/PDFExtractorTestCase.java b/stages/text-extraction/src/test/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/PDFExtractorTestCase.java index cb9bb4b80..a894c865c 100644 --- a/stages/text-extraction/src/test/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/PDFExtractorTestCase.java +++ b/stages/text-extraction/src/test/java/edu/kit/kastel/mcse/ardoco/core/textextraction/agents/PDFExtractorTestCase.java @@ -3,22 +3,26 @@ import java.io.File; import java.io.IOException; -import java.util.LinkedHashSet; import java.util.Set; import java.util.function.BiConsumer; import java.util.function.Predicate; import org.apache.pdfbox.Loader; import org.apache.pdfbox.text.PDFTextStripper; +import org.eclipse.collections.api.factory.SortedSets; +import org.eclipse.collections.api.set.sorted.MutableSortedSet; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; import com.fasterxml.jackson.databind.ObjectMapper; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; + /** * Not a test, but it extracts the data from the downloaded pdfs. */ @EnabledIfEnvironmentVariable(matches = "true", named = "ExtractPDF") +@Deterministic class PDFExtractorTestCase { @Test @@ -67,7 +71,7 @@ void extractISO24765() throws IOException { extract("./src/main/resources/pdfs/24765-2017.pdf", "./src/main/resources/pdfs/24765-2017.pdf.words.txt", this::processTextISO24765); } - private void processTextISO24765(String text, Set foundWords) { + private void processTextISO24765(String text, MutableSortedSet foundWords) { String[] lines = text.lines().toArray(String[]::new); boolean lastLineWasIdentifier = false; Predicate isIdentifier = l -> l != null && l.trim().matches("^3\\.[0-9]+$"); @@ -84,10 +88,10 @@ private void processTextISO24765(String text, Set foundWords) { } } - private void extract(String in, String out, BiConsumer> processor) throws IOException { + private void extract(String in, String out, BiConsumer> processor) throws IOException { var file = new File(in); var pdf = Loader.loadPDF(file); - Set foundWords = new LinkedHashSet<>(); + MutableSortedSet foundWords = SortedSets.mutable.empty(); PDFTextStripper pts = new PDFTextStripper(); var text = pts.getText(pdf); processor.accept(text, foundWords); diff --git a/stages/text-preprocessing/src/main/java/edu/kit/kastel/mcse/ardoco/core/text/providers/TextPreprocessingAgent.java b/stages/text-preprocessing/src/main/java/edu/kit/kastel/mcse/ardoco/core/text/providers/TextPreprocessingAgent.java index a9a18682f..858e7f828 100644 --- a/stages/text-preprocessing/src/main/java/edu/kit/kastel/mcse/ardoco/core/text/providers/TextPreprocessingAgent.java +++ b/stages/text-preprocessing/src/main/java/edu/kit/kastel/mcse/ardoco/core/text/providers/TextPreprocessingAgent.java @@ -2,7 +2,7 @@ package edu.kit.kastel.mcse.ardoco.core.text.providers; import java.util.List; -import java.util.Map; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.api.text.NlpInformant; import edu.kit.kastel.mcse.ardoco.core.configuration.Configurable; @@ -37,14 +37,14 @@ public TextPreprocessingAgent(DataRepository data) { * @param dataRepository the data repository * @return a CoreNLPProvider with the provided text read in */ - public static TextPreprocessingAgent get(Map additionalConfigs, DataRepository dataRepository) { + public static TextPreprocessingAgent get(SortedMap additionalConfigs, DataRepository dataRepository) { var textProvider = new TextPreprocessingAgent(dataRepository); textProvider.applyConfiguration(additionalConfigs); return textProvider; } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { informants.forEach(e -> e.applyConfiguration(additionalConfiguration)); } diff --git a/stages/text-preprocessing/src/main/java/edu/kit/kastel/mcse/ardoco/core/text/providers/informants/corenlp/CoreNLPProvider.java b/stages/text-preprocessing/src/main/java/edu/kit/kastel/mcse/ardoco/core/text/providers/informants/corenlp/CoreNLPProvider.java index dd5542fde..8a38920f3 100644 --- a/stages/text-preprocessing/src/main/java/edu/kit/kastel/mcse/ardoco/core/text/providers/informants/corenlp/CoreNLPProvider.java +++ b/stages/text-preprocessing/src/main/java/edu/kit/kastel/mcse/ardoco/core/text/providers/informants/corenlp/CoreNLPProvider.java @@ -1,8 +1,8 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.text.providers.informants.corenlp; -import java.util.Map; import java.util.Properties; +import java.util.SortedMap; import edu.kit.kastel.mcse.ardoco.core.api.PreprocessingData; import edu.kit.kastel.mcse.ardoco.core.api.text.NlpInformant; @@ -79,7 +79,7 @@ private Text processText(String inputText) { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map map) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap map) { // empty } } diff --git a/stages/text-preprocessing/src/main/java/edu/kit/kastel/mcse/ardoco/core/text/providers/informants/corenlp/PhraseImpl.java b/stages/text-preprocessing/src/main/java/edu/kit/kastel/mcse/ardoco/core/text/providers/informants/corenlp/PhraseImpl.java index 23af8203a..7712c8e11 100644 --- a/stages/text-preprocessing/src/main/java/edu/kit/kastel/mcse/ardoco/core/text/providers/informants/corenlp/PhraseImpl.java +++ b/stages/text-preprocessing/src/main/java/edu/kit/kastel/mcse/ardoco/core/text/providers/informants/corenlp/PhraseImpl.java @@ -3,19 +3,24 @@ import java.util.Objects; +import org.eclipse.collections.api.RichIterable; import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.factory.Maps; +import org.eclipse.collections.api.factory.SortedMaps; import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.list.MutableList; -import org.eclipse.collections.api.map.ImmutableMap; import org.eclipse.collections.api.map.MutableMap; +import org.eclipse.collections.api.map.sorted.ImmutableSortedMap; +import org.eclipse.collections.api.map.sorted.MutableSortedMap; import edu.kit.kastel.mcse.ardoco.core.api.text.Phrase; import edu.kit.kastel.mcse.ardoco.core.api.text.PhraseType; import edu.kit.kastel.mcse.ardoco.core.api.text.Word; +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; import edu.stanford.nlp.trees.Tree; +@Deterministic public class PhraseImpl implements Phrase { + private final Tree tree; private final ImmutableList words; @@ -89,10 +94,10 @@ public boolean isSubPhraseOf(Phrase other) { } @Override - public ImmutableMap getPhraseVector() { - MutableMap phraseVector = Maps.mutable.empty(); + public ImmutableSortedMap getPhraseVector() { + MutableSortedMap phraseVector = SortedMaps.mutable.empty(); - var grouped = getContainedWords().groupBy(Word::getText).toMap(); + MutableMap> grouped = getContainedWords().groupBy(Word::getText).toMap(); grouped.forEach((key, value) -> phraseVector.put(value.getAny(), value.size())); return phraseVector.toImmutable(); diff --git a/stages/text-preprocessing/src/main/java/edu/kit/kastel/mcse/ardoco/core/text/providers/informants/corenlp/WordImpl.java b/stages/text-preprocessing/src/main/java/edu/kit/kastel/mcse/ardoco/core/text/providers/informants/corenlp/WordImpl.java index 02d4cf1d9..02f20726e 100644 --- a/stages/text-preprocessing/src/main/java/edu/kit/kastel/mcse/ardoco/core/text/providers/informants/corenlp/WordImpl.java +++ b/stages/text-preprocessing/src/main/java/edu/kit/kastel/mcse/ardoco/core/text/providers/informants/corenlp/WordImpl.java @@ -179,4 +179,16 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(getPosition(), getPosTag(), getText(), getSentenceNo()); } + + @Override + public int compareTo(Word o) { + if (this.equals(o)) + return 0; + + int compareSentences = Integer.compare(this.getSentenceNo(), o.getSentenceNo()); + if (compareSentences != 0) { + return compareSentences; + } + return Integer.compare(this.getPosition(), o.getPosition()); + } } diff --git a/tests/tests-base/src/main/java/edu/kit/kastel/mcse/ardoco/core/tests/TestUtil.java b/tests/tests-base/src/main/java/edu/kit/kastel/mcse/ardoco/core/tests/TestUtil.java index b535c3ac9..77f035686 100644 --- a/tests/tests-base/src/main/java/edu/kit/kastel/mcse/ardoco/core/tests/TestUtil.java +++ b/tests/tests-base/src/main/java/edu/kit/kastel/mcse/ardoco/core/tests/TestUtil.java @@ -1,7 +1,6 @@ /* Licensed under MIT 2021-2023. */ package edu.kit.kastel.mcse.ardoco.core.tests; -import java.util.HashSet; import java.util.Locale; import java.util.Set; import java.util.stream.Collectors; @@ -35,8 +34,8 @@ private TestUtil() { */ public static EvaluationResults compareTLR(ArDoCoResult arDoCoResult, ImmutableCollection results, ImmutableCollection goldStandard) { - Set distinctTraceLinks = new HashSet<>(results.castToCollection()); - Set distinctGoldStandard = new HashSet<>(goldStandard.castToCollection()); + Set distinctTraceLinks = new java.util.LinkedHashSet<>(results.castToCollection()); + Set distinctGoldStandard = new java.util.LinkedHashSet<>(goldStandard.castToCollection()); // True Positives are the trace links that are contained on both lists Set truePositives = distinctTraceLinks.stream().filter(distinctGoldStandard::contains).collect(Collectors.toSet()); @@ -65,8 +64,8 @@ public static EvaluationResults compareTLR(ArDoCoResult arDoCoResult, Imm public static EvaluationResults compareInconsistencies(ArDoCoResult arDoCoResult, ImmutableCollection results, ImmutableCollection goldStandard) { - Set distinctTraceLinks = new HashSet<>(results.castToCollection()); - Set distinctGoldStandard = new HashSet<>(goldStandard.castToCollection()); + Set distinctTraceLinks = new java.util.LinkedHashSet<>(results.castToCollection()); + Set distinctGoldStandard = new java.util.LinkedHashSet<>(goldStandard.castToCollection()); // True Positives are the trace links that are contained on both lists Set truePositives = distinctTraceLinks.stream().filter(distinctGoldStandard::contains).collect(Collectors.toSet()); diff --git a/tests/tests-base/src/main/java/edu/kit/kastel/mcse/ardoco/core/tests/eval/Project.java b/tests/tests-base/src/main/java/edu/kit/kastel/mcse/ardoco/core/tests/eval/Project.java index f17511c28..695cc5f97 100644 --- a/tests/tests-base/src/main/java/edu/kit/kastel/mcse/ardoco/core/tests/eval/Project.java +++ b/tests/tests-base/src/main/java/edu/kit/kastel/mcse/ardoco/core/tests/eval/Project.java @@ -6,8 +6,8 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; -import java.util.Map; import java.util.Optional; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.ImmutableList; @@ -178,7 +178,7 @@ public File getTextFile() { * * @return the map of additional configuration options */ - public Map getAdditionalConfigurations() { + public SortedMap getAdditionalConfigurations() { return ConfigurationHelper.loadAdditionalConfigs(getAdditionalConfigurationsFile()); } diff --git a/tests/tests-inconsistency/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/eval/baseline/InconsistencyBaselineInformant.java b/tests/tests-inconsistency/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/eval/baseline/InconsistencyBaselineInformant.java index 803952ed0..16ff6f26d 100644 --- a/tests/tests-inconsistency/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/eval/baseline/InconsistencyBaselineInformant.java +++ b/tests/tests-inconsistency/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/eval/baseline/InconsistencyBaselineInformant.java @@ -1,7 +1,7 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.tests.eval.baseline; -import java.util.Map; +import java.util.SortedMap; import org.eclipse.collections.api.factory.Sets; import org.eclipse.collections.api.set.MutableSet; @@ -51,7 +51,7 @@ public void run() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map map) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap map) { // empty } } diff --git a/tests/tests-inconsistency/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/inconsistencyhelper/HoldBackRunResultsProducer.java b/tests/tests-inconsistency/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/inconsistencyhelper/HoldBackRunResultsProducer.java index bccdb5834..cb2f70f64 100644 --- a/tests/tests-inconsistency/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/inconsistencyhelper/HoldBackRunResultsProducer.java +++ b/tests/tests-inconsistency/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/inconsistencyhelper/HoldBackRunResultsProducer.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; +import java.util.SortedMap; import org.junit.jupiter.api.Assertions; @@ -131,7 +132,7 @@ private static ArDoCo defineArDoCoWithPreComputedData(ArDoCoResult precomputedRe } private static void addMiddleSteps(HoldElementsBackModelConnector holdElementsBackModelConnector, ArDoCo arDoCo, DataRepository dataRepository, - Map additionalConfigs) { + SortedMap additionalConfigs) { arDoCo.addPipelineStep(new ModelProviderInformant(dataRepository, holdElementsBackModelConnector)); arDoCo.addPipelineStep(TextExtraction.get(additionalConfigs, dataRepository)); arDoCo.addPipelineStep(RecommendationGenerator.get(additionalConfigs, dataRepository)); diff --git a/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/ConfigurationTest.java b/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/ConfigurationTest.java index acd8dc8d0..b2ed87110 100644 --- a/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/ConfigurationTest.java +++ b/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/ConfigurationTest.java @@ -1,7 +1,10 @@ /* Licensed under MIT 2022-2023. */ package edu.kit.kastel.mcse.ardoco.core.tests; -import java.util.*; +import java.util.List; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -44,7 +47,7 @@ public void testValidityOfConfigurableFields() throws Exception { @Test void testBasicConfigurable() throws Exception { - Map configs = new TreeMap<>(); + SortedMap configs = new TreeMap<>(); processConfigurationOfClass(configs, TestConfigurable.class); Assertions.assertEquals(5, configs.size()); @@ -62,7 +65,7 @@ void testBasicConfigurable() throws Exception { Assertions.assertEquals(TestConfigurable.MyEnum.B, t.testEnumNo); //@formatter:off - configs = Map.of(// + configs = new TreeMap<>(Map.of(// TestConfigurable.class.getSimpleName() + AbstractConfigurable.CLASS_ATTRIBUTE_CONNECTOR + "testInt", "42", // TestConfigurable.class.getSimpleName() + AbstractConfigurable.CLASS_ATTRIBUTE_CONNECTOR + "testIntNo", "42", // TestConfigurable.class.getSimpleName() + AbstractConfigurable.CLASS_ATTRIBUTE_CONNECTOR + "testDouble", "48", // @@ -74,7 +77,7 @@ void testBasicConfigurable() throws Exception { TestConfigurable.class.getSimpleName() + AbstractConfigurable.CLASS_ATTRIBUTE_CONNECTOR + "testEnum", TestConfigurable.MyEnum.C.name(), // TestConfigurable.class.getSimpleName() + AbstractConfigurable.CLASS_ATTRIBUTE_CONNECTOR + "testEnumNo", TestConfigurable.MyEnum.C.name() - ); + )); //@formatter:on t.applyConfiguration(configs); @@ -115,7 +118,7 @@ public TestConfigurable() { } @Override - protected void delegateApplyConfigurationToInternalObjects(Map additionalConfiguration) { + protected void delegateApplyConfigurationToInternalObjects(SortedMap additionalConfiguration) { } private enum MyEnum { diff --git a/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/architecture/DeterministicArDoCoTest.java b/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/architecture/DeterministicArDoCoTest.java new file mode 100644 index 000000000..201c21e72 --- /dev/null +++ b/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/architecture/DeterministicArDoCoTest.java @@ -0,0 +1,276 @@ +/* Licensed under MIT 2023. */ +package edu.kit.kastel.mcse.ardoco.core.tests.architecture; + +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.fields; +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods; +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; + +import java.lang.annotation.Annotation; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.SortedMap; +import java.util.SortedSet; + +import org.eclipse.collections.api.factory.Maps; +import org.eclipse.collections.api.factory.Sets; +import org.eclipse.collections.api.map.ImmutableMap; +import org.eclipse.collections.api.map.MutableMap; +import org.eclipse.collections.api.map.sorted.ImmutableSortedMap; +import org.eclipse.collections.api.map.sorted.MutableSortedMap; +import org.eclipse.collections.api.set.ImmutableSet; +import org.eclipse.collections.api.set.MutableSet; +import org.eclipse.collections.api.set.sorted.ImmutableSortedSet; +import org.eclipse.collections.api.set.sorted.MutableSortedSet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.tngtech.archunit.base.DescribedPredicate; +import com.tngtech.archunit.core.domain.JavaClass; +import com.tngtech.archunit.core.domain.JavaField; +import com.tngtech.archunit.core.domain.JavaMethod; +import com.tngtech.archunit.core.domain.JavaParameterizedType; +import com.tngtech.archunit.core.domain.JavaWildcardType; +import com.tngtech.archunit.junit.AnalyzeClasses; +import com.tngtech.archunit.junit.ArchTest; +import com.tngtech.archunit.lang.ArchCondition; +import com.tngtech.archunit.lang.ArchRule; +import com.tngtech.archunit.lang.ConditionEvents; +import com.tngtech.archunit.lang.SimpleConditionEvent; + +import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic; +import edu.kit.kastel.mcse.ardoco.core.architecture.NoHashCodeEquals; + +@AnalyzeClasses(packages = "edu.kit.kastel.mcse.ardoco.core") +public class DeterministicArDoCoTest { + + private static final Logger logger = LoggerFactory.getLogger(DeterministicArDoCoTest.class); + + @ArchTest + public static final ArchRule forbidUnorderedSetsAndMaps = noClasses().that() + .resideOutsideOfPackages("..tests..") + .and(areNotDirectlyAnnotatedWith(Deterministic.class)) + .should() + .accessClassesThat(areForbiddenClasses()) + .orShould() + .dependOnClassesThat(areForbiddenClasses()); + + private static DescribedPredicate areNotDirectlyAnnotatedWith(Class targetAnnotation) { + return new DescribedPredicate<>("not directly annotated with " + targetAnnotation.getName()) { + @Override + public boolean test(JavaClass javaClass) { + var annotations = javaClass.getAnnotations(); + for (var annotation : annotations) { + if (annotation.getRawType().getFullName().equals(targetAnnotation.getName())) { + return false; + } + } + return true; + } + }; + } + + private static DescribedPredicate areForbiddenClasses() { + Set> forbiddenClasses = Set.of(Set.class, HashSet.class, MutableSet.class, ImmutableSet.class, Sets.class, // + Map.class, HashMap.class, MutableMap.class, ImmutableMap.class, Maps.class // + ); + return new DescribedPredicate<>("forbidden classes") { + @Override + public boolean test(JavaClass javaClass) { + return forbiddenClasses.stream().map(Class::getName).anyMatch(it -> it.equals(javaClass.getFullName())); + } + }; + } + + @ArchTest + public static final ArchRule forbidHashMapAndHashSetInFavorOfLinkedVersions = noClasses().that() + .doNotHaveFullyQualifiedName(DeterministicArDoCoTest.class.getName()) + .should() + .accessClassesThat() + .haveNameMatching(HashMap.class.getName() + "|" + HashSet.class.getName()) + .orShould() + .dependOnClassesThat() + .haveNameMatching(HashMap.class.getName() + "|" + HashSet.class.getName()); + + @ArchTest + public static final ArchRule forbidEqualsAndHashCodeInCertainClasses = noClasses().that() + .areAnnotatedWith(NoHashCodeEquals.class) + .should(implementEqualsOrHashCode()); + + private static ArchCondition implementEqualsOrHashCode() { + return new ArchCondition<>("implement equals or hashCode") { + @Override + public void check(JavaClass javaClass, ConditionEvents conditionEvents) { + var methods = javaClass.getAllMethods(); + for (var method : methods) { + if (!method.getFullName().contains(javaClass.getFullName())) + continue; + if (method.getName().equals("hashCode") || method.getName().equals("equals")) { + satisfied(conditionEvents, javaClass, "Class " + javaClass.getName() + " implements " + method.getFullName()); + } + } + } + }; + } + + @ArchTest + public static final ArchRule ensureContractBetweenEqualsHashCodeAndCompareTo = classes().that(directlyImplement(Comparable.class)) + .and() + .areNotEnums() + .and() + .areNotInterfaces() + .and() + .areNotAnonymousClasses() // e.g., type references for jackson + .should(implementEqualsAndHashCode()); + + private static DescribedPredicate directlyImplement(Class targetClass) { + return new DescribedPredicate<>("directly implement " + targetClass.getName()) { + @Override + public boolean test(JavaClass javaClass) { + var directInterfaces = javaClass.getRawInterfaces(); + for (var di : directInterfaces) { + if (di.getName().equals(targetClass.getName())) { + return true; + } + } + return false; + } + }; + } + + private static ArchCondition implementEqualsAndHashCode() { + return new ArchCondition<>("implement equals or hashCode") { + @Override + public void check(JavaClass javaClass, ConditionEvents conditionEvents) { + var methods = javaClass.getAllMethods(); + boolean equals = false; + boolean hashCode = false; + for (var method : methods) { + if (!method.getFullName().contains(javaClass.getFullName())) + continue; + + if (method.getName().equals("hashCode")) { + hashCode = true; + } else if (method.getName().equals("equals")) { + equals = true; + } + } + + if (equals && hashCode) { + satisfied(conditionEvents, javaClass, "Class " + javaClass.getName() + " implements equals and hashCode"); + } else if (equals) { + violated(conditionEvents, javaClass, "Class " + javaClass.getName() + " implements equals but not hashCode"); + } else if (hashCode) { + violated(conditionEvents, javaClass, "Class " + javaClass.getName() + " implements hashCode but not equals"); + } else { + violated(conditionEvents, javaClass, "Class " + javaClass.getName() + " implements neither equals nor hashCode"); + } + } + }; + } + + @ArchTest + public static final ArchRule ensureSortedCollectionsOnlyForComparableTypes = fields().that() + .haveRawType(SortedMap.class) + .or() + .haveRawType(ImmutableSortedMap.class) + .or() + .haveRawType(MutableSortedMap.class) + .or() + .haveRawType(SortedSet.class) + .or() + .haveRawType(ImmutableSortedSet.class) + .or() + .haveRawType(MutableSortedSet.class) + .should(haveComparableGenericType()); + + @ArchTest + public static final ArchRule ensureSortedCollectionsOnlyForComparableTypesInReturn = methods().that() + .haveRawReturnType(SortedSet.class) + .or() + .haveRawReturnType(ImmutableSortedSet.class) + .or() + .haveRawReturnType(MutableSortedSet.class) + .should(haveComparableReturn()); + + @ArchTest + public static final ArchRule ensureSortedMapOnlyForComparableTypesInReturn = methods().that() + .haveRawReturnType(SortedMap.class) + .or() + .haveRawReturnType(ImmutableSortedMap.class) + .or() + .haveRawReturnType(MutableSortedMap.class) + .should(haveComparableReturn()); + + private static ArchCondition haveComparableGenericType() { + return new ArchCondition<>("have Comparable generic type") { + @Override + public void check(JavaField javaField, ConditionEvents conditionEvents) { + var type = javaField.getType(); + if (type instanceof JavaParameterizedType parameterizedType) { + var typeParameter = parameterizedType.getActualTypeArguments().get(0); + if ((typeParameter instanceof JavaClass typeParameterClass) && typeParameterClass.getAllRawInterfaces() + .stream() + .anyMatch(i -> i.getFullName().equals(Comparable.class.getName()))) { + + satisfied(conditionEvents, javaField, "Field " + javaField.getFullName() + " has a Comparable generic type"); + } else { + violated(conditionEvents, javaField, "Field " + javaField.getFullName() + " has a non-Comparable generic type"); + } + } else if (type instanceof JavaClass) { + // Classes generated from lambdas cannot be checked :( + logger.debug("Skipping field {}", javaField.getFullName()); + } else { + violated(conditionEvents, javaField, "Field " + javaField.getFullName() + " is not a parameterized type"); + } + } + }; + } + + private static ArchCondition haveComparableReturn() { + return new ArchCondition<>("have Comparable generic type") { + @Override + public void check(JavaMethod javaMethod, ConditionEvents conditionEvents) { + var type = javaMethod.getReturnType(); + if (!(type instanceof JavaParameterizedType parameterizedType)) { + violated(conditionEvents, javaMethod, "Method " + javaMethod.getFullName() + " is not a parameterized type"); + return; + } + + var typeParameter = parameterizedType.getActualTypeArguments().get(0); + if ((typeParameter instanceof JavaClass typeParameterClass) && typeParameterClass.getAllRawInterfaces() + .stream() + .anyMatch(i -> i.getFullName().equals(Comparable.class.getName()))) { + + satisfied(conditionEvents, javaMethod, "Method " + javaMethod.getFullName() + " has a Comparable generic type"); + } else if ((typeParameter instanceof JavaWildcardType typeParameterWildCard)) { + var upperBound = typeParameterWildCard.getUpperBounds().get(0); + + if (!(upperBound instanceof JavaClass upperBoundClass) || upperBoundClass.getAllRawInterfaces() + .stream() + .noneMatch(i -> i.getFullName().equals(Comparable.class.getName()))) { + violated(conditionEvents, javaMethod, "Method " + javaMethod.getFullName() + " has a non-Comparable generic type"); + return; + } + + satisfied(conditionEvents, javaMethod, "Method " + javaMethod.getFullName() + " has a Comparable generic type"); + } else { + violated(conditionEvents, javaMethod, "Method " + javaMethod.getFullName() + " has a non-Comparable generic type"); + } + } + }; + } + + private static void satisfied(ConditionEvents events, Object location, String message) { + var event = new SimpleConditionEvent(location, true, message); + events.add(event); + } + + private static void violated(ConditionEvents events, Object location, String message) { + var event = new SimpleConditionEvent(location, false, message); + events.add(event); + } + +} diff --git a/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/statehelper/ChangedStatesTest.java b/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/statehelper/ChangedStatesTest.java index a286ff2a8..db868a80d 100644 --- a/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/statehelper/ChangedStatesTest.java +++ b/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/statehelper/ChangedStatesTest.java @@ -6,8 +6,9 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; +import java.util.TreeMap; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assumptions; @@ -35,7 +36,7 @@ public class ChangedStatesTest { private static final String OUTPUT = "src/test/resources/testout"; private static final Path OUTPUT_PATH = Path.of(OUTPUT); - private static final Map DATA_MAP = new HashMap<>(); + private static final Map DATA_MAP = new LinkedHashMap<>(); private static final String LOGGING_ARDOCO_CORE = "org.slf4j.simpleLogger.log.edu.kit.kastel.mcse.ardoco.core"; @BeforeAll @@ -60,7 +61,7 @@ static void evaluateStates() throws IOException { private static ArDoCoResult getArDoCoResult(String name, File inputText, File inputModel) { var runner = new ArDoCoForInconsistencyDetection(name); - runner.setUp(inputText, inputModel, ArchitectureModelType.PCM, Map.of(), new File(OUTPUT)); + runner.setUp(inputText, inputModel, ArchitectureModelType.PCM, new TreeMap<>(), new File(OUTPUT)); return runner.run(); } diff --git a/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/statehelper/files/ConnectionStateFile.java b/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/statehelper/files/ConnectionStateFile.java index 1c6386b90..54f486ca3 100644 --- a/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/statehelper/files/ConnectionStateFile.java +++ b/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/statehelper/files/ConnectionStateFile.java @@ -14,7 +14,7 @@ import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.list.MutableList; -import org.eclipse.collections.api.set.ImmutableSet; +import org.eclipse.collections.api.set.sorted.ImmutableSortedSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -150,7 +150,7 @@ public static boolean writeDiff(Path sourceFile, Path targetFile, Path diffFile, ImmutableList names = currentTextInstance.getNameMappings().collect(NounMapping::getReference).toSet().toImmutableList(); ImmutableList types = currentTextInstance.getTypeMappings().collect(NounMapping::getReference).toSet().toImmutableList(); String probability = df.format(currentTextInstance.getProbability()); - ImmutableSet claimants = currentTextInstance.getClaimants().collect(c -> c.getClass().getSimpleName()); + ImmutableSortedSet claimants = currentTextInstance.getClaimants().collect(c -> c.getClass().getSimpleName()).toImmutableSortedSet(); String currentModelLine = String.join(VALUE_SEPARATOR, uid, modelName, modelType); String currentLinkLine = String.join(VALUE_SEPARATOR, linkProbability, String.join(LIST_SEPARATOR, sentences), name, type, String.join( diff --git a/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/statehelper/files/RecommendationStateFile.java b/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/statehelper/files/RecommendationStateFile.java index 5f96947e9..65e04f2be 100644 --- a/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/statehelper/files/RecommendationStateFile.java +++ b/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/statehelper/files/RecommendationStateFile.java @@ -14,7 +14,7 @@ import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.list.MutableList; -import org.eclipse.collections.api.set.ImmutableSet; +import org.eclipse.collections.api.set.sorted.ImmutableSortedSet; import edu.kit.kastel.mcse.ardoco.core.api.models.Metamodel; import edu.kit.kastel.mcse.ardoco.core.api.output.ArDoCoResult; @@ -132,7 +132,9 @@ public static boolean writeDiff(Path sourceFile, Path targetFile, Path diffFile, .toSortedList() .collect(no -> Integer.toString(no)) .toImmutable(); - ImmutableSet claimants = currentRecommendedInstance.getClaimants().collect(c -> c.getClass().getSimpleName()); + ImmutableSortedSet claimants = currentRecommendedInstance.getClaimants() + .collect(c -> c.getClass().getSimpleName()) + .toImmutableSortedSet(); String currentLine = String.join(VALUE_SEPARATOR, name, type, probability, String.join(LIST_SEPARATOR, names), String.join(LIST_SEPARATOR, types), String.join(LIST_SEPARATOR, sentences), String.join(LIST_SEPARATOR, claimants)); diff --git a/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/statehelper/files/TextStateFile.java b/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/statehelper/files/TextStateFile.java index 89c2b19dd..1c9e34f07 100644 --- a/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/statehelper/files/TextStateFile.java +++ b/tests/tests-misc/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/statehelper/files/TextStateFile.java @@ -15,7 +15,7 @@ import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.list.MutableList; -import org.eclipse.collections.api.set.ImmutableSet; +import org.eclipse.collections.api.set.sorted.ImmutableSortedSet; import edu.kit.kastel.mcse.ardoco.core.api.output.ArDoCoResult; import edu.kit.kastel.mcse.ardoco.core.api.text.Word; @@ -124,7 +124,7 @@ public static boolean writeDiff(Path sourceFile, Path targetFile, Path diffFile, .toSortedList() .collect(no -> Integer.toString(no)) .toImmutable(); - ImmutableSet claimants = currentNounMapping.getClaimants().collect(c -> c.getClass().getSimpleName()); + ImmutableSortedSet claimants = currentNounMapping.getClaimants().collect(c -> c.getClass().getSimpleName()).toImmutableSortedSet(); String currentLine = String.join(VALUE_SEPARATOR, ref, nameProb, typeProb, surfaceForms, String.join(LIST_SEPARATOR, words), String.join( LIST_SEPARATOR, sentences), String.join(LIST_SEPARATOR, claimants)); diff --git a/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/SadCodeTraceabilityLinkRecoveryEvaluation.java b/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/SadCodeTraceabilityLinkRecoveryEvaluation.java index a8db0ac77..b14a825a0 100644 --- a/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/SadCodeTraceabilityLinkRecoveryEvaluation.java +++ b/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/SadCodeTraceabilityLinkRecoveryEvaluation.java @@ -4,8 +4,8 @@ import static edu.kit.kastel.mcse.ardoco.core.tests.integration.TraceLinkEvaluationIT.OUTPUT; import java.io.File; -import java.util.HashMap; -import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.ImmutableList; @@ -41,7 +41,7 @@ protected ArDoCoRunner getAndSetupRunner(CodeProject codeProject) { File textInput = textProject.getTextFile(); File inputArchitectureModel = codeProject.getProject().getModelFile(); File inputCode = getInputCode(codeProject); - Map additionalConfigsMap = new HashMap<>(); + SortedMap additionalConfigsMap = new TreeMap<>(); File outputDir = new File(OUTPUT); var runner = new ArDoCoForSadCodeTraceabilityLinkRecovery(name); diff --git a/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/SadSamCodeTraceabilityLinkRecoveryEvaluation.java b/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/SadSamCodeTraceabilityLinkRecoveryEvaluation.java index 1b3f35a55..e4dc071e4 100644 --- a/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/SadSamCodeTraceabilityLinkRecoveryEvaluation.java +++ b/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/SadSamCodeTraceabilityLinkRecoveryEvaluation.java @@ -4,8 +4,8 @@ import static edu.kit.kastel.mcse.ardoco.core.tests.integration.TraceLinkEvaluationIT.OUTPUT; import java.io.File; -import java.util.HashMap; -import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.ImmutableList; @@ -40,7 +40,7 @@ protected ArDoCoRunner getAndSetupRunner(CodeProject codeProject) { File textInput = textProject.getTextFile(); File inputArchitectureModel = codeProject.getProject().getModelFile(); File inputCode = getInputCode(codeProject); - Map additionalConfigsMap = new HashMap<>(); + SortedMap additionalConfigsMap = new TreeMap<>(); File outputDir = new File(OUTPUT); var runner = new ArDoCoForSadSamCodeTraceabilityLinkRecovery(name); diff --git a/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/SadSamTraceabilityLinkRecoveryEvaluation.java b/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/SadSamTraceabilityLinkRecoveryEvaluation.java index 38d977b41..76b4b98ee 100644 --- a/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/SadSamTraceabilityLinkRecoveryEvaluation.java +++ b/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/SadSamTraceabilityLinkRecoveryEvaluation.java @@ -1,7 +1,10 @@ /* Licensed under MIT 2021-2023. */ package edu.kit.kastel.mcse.ardoco.core.tests.integration; -import static edu.kit.kastel.mcse.ardoco.core.tests.integration.TraceLinkEvaluationIT.*; +import static edu.kit.kastel.mcse.ardoco.core.tests.integration.TraceLinkEvaluationIT.DATA_MAP; +import static edu.kit.kastel.mcse.ardoco.core.tests.integration.TraceLinkEvaluationIT.OUTPUT; +import static edu.kit.kastel.mcse.ardoco.core.tests.integration.TraceLinkEvaluationIT.PROJECT_RESULTS; +import static edu.kit.kastel.mcse.ardoco.core.tests.integration.TraceLinkEvaluationIT.RESULTS; import java.io.File; import java.io.IOException; diff --git a/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/SamCodeTraceabilityLinkRecoveryEvaluation.java b/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/SamCodeTraceabilityLinkRecoveryEvaluation.java index bec05dbb9..3e6a3e36d 100644 --- a/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/SamCodeTraceabilityLinkRecoveryEvaluation.java +++ b/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/SamCodeTraceabilityLinkRecoveryEvaluation.java @@ -4,8 +4,8 @@ import static edu.kit.kastel.mcse.ardoco.core.tests.integration.TraceLinkEvaluationIT.OUTPUT; import java.io.File; -import java.util.HashMap; -import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.ImmutableList; @@ -34,7 +34,7 @@ protected ArDoCoForSamCodeTraceabilityLinkRecovery getAndSetupRunner(CodeProject String name = codeProject.name().toLowerCase(); File inputCode = getInputCode(codeProject); File inputArchitectureModel = codeProject.getProject().getModelFile(); - Map additionalConfigsMap = new HashMap<>(); + SortedMap additionalConfigsMap = new TreeMap<>(); File outputDir = new File(OUTPUT); var runner = new ArDoCoForSamCodeTraceabilityLinkRecovery(name); diff --git a/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/TraceLinkEvaluationIT.java b/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/TraceLinkEvaluationIT.java index 7ab02d555..910c97a06 100644 --- a/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/TraceLinkEvaluationIT.java +++ b/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/TraceLinkEvaluationIT.java @@ -18,7 +18,14 @@ import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.tuple.Pair; -import org.junit.jupiter.api.*; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; diff --git a/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/TraceabilityLinkRecoveryEvaluation.java b/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/TraceabilityLinkRecoveryEvaluation.java index c0d5db99c..01b476492 100644 --- a/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/TraceabilityLinkRecoveryEvaluation.java +++ b/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/TraceabilityLinkRecoveryEvaluation.java @@ -3,7 +3,7 @@ import java.io.File; import java.util.EnumMap; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; @@ -159,8 +159,8 @@ protected EvaluationResults calculateEvaluationResults(ArDoCoResult arDo ImmutableList results = createTraceLinkStringList(arDoCoResult); Assertions.assertFalse(results.isEmpty()); - Set distinctTraceLinks = new HashSet<>(results.castToCollection()); - Set distinctGoldStandard = new HashSet<>(goldStandard.castToCollection()); + Set distinctTraceLinks = new LinkedHashSet<>(results.castToCollection()); + Set distinctGoldStandard = new LinkedHashSet<>(goldStandard.castToCollection()); // True Positives are the trace links that are contained on both lists Set truePositives = distinctTraceLinks.stream() diff --git a/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/tlrhelper/files/TLDiffFile.java b/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/tlrhelper/files/TLDiffFile.java index 3eac1c3b5..561f1d089 100644 --- a/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/tlrhelper/files/TLDiffFile.java +++ b/tests/tests-tlr/src/test/java/edu/kit/kastel/mcse/ardoco/core/tests/integration/tlrhelper/files/TLDiffFile.java @@ -6,7 +6,10 @@ import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.text.DecimalFormat; -import java.util.*; +import java.util.Collection; +import java.util.Comparator; +import java.util.List; +import java.util.Map; import org.eclipse.collections.api.tuple.Pair;