Skip to content

Commit

Permalink
InstanceLinks are TraceLinks
Browse files Browse the repository at this point in the history
  • Loading branch information
dfuchss committed Dec 9, 2024
1 parent 5a4c627 commit 86861eb
Showing 1 changed file with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import edu.kit.kastel.mcse.ardoco.core.api.stage.connectiongenerator.ConnectionState;
import edu.kit.kastel.mcse.ardoco.core.api.stage.connectiongenerator.InstanceLink;
import edu.kit.kastel.mcse.ardoco.core.api.stage.recommendationgenerator.RecommendedInstance;
import edu.kit.kastel.mcse.ardoco.core.api.tracelink.TraceLink;
import edu.kit.kastel.mcse.ardoco.core.data.AbstractState;
import edu.kit.kastel.mcse.ardoco.core.pipeline.agent.Claimant;

Expand All @@ -18,14 +19,14 @@
*/
public class ConnectionStateImpl extends AbstractState implements ConnectionState {

private MutableList<InstanceLink> instanceLinks;
private MutableList<TraceLink<RecommendedInstance, ModelInstance>> instanceLinks;

/**
* Creates a new connection state.
*/
public ConnectionStateImpl() {
super();
instanceLinks = Lists.mutable.empty();
this.instanceLinks = Lists.mutable.empty();
}

/**
Expand All @@ -34,8 +35,8 @@ public ConnectionStateImpl() {
* @return all instance links
*/
@Override
public ImmutableList<InstanceLink> getInstanceLinks() {
return Lists.immutable.withAll(instanceLinks);
public ImmutableList<TraceLink<RecommendedInstance, ModelInstance>> getInstanceLinks() {
return Lists.immutable.withAll(this.instanceLinks);
}

/**
Expand All @@ -45,8 +46,8 @@ public ImmutableList<InstanceLink> getInstanceLinks() {
* @return all instance links with a model instance containing the given name as list
*/
@Override
public ImmutableList<InstanceLink> getInstanceLinksByName(String name) {
return Lists.immutable.fromStream(instanceLinks.stream().filter(imapping -> imapping.getModelInstance().getNameParts().contains(name)));
public ImmutableList<TraceLink<RecommendedInstance, ModelInstance>> getInstanceLinksByName(String name) {
return Lists.immutable.fromStream(this.instanceLinks.stream().filter(imapping -> imapping.getSecondEndpoint().getNameParts().contains(name)));
}

/**
Expand All @@ -56,13 +57,13 @@ public ImmutableList<InstanceLink> getInstanceLinksByName(String name) {
* @return all instance links with a model instance containing the given type as list
*/
@Override
public ImmutableList<InstanceLink> getInstanceLinksByType(String type) {
return Lists.immutable.fromStream(instanceLinks.stream().filter(ilink -> ilink.getModelInstance().getTypeParts().contains(type)));
public ImmutableList<TraceLink<RecommendedInstance, ModelInstance>> getInstanceLinksByType(String type) {
return Lists.immutable.fromStream(this.instanceLinks.stream().filter(ilink -> ilink.getSecondEndpoint().getTypeParts().contains(type)));
}

@Override
public ImmutableList<InstanceLink> getInstanceLinksByRecommendedInstance(RecommendedInstance recommendedInstance) {
return Lists.immutable.fromStream(instanceLinks.stream().filter(il -> il.getTextualInstance().equals(recommendedInstance)));
public ImmutableList<TraceLink<RecommendedInstance, ModelInstance>> getInstanceLinksByRecommendedInstance(RecommendedInstance recommendedInstance) {
return Lists.immutable.fromStream(this.instanceLinks.stream().filter(il -> il.getFirstEndpoint().equals(recommendedInstance)));
}

/**
Expand All @@ -73,10 +74,10 @@ public ImmutableList<InstanceLink> getInstanceLinksByRecommendedInstance(Recomme
* @return all instance links with a model instance containing the given name and type as list
*/
@Override
public ImmutableList<InstanceLink> getInstanceLinks(String name, String type) {
return Lists.immutable.fromStream(instanceLinks.stream()
.filter(imapping -> imapping.getModelInstance().getNameParts().contains(name))//
.filter(imapping -> imapping.getModelInstance().getTypeParts().contains(type)));
public ImmutableList<TraceLink<RecommendedInstance, ModelInstance>> getInstanceLinks(String name, String type) {
return Lists.immutable.fromStream(this.instanceLinks.stream()
.filter(imapping -> imapping.getSecondEndpoint().getNameParts().contains(name))//
.filter(imapping -> imapping.getSecondEndpoint().getTypeParts().contains(type)));
}

/**
Expand All @@ -91,15 +92,15 @@ public ImmutableList<InstanceLink> getInstanceLinks(String name, String type) {
public void addToLinks(RecommendedInstance recommendedModelInstance, ModelInstance instance, Claimant claimant, double probability) {

var newInstanceLink = new InstanceLink(recommendedModelInstance, instance, claimant, probability);
if (!isContainedByInstanceLinks(newInstanceLink)) {
instanceLinks.add(newInstanceLink);
if (!this.isContainedByInstanceLinks(newInstanceLink)) {
this.instanceLinks.add(newInstanceLink);
} else {
var optionalInstanceLink = instanceLinks.stream().filter(il -> il.equals(newInstanceLink)).findFirst();
var optionalInstanceLink = this.instanceLinks.stream().filter(il -> il.equals(newInstanceLink)).findFirst();
if (optionalInstanceLink.isPresent()) {
var existingInstanceLink = optionalInstanceLink.get();
var newNameMappings = newInstanceLink.getTextualInstance().getNameMappings();
var newTypeMappings = newInstanceLink.getTextualInstance().getTypeMappings();
existingInstanceLink.getTextualInstance().addMappings(newNameMappings, newTypeMappings);
var newNameMappings = newInstanceLink.getFirstEndpoint().getNameMappings();
var newTypeMappings = newInstanceLink.getFirstEndpoint().getTypeMappings();
existingInstanceLink.getFirstEndpoint().addMappings(newNameMappings, newTypeMappings);
}
}
}
Expand All @@ -111,8 +112,8 @@ public void addToLinks(RecommendedInstance recommendedModelInstance, ModelInstan
* @return true if it is already contained
*/
@Override
public boolean isContainedByInstanceLinks(InstanceLink instanceLink) {
return instanceLinks.contains(instanceLink);
public boolean isContainedByInstanceLinks(TraceLink<RecommendedInstance, ModelInstance> instanceLink) {
return this.instanceLinks.contains(instanceLink);
}

/**
Expand All @@ -121,8 +122,8 @@ public boolean isContainedByInstanceLinks(InstanceLink instanceLink) {
* @param instanceMapping the instance link to remove
*/
@Override
public void removeFromMappings(InstanceLink instanceMapping) {
instanceLinks.remove(instanceMapping);
public void removeFromMappings(TraceLink<RecommendedInstance, ModelInstance> instanceMapping) {
this.instanceLinks.remove(instanceMapping);
}

/**
Expand All @@ -132,7 +133,7 @@ public void removeFromMappings(InstanceLink instanceMapping) {
*/
@Override
public void removeAllInstanceLinksWith(ModelInstance instance) {
instanceLinks.removeIf(mapping -> mapping.getModelInstance().equals(instance));
this.instanceLinks.removeIf(mapping -> mapping.getSecondEndpoint().equals(instance));
}

/**
Expand All @@ -142,7 +143,7 @@ public void removeAllInstanceLinksWith(ModelInstance instance) {
*/
@Override
public void removeAllInstanceLinksWith(RecommendedInstance instance) {
instanceLinks.removeIf(mapping -> mapping.getTextualInstance().equals(instance));
this.instanceLinks.removeIf(mapping -> mapping.getFirstEndpoint().equals(instance));
}

}

0 comments on commit 86861eb

Please sign in to comment.