diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/EMappingStrategy.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/EMappingStrategy.java new file mode 100644 index 0000000000000000000000000000000000000000..85760e681836d8c70a73ac24f11e32b7c80d20e5 --- /dev/null +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/EMappingStrategy.java @@ -0,0 +1,5 @@ +package org.oceandsl.tools.restructuring; + +public enum EMappingStrategy { + NORMAL, EMPTY, RANDOM, KUHN +} diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/LightTraceRestorator.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/LightTraceRestorator.java new file mode 100644 index 0000000000000000000000000000000000000000..11f468349badfc1b718a324fba0d25d4e7eaaa11 --- /dev/null +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/LightTraceRestorator.java @@ -0,0 +1,29 @@ +package org.oceandsl.tools.restructuring; + +import org.oceandsl.tools.restructuring.stages.exec.RestructureStepFinder; +import org.oceandsl.tools.restructuring.stages.exec.mapper.AbstractMapper; +import org.oceandsl.tools.restructuring.stages.exec.mapper.KuhnMatcherMapper; + +import kieker.model.analysismodel.assembly.AssemblyModel; + +public class LightTraceRestorator { + + private AssemblyModel original; + private AssemblyModel goal; + + public LightTraceRestorator(AssemblyModel original, AssemblyModel goal) { + this.original = original; + this.goal = goal; + } + + public int getNumSteps() { + // TODO find better names + AbstractMapper mapper = new KuhnMatcherMapper(original, goal, "original", "goal"); + + RestructureStepFinder stepfinder = new RestructureStepFinder(mapper); + stepfinder.findTransformation(); + + return stepfinder.getNumSteps(); + } + +} diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/MappingStrategyConverter.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/MappingStrategyConverter.java new file mode 100644 index 0000000000000000000000000000000000000000..2f41f76b49a10017cbe90892e2913cf3979e8f7f --- /dev/null +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/MappingStrategyConverter.java @@ -0,0 +1,14 @@ +package org.oceandsl.tools.restructuring; + +import java.util.Locale; + +import com.beust.jcommander.IStringConverter; + +public class MappingStrategyConverter implements IStringConverter<EMappingStrategy> { + + @Override + public EMappingStrategy convert(String value) { + return EMappingStrategy.valueOf(value.toLowerCase(Locale.getDefault())); + } + +} diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/RestructuringMain.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/RestructuringMain.java index b4b04f32b5800a9b5bb1c17ea5b96dc9b2328817..fedee8066d173086eeaab770e39c4c87b0c4b8d2 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/RestructuringMain.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/RestructuringMain.java @@ -1,6 +1,5 @@ package org.oceandsl.tools.restructuring; -import java.io.File; import java.io.IOException; import java.nio.file.Path; @@ -14,47 +13,45 @@ import kieker.tools.common.AbstractService; public class RestructuringMain extends AbstractService<TeetimeConfiguration, Settings> { - public static void main(final String[] args) { - final RestructuringMain main = new RestructuringMain(); - try { - final int exitCode = main.run("architecture model operations", "restructure", args, new Settings()); - System.exit(exitCode); - } catch (final IllegalArgumentException e) { - LoggerFactory.getLogger(RestructuringMain.class).error("Configuration error: {}", e.getLocalizedMessage()); - System.exit(1); - } - } - - @Override - protected TeetimeConfiguration createTeetimeConfiguration() throws ConfigurationException { - try { - return new TeetimeConfiguration(this.settings); - } catch (final IOException e) { - throw new ConfigurationException(e); - } - } - @Override + public static void main(final String[] args) { + final RestructuringMain main = new RestructuringMain(); + try { + final int exitCode = main.run("architecture model operations", "restructure", args, new Settings()); + System.exit(exitCode); + } catch (final IllegalArgumentException e) { + LoggerFactory.getLogger(RestructuringMain.class).error("Configuration error: {}", e.getLocalizedMessage()); + System.exit(1); + } + } + + @Override + protected TeetimeConfiguration createTeetimeConfiguration() throws ConfigurationException { + try { + return new TeetimeConfiguration(this.settings); + } catch (final IOException e) { + throw new ConfigurationException(e); + } + } + + @Override protected Path getConfigurationPath() { // TODO Auto-generated method stub return null; } + @Override + protected boolean checkConfiguration(final Configuration configuration, final JCommander commander) { + return true; + } + @Override + protected boolean checkParameters(final JCommander commander) throws ConfigurationException { + return true; + } - @Override - protected boolean checkConfiguration(final Configuration configuration, final JCommander commander) { - return true; - } - - @Override - protected boolean checkParameters(final JCommander commander) throws ConfigurationException { - - return true; - } - - @Override - protected void shutdownService() { - // No special operation necessary. - } + @Override + protected void shutdownService() { + // No special operation necessary. + } } \ No newline at end of file diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/Settings.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/Settings.java index 979aba426ca81648588e9752b1286bfc3e83131b..8572cd071b971d3567cbd0ad06c582853121010b 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/Settings.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/Settings.java @@ -25,8 +25,8 @@ public class Settings { // NOPMD data class @Parameter(names = { "-e", "--experiment" }, required = true, description = "Experiment name") private String experimentName; - @Parameter(names = { "-s", "--strat" }, required = true, description = "Strat name") - private String mappingStrat; + @Parameter(names = { "-s", "--strategy" }, required = true, converter =MappingStrategyConverter.class , description = "Strategy identifier") + private EMappingStrategy mappingStrat; public List<Path> getInputModelPaths() { return this.inputModelPaths; @@ -40,7 +40,7 @@ public class Settings { // NOPMD data class return this.experimentName; } - public String getMappingStrat() { + public EMappingStrategy getMappingStrat() { return this.mappingStrat; } diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/TeetimeConfiguration.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/TeetimeConfiguration.java index c96c13f28e28f6facd9902f070a3350c954e621b..185aa5a0c5b3cc49bb6ebe5c862b833b4596a8f1 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/TeetimeConfiguration.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/TeetimeConfiguration.java @@ -1,15 +1,16 @@ package org.oceandsl.tools.restructuring; -import java.io.IOException; -import teetime.framework.Configuration; +import java.io.IOException; import org.oceandsl.analysis.architecture.stages.ModelRepositoryReaderStage; - import org.oceandsl.analysis.architecture.stages.ModelSource; -import org.oceandsl.tools.restructuring.stages.Restructurer; -import org.oceandsl.tools.restructuring.stages.SinkStage; -import org.oceandsl.tools.restructuring.stages.TraceRestorator; +import org.oceandsl.analysis.generic.stages.TableCSVSink; +import org.oceandsl.tools.restructuring.stages.AggregateModelEditDistanceStage; +import org.oceandsl.tools.restructuring.stages.RestructureModelSinkStage; +import org.oceandsl.tools.restructuring.stages.RestructurerStage; +import org.oceandsl.tools.restructuring.stages.TraceRestoratorStage; +import teetime.framework.Configuration; /** * Pipe and Filter configuration for the architecture creation tool. @@ -19,23 +20,29 @@ import org.oceandsl.tools.restructuring.stages.TraceRestorator; */ public class TeetimeConfiguration extends Configuration { - public TeetimeConfiguration(final Settings parameterConfiguration) throws IOException { - - final ModelSource modelSource = new ModelSource(parameterConfiguration.getInputModelPaths()); - final ModelRepositoryReaderStage modelReader = new ModelRepositoryReaderStage(); - final TraceRestorator traceRestorator = new TraceRestorator(parameterConfiguration.getMappingStrat()); - final Restructurer restructurer = new Restructurer(); - final SinkStage modelSink = new SinkStage(parameterConfiguration.getOutputDirectory()); - - - - this.connectPorts(modelSource.getOutputPort(), modelReader.getInputPort()); - - this.connectPorts(modelReader.getOutputPort(), traceRestorator.getInputPort()); - - this.connectPorts(traceRestorator.getOutputPort(), restructurer.getInputPort()); - - this.connectPorts(restructurer.getStepsOutputPort(), modelSink.getInputPort()); // PlaceHolder - - } + private static final String MED_RESULT_FILE_NAME = "med-result-file.csv"; + + public TeetimeConfiguration(final Settings parameterConfiguration) throws IOException { + + final ModelSource modelSource = new ModelSource(parameterConfiguration.getInputModelPaths()); + final ModelRepositoryReaderStage modelReader = new ModelRepositoryReaderStage(); + final TraceRestoratorStage traceRestorator = new TraceRestoratorStage(parameterConfiguration.getMappingStrat()); + final RestructurerStage restructurer = new RestructurerStage(); + final RestructureModelSinkStage modelSink = new RestructureModelSinkStage( + parameterConfiguration.getOutputDirectory()); + AggregateModelEditDistanceStage aggregateStage = new AggregateModelEditDistanceStage(); + TableCSVSink medSinkStage = new TableCSVSink(parameterConfiguration.getOutputDirectory(), MED_RESULT_FILE_NAME, + true); + + this.connectPorts(modelSource.getOutputPort(), modelReader.getInputPort()); + + this.connectPorts(modelReader.getOutputPort(), traceRestorator.getInputPort()); + + this.connectPorts(traceRestorator.getOutputPort(), restructurer.getInputPort()); + + this.connectPorts(restructurer.getStepsOutputPort(), modelSink.getInputPort()); // PlaceHolder + + this.connectPorts(restructurer.getNumberOfStepsOutputPort(), aggregateStage.getInputPort()); + this.connectPorts(aggregateStage.getOutputPort(), medSinkStage.getInputPort()); + } } \ No newline at end of file diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/AggregateModelEditDistanceStage.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/AggregateModelEditDistanceStage.java new file mode 100644 index 0000000000000000000000000000000000000000..43715062ebdd3ab9f42a87d3ac3748846d222c5d --- /dev/null +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/AggregateModelEditDistanceStage.java @@ -0,0 +1,35 @@ +/** + * + */ +package org.oceandsl.tools.restructuring.stages; + +import org.oceandsl.analysis.code.stages.data.IntegerValueHandler; +import org.oceandsl.analysis.code.stages.data.StringValueHandler; +import org.oceandsl.analysis.code.stages.data.Table; + +import teetime.stage.basic.AbstractTransformation; + +/** + * @author Reiner Jung + * @since 1.3.0 + */ +public class AggregateModelEditDistanceStage extends AbstractTransformation<ResultRecord, Table> { + + private final Table table; + + public AggregateModelEditDistanceStage() { + this.table = new Table("med-output", new StringValueHandler("original"), new StringValueHandler("goal"), + new IntegerValueHandler("med")); + } + + @Override + protected void execute(ResultRecord element) throws Exception { + this.table.addRow(element.getOriginalModelName(), element.getGoalModelName(), element.getNumberOfSteps()); + } + + @Override + protected void onTerminating() { + this.outputPort.send(table); + super.onTerminating(); + } +} diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/LightTraceRestorator.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/LightTraceRestorator.java deleted file mode 100644 index 1f480fc561c7959042c8ad5ae1c85ce77851678e..0000000000000000000000000000000000000000 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/LightTraceRestorator.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.oceandsl.tools.restructuring.stages; - - -import org.oceandsl.tools.restructuring.stages.exec.RestructureStepFinder; -import org.oceandsl.tools.restructuring.stages.exec.mapper.AbstractMapper; -import org.oceandsl.tools.restructuring.stages.exec.mapper.Matcher; - -import kieker.model.analysismodel.assembly.AssemblyModel; -import teetime.framework.AbstractProducerStage; - -public class LightTraceRestorator{ - - private AssemblyModel original; - private AssemblyModel goal; - - - public LightTraceRestorator(AssemblyModel original, AssemblyModel goal) { - this.original = original; - this.goal = goal; - } - - public int getNumSteps(){ - - AbstractMapper mapper = new Matcher(original,goal); - - RestructureStepFinder stepfinder = new RestructureStepFinder(mapper); - stepfinder.findTransformation(); - return stepfinder.getNumStep(); - - } - - - -} diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/RestructureModelSinkStage.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/RestructureModelSinkStage.java new file mode 100644 index 0000000000000000000000000000000000000000..78b6c6e45b15cb49ac722c6dbe98572c31b68f31 --- /dev/null +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/RestructureModelSinkStage.java @@ -0,0 +1,31 @@ +package org.oceandsl.tools.restructuring.stages; + +import java.nio.file.Path; + +import org.oceandsl.tools.restructuring.stages.exec.OutputModelCreator; +import org.oceandsl.tools.restructuring.stages.exec.RestructureStepFinder; +import org.oceandsl.tools.restructuring.util.TransformationFactory; +import org.oceandsl.tools.restructuring.util.WriteModelUtils; + +import teetime.framework.AbstractConsumerStage; + +public class RestructureModelSinkStage extends AbstractConsumerStage<RestructureStepFinder> { + private final Path outputPath; + + public RestructureModelSinkStage(final Path outputPath) { + this.outputPath = outputPath; + } + + @Override + protected void execute(RestructureStepFinder element) throws Exception { + if (TransformationFactory.areSameModels(element.getGoal(), element.getOrig())) { + OutputModelCreator output = new OutputModelCreator(element); + output.createOutputModel(); + logger.info("Num of steps: {}", (element.getNumSteps())); + WriteModelUtils.writeModelRepository(outputPath, output.getOutputModel()); + } else { + logger.error("Faulty sequence"); + } + } + +} diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/Restructurer.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/Restructurer.java deleted file mode 100644 index f13edbf0d35034e90dd0305c93c783a51fced6fa..0000000000000000000000000000000000000000 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/Restructurer.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.oceandsl.tools.restructuring.stages; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map.Entry; - -import org.eclipse.emf.common.util.EMap; -import org.oceandsl.tools.restructuring.stages.exec.RestructureStepFinder; -import org.oceandsl.tools.restructuring.stages.exec.mapper.AbstractMapper; -import org.oceandsl.tools.restructuring.transformations.AbstractTransformationStep; -import org.oceandsl.tools.restructuring.transformations.CreateTransformation; -import org.oceandsl.tools.restructuring.transformations.CutTransformation; -import org.oceandsl.tools.restructuring.transformations.PasteTransformation; - -import kieker.analysis.architecture.repository.ModelRepository; -import kieker.model.analysismodel.assembly.AssemblyComponent; -import kieker.model.analysismodel.assembly.AssemblyModel; -import kieker.model.analysismodel.assembly.AssemblyOperation; -import teetime.framework.AbstractConsumerStage; -import teetime.framework.AbstractStage; -import teetime.framework.InputPort; -import teetime.framework.OutputPort; - -public class Restructurer extends AbstractConsumerStage<AbstractMapper> { - - //protected final InputPort<ComponentsMapper> compMapperPort = this.createInputPort(); - - protected final OutputPort<RestructureStepFinder> stepsOutputPort = this.createOutputPort(); - - - - public OutputPort<RestructureStepFinder>getStepsOutputPort(){ - return this.stepsOutputPort; - } - @Override - protected void execute(AbstractMapper mapper) throws Exception { - RestructureStepFinder restructureStepsFinder = new RestructureStepFinder(mapper); - restructureStepsFinder.findTransformation(); - this.stepsOutputPort.send(restructureStepsFinder); - - } -} diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/RestructurerStage.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/RestructurerStage.java new file mode 100644 index 0000000000000000000000000000000000000000..5b60101c920ca966755bfade4939bbea66f470ec --- /dev/null +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/RestructurerStage.java @@ -0,0 +1,33 @@ +package org.oceandsl.tools.restructuring.stages; + +import org.oceandsl.tools.restructuring.stages.exec.RestructureStepFinder; +import org.oceandsl.tools.restructuring.stages.exec.mapper.AbstractMapper; + +import teetime.framework.AbstractConsumerStage; +import teetime.framework.OutputPort; + +public class RestructurerStage extends AbstractConsumerStage<AbstractMapper> { + + // protected final InputPort<ComponentsMapper> compMapperPort = + // this.createInputPort(); + + protected final OutputPort<RestructureStepFinder> stepsOutputPort = this.createOutputPort(); + private OutputPort<ResultRecord> numberOfStepsOutputPort = this.createOutputPort(ResultRecord.class); + + public OutputPort<RestructureStepFinder> getStepsOutputPort() { + return this.stepsOutputPort; + } + + public OutputPort<ResultRecord> getNumberOfStepsOutputPort() { + return this.numberOfStepsOutputPort; + } + + @Override + protected void execute(AbstractMapper mapper) throws Exception { + RestructureStepFinder restructureStepsFinder = new RestructureStepFinder(mapper); + restructureStepsFinder.findTransformation(); + this.stepsOutputPort.send(restructureStepsFinder); + this.numberOfStepsOutputPort.send(new ResultRecord(mapper.getOriginalModelName(), mapper.getGoalModelName(), + restructureStepsFinder.getNumSteps())); + } +} diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/ResultRecord.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/ResultRecord.java new file mode 100644 index 0000000000000000000000000000000000000000..0625659a4bcd085847f5d2580eb1ca8e2812b1c4 --- /dev/null +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/ResultRecord.java @@ -0,0 +1,31 @@ +package org.oceandsl.tools.restructuring.stages; + +/** + * + * @author Reiner Jung + * @since 1.3.0 + */ +public class ResultRecord { + String originalModelName; + String goalModelName; + int numberOfSteps; + + public ResultRecord(String originalModelName, String goalModelName, int numberOfSteps) { + this.originalModelName = originalModelName; + this.goalModelName = goalModelName; + this.numberOfSteps = numberOfSteps; + } + + public String getOriginalModelName() { + return originalModelName; + } + + public String getGoalModelName() { + return goalModelName; + } + + public int getNumberOfSteps() { + return numberOfSteps; + } + +} diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/SinkStage.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/SinkStage.java deleted file mode 100644 index 912d6091f086b18b586e5a2683af76a2a530b6c0..0000000000000000000000000000000000000000 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/SinkStage.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.oceandsl.tools.restructuring.stages; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Collections; -import java.util.Map; - -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; -import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; -import org.oceandsl.analysis.architecture.ArchitectureModelManagementUtils; -import org.oceandsl.tools.restructuring.stages.exec.OutputModelCreator; -import org.oceandsl.tools.restructuring.stages.exec.RestructureStepFinder; -import org.oceandsl.tools.restructuring.util.TransformationFactory; -import org.oceandsl.tools.restructuring.util.WriteModelUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -import teetime.framework.AbstractConsumerStage; - -public class SinkStage extends AbstractConsumerStage<RestructureStepFinder>{ - private final Path outputPath; - - private static final Logger LOGGER = LoggerFactory.getLogger(ArchitectureModelManagementUtils.class); - public SinkStage(final Path outputPath) { - this.outputPath = outputPath; - } - @Override - protected void execute(RestructureStepFinder element) throws Exception { - if(TransformationFactory.areSameModels(element.getGoal(), element.getOrig())) { - OutputModelCreator output = new OutputModelCreator(element); - output.createOutputModel(); - System.out.println("Num of steps: "+(element.getNumStep())); - WriteModelUtils.writeModelRepository(outputPath, output.getOutputModel()); - }else { - System.out.println("Sequence falty"); - } - - - } - - - - -} diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/TraceRestorator.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/TraceRestoratorStage.java similarity index 52% rename from tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/TraceRestorator.java rename to tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/TraceRestoratorStage.java index 16ee9d80e7ca53b57488842e9aab04436aeeabf5..3353b707180da505c19c9890d21e7185546aebc8 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/TraceRestorator.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/TraceRestoratorStage.java @@ -1,71 +1,67 @@ package org.oceandsl.tools.restructuring.stages; +import org.oceandsl.tools.restructuring.EMappingStrategy; import org.oceandsl.tools.restructuring.stages.exec.mapper.AbstractMapper; import org.oceandsl.tools.restructuring.stages.exec.mapper.ComponentsMapper; import org.oceandsl.tools.restructuring.stages.exec.mapper.EmptyMapper; -import org.oceandsl.tools.restructuring.stages.exec.mapper.Matcher; +import org.oceandsl.tools.restructuring.stages.exec.mapper.KuhnMatcherMapper; import org.oceandsl.tools.restructuring.stages.exec.mapper.RandomMapper; import org.oceandsl.tools.restructuring.util.TransformationFactory; import kieker.analysis.architecture.repository.ModelRepository; import kieker.model.analysismodel.assembly.AssemblyModel; import kieker.model.analysismodel.assembly.AssemblyPackage; -import kieker.model.analysismodel.type.TypePackage; import teetime.framework.AbstractConsumerStage; import teetime.framework.OutputPort; +public class TraceRestoratorStage extends AbstractConsumerStage<ModelRepository> { + private EMappingStrategy strat; + protected final OutputPort<AbstractMapper> compMapperOutputPort = this.createOutputPort();// original - -public class TraceRestorator extends AbstractConsumerStage<ModelRepository> { - - private String strat; - - protected final OutputPort<AbstractMapper> compMapperOutputPort = this.createOutputPort();//original - private ModelRepository goal; private ModelRepository original; - - - - public TraceRestorator(String strat) { + + public TraceRestoratorStage(EMappingStrategy strat) { this.strat = strat; } - - public OutputPort<AbstractMapper> getOutputPort(){ - return this.compMapperOutputPort; - + + public OutputPort<AbstractMapper> getOutputPort() { + return this.compMapperOutputPort; } - - + @Override protected void execute(ModelRepository rep) throws Exception { - - if(this.original==null) { + if (this.original == null) { this.original = rep; - }else { + } else { this.goal = rep; AssemblyModel o = this.original.getModel(AssemblyPackage.eINSTANCE.getAssemblyModel()); AssemblyModel g = this.goal.getModel(AssemblyPackage.eINSTANCE.getAssemblyModel()); - AbstractMapper mapper = new ComponentsMapper(o,g); - if (strat.equals("normal")) { - mapper = new ComponentsMapper(o, g); - }else if (strat.equals("empty")){ - mapper = new EmptyMapper(o,g); - }else if((strat.equals("rand"))) { - mapper = new RandomMapper(o,g); - }else if((strat.equals("kuhn"))) { - mapper = new Matcher(o,g); + AbstractMapper mapper; + switch (strat) { + case EMPTY: + mapper = new EmptyMapper(o, g, original.getName(), goal.getName()); + break; + case RANDOM: + mapper = new RandomMapper(o, g, original.getName(), goal.getName()); + break; + case KUHN: + mapper = new KuhnMatcherMapper(o, g, original.getName(), goal.getName()); + break; + case NORMAL: + default: + mapper = new ComponentsMapper(o, g, original.getName(), goal.getName()); + break; } - if(TransformationFactory.areSameModels(o, g)) + + if (TransformationFactory.areSameModels(o, g)) { + this.logger.error("Identical models"); throw new Exception(); - this.compMapperOutputPort.send(mapper); + } else + this.compMapperOutputPort.send(mapper); } - - } - - } \ No newline at end of file diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/OutputModelCreator.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/OutputModelCreator.java index 80ed2b4fd5722dbff49adc29565488d4b112c8d7..6b83f7aa0d307bf64a709ed617c0cc45ff46dab2 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/OutputModelCreator.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/OutputModelCreator.java @@ -1,5 +1,6 @@ package org.oceandsl.tools.restructuring.stages.exec; + import java.util.List; import org.oceandsl.tools.restructuring.transformations.AbstractTransformationStep; @@ -11,7 +12,6 @@ import org.oceandsl.tools.restructuring.transformations.MoveTransformation; import org.oceandsl.tools.restructuring.transformations.PasteTransformation; import org.oceandsl.tools.restructuring.transformations.SplitTransformation; -import kieker.model.analysismodel.assembly.AssemblyFactory; import restructuremodel.ComponentsTransformation; import restructuremodel.CreateComponent; import restructuremodel.CutOperation; @@ -22,119 +22,117 @@ import restructuremodel.PasteOperation; import restructuremodel.RestructuremodelFactory; import restructuremodel.SplitComponent; - public class OutputModelCreator { private RestructureStepFinder stepFinder; private ComponentsTransformation outputModel; RestructuremodelFactory factory = RestructuremodelFactory.eINSTANCE; - + public OutputModelCreator(RestructureStepFinder stepFinder) { this.stepFinder = stepFinder; this.outputModel = factory.createComponentsTransformation(); } - + public ComponentsTransformation getOutputModel() { return this.outputModel; } - + public void createOutputModel() { - List<AbstractTransformationStep> transformations=stepFinder.getSteps(); - for(AbstractTransformationStep step : transformations) { - if(step instanceof CreateTransformation) { - //System.out.println("dadsadre"+outputModel.getTransformations()!=null); - outputModel.getTransformations().add(createCreateComponent((CreateTransformation)step)); - }else if(step instanceof DeleteTransformation) { - outputModel.getTransformations().add(createDeleteComponent((DeleteTransformation)step)); - }else if(step instanceof CutTransformation) { - outputModel.getTransformations().add(createCutOperation((CutTransformation)step)); - }else if (step instanceof PasteTransformation){ - outputModel.getTransformations().add(createPasteOperation((PasteTransformation)step)); - }else if ((step instanceof MoveTransformation)) { - outputModel.getTransformations().add(createMoveOperation((MoveTransformation)step)); - }else if (step instanceof SplitTransformation) { - outputModel.getTransformations().add(createSplitComponent((SplitTransformation)step)); - }else if (step instanceof MergeTransformation) { - outputModel.getTransformations().add(createMergeComponent((MergeTransformation)step)); + List<AbstractTransformationStep> transformations = stepFinder.getSteps(); + for (AbstractTransformationStep step : transformations) { + if (step instanceof CreateTransformation) { + // System.out.println("dadsadre"+outputModel.getTransformations()!=null); + outputModel.getTransformations().add(createCreateComponent((CreateTransformation) step)); + } else if (step instanceof DeleteTransformation) { + outputModel.getTransformations().add(createDeleteComponent((DeleteTransformation) step)); + } else if (step instanceof CutTransformation) { + outputModel.getTransformations().add(createCutOperation((CutTransformation) step)); + } else if (step instanceof PasteTransformation) { + outputModel.getTransformations().add(createPasteOperation((PasteTransformation) step)); + } else if ((step instanceof MoveTransformation)) { + outputModel.getTransformations().add(createMoveOperation((MoveTransformation) step)); + } else if (step instanceof SplitTransformation) { + outputModel.getTransformations().add(createSplitComponent((SplitTransformation) step)); + } else if (step instanceof MergeTransformation) { + outputModel.getTransformations().add(createMergeComponent((MergeTransformation) step)); } } } - - + public CreateComponent createCreateComponent(CreateTransformation transformation) { CreateComponent result = this.factory.createCreateComponent(); - result.setComponentName(transformation.getComponentName()); + result.setComponentName(transformation.getComponentName()); return result; - + } - + public DeleteComponent createDeleteComponent(DeleteTransformation transformation) { DeleteComponent result = this.factory.createDeleteComponent(); - result.setComponentName(transformation.getComponentName()); + result.setComponentName(transformation.getComponentName()); return result; - + } - + public CutOperation createCutOperation(CutTransformation transformation) { CutOperation result = this.factory.createCutOperation(); - result.setComponentName(transformation.getComponentName()); + result.setComponentName(transformation.getComponentName()); result.setOperationName(transformation.getOperationName()); return result; - + } - + public PasteOperation createPasteOperation(PasteTransformation transformation) { PasteOperation result = this.factory.createPasteOperation(); - result.setComponentName(transformation.getComponentName()); + result.setComponentName(transformation.getComponentName()); result.setOperationName(transformation.getOperationName()); return result; - + } - + public MoveOperation createMoveOperation(MoveTransformation transformation) { MoveOperation result = this.factory.createMoveOperation(); result.setFrom(transformation.getCutTransformation().getComponentName()); result.setTo(transformation.getPasteTransformation().getComponentName()); result.setOperationName(transformation.getCutTransformation().getOperationName()); - + CutOperation cut = createCutOperation(transformation.getCutTransformation()); PasteOperation paste = createPasteOperation(transformation.getPasteTransformation()); - + result.setCutOperation(cut); result.setPasteOperation(paste); - + return result; } - + public SplitComponent createSplitComponent(SplitTransformation transformation) { SplitComponent result = this.factory.createSplitComponent(); result.setNewComponent(transformation.getCreateTransformation().getComponentName()); result.setCreateComponent(createCreateComponent(transformation.getCreateTransformation())); - MoveTransformation move = (MoveTransformation)transformation.getMoveTransformation().get(0); + MoveTransformation move = (MoveTransformation) transformation.getMoveTransformation().get(0); result.setOldComponent(move.getCutTransformation().getComponentName()); - for(AbstractTransformationStep mv : transformation.getMoveTransformation()) { - MoveTransformation tmp = (MoveTransformation)mv; + for (AbstractTransformationStep mv : transformation.getMoveTransformation()) { + MoveTransformation tmp = (MoveTransformation) mv; result.getOperationsToMove().add(tmp.getCutTransformation().getOperationName()); result.getMoveOperations().add(createMoveOperation(tmp)); } - + return result; - + } - + public MergeComponent createMergeComponent(MergeTransformation transformation) { MergeComponent result = this.factory.createMergeComponent(); result.setComponentName(transformation.getDeleteTransformation().getComponentName()); result.setDeleteTransformation(createDeleteComponent(transformation.getDeleteTransformation())); - MoveTransformation move = (MoveTransformation)transformation.getMoveTransformations().get(0); + MoveTransformation move = (MoveTransformation) transformation.getMoveTransformations().get(0); result.setMergeGoalComponent(move.getPasteTransformation().getComponentName()); - for(AbstractTransformationStep mv : transformation.getMoveTransformations()) { - MoveTransformation tmp = (MoveTransformation)mv; + for (AbstractTransformationStep mv : transformation.getMoveTransformations()) { + MoveTransformation tmp = (MoveTransformation) mv; result.getOperations().add(tmp.getCutTransformation().getOperationName()); result.getOperationToMove().add(createMoveOperation(tmp)); } - + return result; } - + } diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/RestructureStepFinder.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/RestructureStepFinder.java index a07a5c2344c20fb13c302e0b9395222b0f43c78c..bc6d43be2a0370ddf2af93501a292e1ee82afdd7 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/RestructureStepFinder.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/RestructureStepFinder.java @@ -1,15 +1,10 @@ package org.oceandsl.tools.restructuring.stages.exec; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.Map.Entry; -import org.eclipse.emf.common.util.BasicEMap; import org.eclipse.emf.common.util.EMap; -import org.eclipse.emf.ecore.util.EcoreEMap; import org.oceandsl.tools.restructuring.stages.exec.mapper.AbstractMapper; import org.oceandsl.tools.restructuring.stages.exec.mapper.ComponentsMapper; import org.oceandsl.tools.restructuring.transformations.AbstractTransformationStep; @@ -31,21 +26,22 @@ public class RestructureStepFinder { private AbstractMapper compMapper; private AssemblyModel orig; private AssemblyModel goal; - private int numSteps = 0; + private int numSteps = 0; private List<AbstractTransformationStep> transformations = new ArrayList<AbstractTransformationStep>(); /** * Cosntructor is used to - * + * * @param orig * @param goal * @param compMapper */ - public RestructureStepFinder(AssemblyModel orig, AssemblyModel goal) { + public RestructureStepFinder(AssemblyModel orig, AssemblyModel goal, String originalModelName, + String goalModelName) { this.orig = orig; this.goal = goal; - this.compMapper = new ComponentsMapper(this.orig, this.goal); + this.compMapper = new ComponentsMapper(this.orig, this.goal, originalModelName, goalModelName); } public RestructureStepFinder(AssemblyModel orig, AssemblyModel goal, ComponentsMapper compMapper) { @@ -60,6 +56,12 @@ public class RestructureStepFinder { this.goal = compMapper.getGoal(); } + public RestructureStepFinder(AbstractMapper compMapper, String originalModelName, String goalModelName) { + this.compMapper = compMapper; + this.orig = compMapper.getOrig(); + this.goal = compMapper.getGoal(); + } + public List<AbstractTransformationStep> getSteps() { return this.transformations; } @@ -67,51 +69,55 @@ public class RestructureStepFinder { public AssemblyModel getOrig() { return this.orig; } - + public AssemblyModel getGoal() { return this.goal; } - public int getNumStep() { + + public int getNumSteps() { return this.numSteps; } + public void findTransformation() { // goalComponents. - //System.out.println("Num of gto in step finder:"+this.compMapper.getGoalToOriginal().size()); - //System.out.println("Num of tgo in stepfinder:"+this.compMapper.getOriginallToGoal().size()); - EMap<String, AssemblyComponent> originalComponents = (EcoreEMap<String, AssemblyComponent>) this.orig - .getComponents(); - while(!TransformationFactory.areSameModels(goal, orig)) { - for (int i = 0; i < originalComponents.size(); i++) { - - Entry<String, AssemblyComponent> entry = originalComponents.get(i); - String nameOfOriginalC = entry.getKey(); - String nameOfGoalC = this.compMapper.getOriginallToGoal().get(nameOfOriginalC); - - // We could find a mapping, yeah! - if (nameOfGoalC != null) { - //System.out.println("Get nameOfGoalC "+ nameOfGoalC); - AssemblyComponent goalAssemblyComponentObject = this.goal.getComponents().get(nameOfGoalC); - EMap<String, AssemblyOperation> operationInGoalcomponent = goalAssemblyComponentObject.getOperations(); - - // If the original and corresponding goal component equal, nothing to do - // if (entry.getValue().equals(goalAssemblyComponentObject)) // the mapping - // matches look for next - if (TransformationFactory.areSameComponents(entry.getValue(), goalAssemblyComponentObject)) - continue; - - // Operations that are in original component but not in goal component - List<String> out = getOperationsToMove(entry.getValue(), goalAssemblyComponentObject); - // Operation that are in goal component but not in the original component - List<String> in = getOperationToAdd(entry.getValue(), goalAssemblyComponentObject); - transformModel(out, in, entry.getKey(), this.goal); + // System.out.println("Num of gto in step + // finder:"+this.compMapper.getGoalToOriginal().size()); + // System.out.println("Num of tgo in + // stepfinder:"+this.compMapper.getOriginallToGoal().size()); + EMap<String, AssemblyComponent> originalComponents = this.orig.getComponents(); + while (!TransformationFactory.areSameModels(goal, orig)) { + for (int i = 0; i < originalComponents.size(); i++) { + + Entry<String, AssemblyComponent> entry = originalComponents.get(i); + String nameOfOriginalC = entry.getKey(); + String nameOfGoalC = this.compMapper.getOriginallToGoal().get(nameOfOriginalC); + + // We could find a mapping, yeah! + if (nameOfGoalC != null) { + // System.out.println("Get nameOfGoalC "+ nameOfGoalC); + AssemblyComponent goalAssemblyComponentObject = this.goal.getComponents().get(nameOfGoalC); + EMap<String, AssemblyOperation> operationInGoalcomponent = goalAssemblyComponentObject + .getOperations(); + + // If the original and corresponding goal component equal, nothing to do + // if (entry.getValue().equals(goalAssemblyComponentObject)) // the mapping + // matches look for next + if (TransformationFactory.areSameComponents(entry.getValue(), goalAssemblyComponentObject)) + continue; + + // Operations that are in original component but not in goal component + List<String> out = getOperationsToMove(entry.getValue(), goalAssemblyComponentObject); + // Operation that are in goal component but not in the original component + List<String> in = getOperationToAdd(entry.getValue(), goalAssemblyComponentObject); + transformModel(out, in, entry.getKey(), this.goal); + + } else { + // Mapping could not be found + nonMappedComponentTransformation(entry.getValue(), this.orig, this.goal); - } else { - // Mapping could not be found - nonMappedComponentTransformation(entry.getValue(), this.orig, this.goal); + } } - - } } } // } @@ -128,8 +134,8 @@ public class RestructureStepFinder { // Where does it lie currently? // String originalComponent = operation.getValue().getComponent().getSignature(); - - //MP 2023 + + // MP 2023 String originalComponent = this.compMapper.getOperationToComponentO().get(operation.getKey()); // check if the goal location of the current operation is mapped to some // component in original? @@ -166,16 +172,16 @@ public class RestructureStepFinder { cut.setComponentName(originalComponent); cut.setOperationName(operationName); this.numSteps++; - //this.transformations.add(cut); - //cut.applyTransformation(this.orig); + // this.transformations.add(cut); + // cut.applyTransformation(this.orig); PasteTransformation paste = new PasteTransformation(null); paste.setComponentName(to); paste.setOperationName(operationName); this.numSteps++; - //this.transformations.add(paste); - //paste.applyTransformation(this.orig); - + // this.transformations.add(paste); + // paste.applyTransformation(this.orig); + MoveTransformation move = new MoveTransformation(null); move.getSteps().add(cut); move.getSteps().add(paste); @@ -187,14 +193,14 @@ public class RestructureStepFinder { delete.setComponentName(originalComponent); delete.applyTransformation(this.orig); this.numSteps++; - //this.transformations.add(delete); - + // this.transformations.add(delete); + MergeTransformation merge = new MergeTransformation(null); merge.add(move); merge.add(delete); - this.transformations.remove(this.transformations.size()-1); + this.transformations.remove(this.transformations.size() - 1); this.transformations.add(delete); - + } } @@ -205,7 +211,7 @@ public class RestructureStepFinder { } /** - * + * * @param out operations that are not contained in the goal model and must be * removed from original * @param in operation that are contained in the goal model and must be added @@ -231,17 +237,17 @@ public class RestructureStepFinder { cut.setComponentName(origC); cut.setOperationName(op); this.numSteps++; - //this.transformations.add(cut); - //cut.applyTransformation(this.orig); + // this.transformations.add(cut); + // cut.applyTransformation(this.orig); // Paste into another component PasteTransformation paste = new PasteTransformation(null); paste.setComponentName(originalComponentFromGoal); paste.setOperationName(op); this.numSteps++; - //paste.applyTransformation(this.orig); - //this.transformations.add(paste); - + // paste.applyTransformation(this.orig); + // this.transformations.add(paste); + MoveTransformation move = new MoveTransformation(null); move.getSteps().add(cut); move.getSteps().add(paste); @@ -256,8 +262,8 @@ public class RestructureStepFinder { this.numSteps++; // we use the name as it is specified in goal model - //this.transformations.add(create); - //create.applyTransformation(this.orig); + // this.transformations.add(create); + // create.applyTransformation(this.orig); this.compMapper.getOriginallToGoal().put(compName, compName); this.compMapper.getGoalToOriginal().put(compName, compName); @@ -267,27 +273,27 @@ public class RestructureStepFinder { cut.setComponentName(origC); cut.setOperationName(op); this.numSteps++; - // this.transformations.add(cut); - // cut.applyTransformation(this.orig); + // this.transformations.add(cut); + // cut.applyTransformation(this.orig); PasteTransformation paste = new PasteTransformation(null); paste.setComponentName(compName); paste.setOperationName(op); this.numSteps++; - // this.transformations.add(paste); - // paste.applyTransformation(this.orig); - + // this.transformations.add(paste); + // paste.applyTransformation(this.orig); + MoveTransformation move = new MoveTransformation(null); move.getSteps().add(cut); move.getSteps().add(paste); - // move.applyTransformation(this.orig); - + // move.applyTransformation(this.orig); + SplitTransformation split = new SplitTransformation(null); split.add(create); split.add(move); split.applyTransformation(this.orig); this.transformations.add(split); - + } } // move in @@ -300,16 +306,16 @@ public class RestructureStepFinder { cut.setComponentName(compName); cut.setOperationName(op); this.numSteps++; - //this.transformations.add(cut); - //cut.applyTransformation(this.orig); + // this.transformations.add(cut); + // cut.applyTransformation(this.orig); PasteTransformation paste = new PasteTransformation(null); paste.setOperationName(op); paste.setComponentName(origC); this.numSteps++; - //this.transformations.add(paste); - //paste.applyTransformation(this.orig); - + // this.transformations.add(paste); + // paste.applyTransformation(this.orig); + MoveTransformation move = new MoveTransformation(null); move.getSteps().add(cut); move.getSteps().add(paste); @@ -325,11 +331,11 @@ public class RestructureStepFinder { delete.applyTransformation(this.orig); this.numSteps++; this.transformations.add(delete); - + MergeTransformation merge = new MergeTransformation(null); merge.add(move); merge.add(delete); - this.transformations.remove(this.transformations.size()-1); + this.transformations.remove(this.transformations.size() - 1); this.transformations.add(merge); } diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/AbstractMapper.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/AbstractMapper.java index d991fc3416be509904839ea04ab49ec53eef1b46..42052dd727680a334ad6852fea534da7bf8eef03 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/AbstractMapper.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/AbstractMapper.java @@ -4,25 +4,42 @@ import java.util.HashMap; import kieker.model.analysismodel.assembly.AssemblyModel; -public class AbstractMapper { +public abstract class AbstractMapper { + private ComponentsMapper compMapper; + private String originalModelName; + private String goalModelName; + protected AssemblyModel orig; protected AssemblyModel goal; - - protected HashMap <String, String> operationToComponentO = new HashMap<String, String>(); - protected HashMap<String, String> operationToComponentG = new HashMap<String, String>(); - - protected HashMap<String,HashMap<String, Integer>> traceModell = new HashMap<String, HashMap<String,Integer>>(); - protected HashMap<String,String> goalToOriginal = new HashMap<String,String>(); - protected HashMap<String,String> originallToGoal = new HashMap<String,String>(); - public HashMap <String, String> getOperationToComponentO() { + + protected HashMap<String, String> operationToComponentO = new HashMap<String, String>(); + protected HashMap<String, String> operationToComponentG = new HashMap<String, String>(); + + protected HashMap<String, HashMap<String, Integer>> traceModell = new HashMap<String, HashMap<String, Integer>>(); + protected HashMap<String, String> goalToOriginal = new HashMap<String, String>(); + protected HashMap<String, String> originallToGoal = new HashMap<String, String>(); + + public AbstractMapper(String originalModelName, String goalModelName) { + this.originalModelName = originalModelName; + this.goalModelName = goalModelName; + } + + public String getGoalModelName() { + return goalModelName; + } + + public String getOriginalModelName() { + return originalModelName; + } + + public HashMap<String, String> getOperationToComponentO() { return operationToComponentO; } - public void setOperationToComponentO(HashMap <String, String> operationToComponentO) { + public void setOperationToComponentO(HashMap<String, String> operationToComponentO) { this.operationToComponentO = operationToComponentO; } - public HashMap<String, String> getOperationToComponentG() { return operationToComponentG; @@ -32,37 +49,37 @@ public class AbstractMapper { this.operationToComponentG = operationToComponentG; } - public HashMap<String,HashMap<String, Integer>> getTraceModell() { + public HashMap<String, HashMap<String, Integer>> getTraceModell() { return traceModell; } - public void setTraceModell(HashMap<String,HashMap<String, Integer>> traceModell) { + public void setTraceModell(HashMap<String, HashMap<String, Integer>> traceModell) { this.traceModell = traceModell; } - public HashMap<String,String> getGoalToOriginal() { + public HashMap<String, String> getGoalToOriginal() { return goalToOriginal; } - public void setGoalToOriginal(HashMap<String,String> goalToOriginal) { + public void setGoalToOriginal(HashMap<String, String> goalToOriginal) { this.goalToOriginal = goalToOriginal; } - public HashMap<String,String> getOriginallToGoal() { + public HashMap<String, String> getOriginallToGoal() { return originallToGoal; } - public void setOriginallToGoal(HashMap<String,String> originallToGoal) { + public void setOriginallToGoal(HashMap<String, String> originallToGoal) { this.originallToGoal = originallToGoal; } - + public AssemblyModel getOrig() { return this.orig; - + } public AssemblyModel getGoal() { return this.goal; - + } } diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/ComponentsMapper.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/ComponentsMapper.java index d0ba19ab3fc104c5eeac1acf5b509c614fd0961b..f3ff1660292d30d0b28a5eb976efa37e620b69d4 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/ComponentsMapper.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/ComponentsMapper.java @@ -1,177 +1,181 @@ package org.oceandsl.tools.restructuring.stages.exec.mapper; import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map.Entry; - -import org.eclipse.emf.common.util.EMap; - import java.util.Set; import kieker.model.analysismodel.assembly.AssemblyComponent; import kieker.model.analysismodel.assembly.AssemblyModel; -import kieker.model.analysismodel.assembly.AssemblyOperation; -public class ComponentsMapper extends AbstractMapper{ +public class ComponentsMapper extends AbstractMapper { private ComponentsMapper compMapper; private AssemblyModel orig; private AssemblyModel goal; - - private HashMap <String, String> operationToComponentO = new HashMap<String, String>(); - private HashMap<String, String> operationToComponentG = new HashMap<String, String>(); - - private HashMap<String,HashMap<String, Integer>> traceModell = new HashMap<String, HashMap<String,Integer>>(); - private HashMap<String,String> goalToOriginal = new HashMap<String,String>(); - private HashMap<String,String> originallToGoal = new HashMap<String,String>(); - + + private HashMap<String, String> operationToComponentO = new HashMap<String, String>(); + private HashMap<String, String> operationToComponentG = new HashMap<String, String>(); + + private HashMap<String, HashMap<String, Integer>> traceModell = new HashMap<String, HashMap<String, Integer>>(); + private HashMap<String, String> goalToOriginal = new HashMap<String, String>(); + private HashMap<String, String> originallToGoal = new HashMap<String, String>(); + /** * Cosntructor is used to + * * @param orig * @param goal * @param compMapper */ - public ComponentsMapper(AssemblyModel orig, AssemblyModel goal) { + public ComponentsMapper(AssemblyModel orig, AssemblyModel goal, String originalModelName, String goalModelName) { + super(originalModelName, goalModelName); + this.orig = orig; this.goal = goal; - //init mappings + // init mappings populateOperationTocomponentG(); populateOperationToComponentO(); populateTraceModel(); computeOriginalComponentNames(); - + } - - - public HashMap <String, String> getOperationToComponentO() { + + @Override + public HashMap<String, String> getOperationToComponentO() { return operationToComponentO; } - public void setOperationToComponentO(HashMap <String, String> operationToComponentO) { + @Override + public void setOperationToComponentO(HashMap<String, String> operationToComponentO) { this.operationToComponentO = operationToComponentO; } - + @Override public HashMap<String, String> getOperationToComponentG() { return operationToComponentG; } + @Override public void setOperationToComponentG(HashMap<String, String> operationToComponentG) { this.operationToComponentG = operationToComponentG; } - public HashMap<String,HashMap<String, Integer>> getTraceModell() { + @Override + public HashMap<String, HashMap<String, Integer>> getTraceModell() { return traceModell; } - public void setTraceModell(HashMap<String,HashMap<String, Integer>> traceModell) { + @Override + public void setTraceModell(HashMap<String, HashMap<String, Integer>> traceModell) { this.traceModell = traceModell; } - public HashMap<String,String> getGoalToOriginal() { + @Override + public HashMap<String, String> getGoalToOriginal() { return goalToOriginal; } - public void setGoalToOriginal(HashMap<String,String> goalToOriginal) { + @Override + public void setGoalToOriginal(HashMap<String, String> goalToOriginal) { this.goalToOriginal = goalToOriginal; } - public HashMap<String,String> getOriginallToGoal() { + @Override + public HashMap<String, String> getOriginallToGoal() { return originallToGoal; } - public void setOriginallToGoal(HashMap<String,String> originallToGoal) { + @Override + public void setOriginallToGoal(HashMap<String, String> originallToGoal) { this.originallToGoal = originallToGoal; } - + + @Override public AssemblyModel getOrig() { return this.orig; - + } + @Override public AssemblyModel getGoal() { return this.goal; - + } - private void computeOriginalComponentNames() { + + private void computeOriginalComponentNames() { Set<String> assignedComponentsG = new HashSet<String>(); Set<String> assignedComponentsO = new HashSet<String>(); - for(Entry<String, HashMap<String,Integer>> goalComponent : this.traceModell.entrySet()) { + for (Entry<String, HashMap<String, Integer>> goalComponent : this.traceModell.entrySet()) { ArrayList<Entry<String, Integer>> componentTraces = new ArrayList<>(goalComponent.getValue().entrySet()); componentTraces.sort(Comparator.comparing(Entry::getValue)); - - for(Entry<String, Integer> e : componentTraces) { - if(assignedComponentsO.contains(e.getKey())) { - continue; - } - assignedComponentsO.add(e.getKey()); - assignedComponentsG.add(goalComponent.getKey()); - this.goalToOriginal.put(goalComponent.getKey(), e.getKey()); - this.originallToGoal.put(e.getKey(), goalComponent.getKey()); - break; + + for (Entry<String, Integer> e : componentTraces) { + if (assignedComponentsO.contains(e.getKey())) { + continue; + } + assignedComponentsO.add(e.getKey()); + assignedComponentsG.add(goalComponent.getKey()); + this.goalToOriginal.put(goalComponent.getKey(), e.getKey()); + this.originallToGoal.put(e.getKey(), goalComponent.getKey()); + break; } } - + } - - private void populateTraceModel() { // For each component in the goal model... - for(Entry<String, AssemblyComponent> entry : this.goal.getComponents().entrySet()) { - - AssemblyComponent comp = entry.getValue(); - String name = entry.getKey(); - - // get operations of the current component - final Set<String> ops = comp.getOperations().keySet(); - //here we store the components where operations actually originate from and count how many operations of each - // original component are in the "goal component" - final HashMap<String, Integer> referencedComponents = new HashMap<String, Integer>(); - - // For each operation of current component.. - for(String op : ops) { - - - //String opName = op.getKey(); - //look up the name of the "original component" for that operation - String originalComponent = this.operationToComponentO.get(op); - - //Already found or not? - if(referencedComponents.containsKey(originalComponent)) { - referencedComponents.put(originalComponent, referencedComponents.get(originalComponent)+1); - - }else { - //first occurence - referencedComponents.put(originalComponent,1); - } - - } - this.traceModell.put(name, referencedComponents); - + for (Entry<String, AssemblyComponent> entry : this.goal.getComponents().entrySet()) { + + AssemblyComponent comp = entry.getValue(); + String name = entry.getKey(); + + // get operations of the current component + final Set<String> ops = comp.getOperations().keySet(); + // here we store the components where operations actually originate from and + // count how many operations of each + // original component are in the "goal component" + final HashMap<String, Integer> referencedComponents = new HashMap<String, Integer>(); + + // For each operation of current component.. + for (String op : ops) { + + // String opName = op.getKey(); + // look up the name of the "original component" for that operation + String originalComponent = this.operationToComponentO.get(op); + + // Already found or not? + if (referencedComponents.containsKey(originalComponent)) { + referencedComponents.put(originalComponent, referencedComponents.get(originalComponent) + 1); + + } else { + // first occurence + referencedComponents.put(originalComponent, 1); } + + } + this.traceModell.put(name, referencedComponents); + + } } - - + private void populateOperationToComponentO() { - for(Entry<String, AssemblyComponent> e:this.orig.getComponents().entrySet()) { - Set<String>ops = e.getValue().getOperations().keySet(); - for(String s : ops) { + for (Entry<String, AssemblyComponent> e : this.orig.getComponents().entrySet()) { + Set<String> ops = e.getValue().getOperations().keySet(); + for (String s : ops) { this.operationToComponentO.put(s, e.getKey()); } } } - + private void populateOperationTocomponentG() { - for(Entry<String, AssemblyComponent> e:this.goal.getComponents().entrySet()) { - Set<String>ops = e.getValue().getOperations().keySet(); - for(String s : ops) { + for (Entry<String, AssemblyComponent> e : this.goal.getComponents().entrySet()) { + Set<String> ops = e.getValue().getOperations().keySet(); + for (String s : ops) { this.operationToComponentG.put(s, e.getKey()); } } diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/EmptyMapper.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/EmptyMapper.java index 371799078894a48ed0a6decc6c2752eac3130205..08e6c8299b6a5cd6e56e8dc412bf7e953d0749bd 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/EmptyMapper.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/EmptyMapper.java @@ -1,20 +1,19 @@ package org.oceandsl.tools.restructuring.stages.exec.mapper; -import java.util.HashMap; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; import kieker.model.analysismodel.assembly.AssemblyComponent; import kieker.model.analysismodel.assembly.AssemblyModel; -public class EmptyMapper extends AbstractMapper{ - +public class EmptyMapper extends AbstractMapper { - public EmptyMapper(AssemblyModel orig, AssemblyModel goal) { + public EmptyMapper(AssemblyModel orig, AssemblyModel goal, String originalModelName, String goalModelName) { + super(originalModelName, goalModelName); this.orig = orig; this.goal = goal; - // System.out.println(this.orig != null); - // System.out.println(this.goal != null); + // System.out.println(this.orig != null); + // System.out.println(this.goal != null); // init mappings populateOperationTocomponentG(); populateOperationToComponentO(); diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/Matcher.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/KuhnMatcherMapper.java similarity index 89% rename from tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/Matcher.java rename to tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/KuhnMatcherMapper.java index b782b213a8a79451c0069f3b2211330f7d4dc040..43f00a77248e3f97c56bb65ee343b875daa3e738 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/Matcher.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/KuhnMatcherMapper.java @@ -1,25 +1,22 @@ package org.oceandsl.tools.restructuring.stages.exec.mapper; -import java.util.ArrayList; -import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; -import java.util.List; -import java.util.Set; import java.util.Map.Entry; - -import kieker.model.analysismodel.assembly.AssemblyComponent; -import kieker.model.analysismodel.assembly.AssemblyModel; -import kieker.model.analysismodel.assembly.AssemblyOperation; +import java.util.Set; import org.jgrapht.Graph; import org.jgrapht.alg.interfaces.MatchingAlgorithm.Matching; -import org.jgrapht.alg.matching.KuhnMunkresMinimalWeightBipartitePerfectMatching; import org.jgrapht.alg.matching.MaximumWeightBipartiteMatching; -import org.jgrapht.graph.*; +import org.jgrapht.graph.DefaultEdge; +import org.jgrapht.graph.SimpleWeightedGraph; import org.oceandsl.tools.restructuring.util.RestructurerTools; -public class Matcher extends AbstractMapper { +import kieker.model.analysismodel.assembly.AssemblyComponent; +import kieker.model.analysismodel.assembly.AssemblyModel; +import kieker.model.analysismodel.assembly.AssemblyOperation; + +public class KuhnMatcherMapper extends AbstractMapper { private ComponentsMapper compMapper; private final static String GOAL = "20_"; private AssemblyModel orig; @@ -37,7 +34,8 @@ public class Matcher extends AbstractMapper { private HashMap<String, String> goalToOriginal = new HashMap<String, String>(); private HashMap<String, String> originallToGoal = new HashMap<String, String>(); - public Matcher(AssemblyModel orig, AssemblyModel goal) { + public KuhnMatcherMapper(AssemblyModel orig, AssemblyModel goal, String originalModelName, String goalModelName) { + super(originalModelName, goalModelName); this.orig = RestructurerTools.cloneModel(orig); this.goal = RestructurerTools.alterComponentNames(goal); this.s.addAll(this.orig.getComponents().keySet()); @@ -45,8 +43,8 @@ public class Matcher extends AbstractMapper { this.graph = new SimpleWeightedGraph<String, DefaultEdge>(DefaultEdge.class); populateOperationTocomponentG(); populateOperationToComponentO(); - - if(this.operationToComponentO.size()!=this.operationToComponentG.size()) { + + if (this.operationToComponentO.size() != this.operationToComponentG.size()) { throw new Error("Some operations are lost?"); } // System.out.println("Same comps:" + @@ -65,7 +63,7 @@ public class Matcher extends AbstractMapper { // operations in // original // componen - + String goalVertex = this.operationToComponentG.get(ops.getKey()); if (!this.graph.containsVertex(goalVertex)) { // vertex was not added yet , thus simply create and edge this.graph.addVertex(goalVertex); // component on goal as vertex @@ -104,7 +102,7 @@ public class Matcher extends AbstractMapper { * AssemblyComponent>e:this.goal.getComponents().entrySet()) { DefaultEdge * edge=this.graph.addEdge(dummy, e.getKey()); this.graph.setEdgeWeight(edge, * 0); } } - * + * * }else if(this.orig.getComponents().size()>this.goal.getComponents().size()) { * //stock up goal vertices with dummies int diff = * this.orig.getComponents().size()-this.goal.getComponents().size(); for(int @@ -112,11 +110,11 @@ public class Matcher extends AbstractMapper { * this.t.add(dummy); for(Entry <String, * AssemblyComponent>e:this.orig.getComponents().entrySet()) { DefaultEdge * edge=this.graph.addEdge(e.getKey(), dummy); - * + * * this.graph.setEdgeWeight(edge, 0); } } } - * + * * //add 0 edges if not exist yet - * + * * for(String o:this.s) { for(String g : this.t) { * if(!this.graph.containsEdge(o,g)) { DefaultEdge edge=this.graph.addEdge(o, * g); this.graph.setEdgeWeight(edge, 0); } } } @@ -138,51 +136,63 @@ public class Matcher extends AbstractMapper { } + @Override public HashMap<String, String> getOperationToComponentO() { return operationToComponentO; } + @Override public void setOperationToComponentO(HashMap<String, String> operationToComponentO) { this.operationToComponentO = operationToComponentO; } + @Override public HashMap<String, String> getOperationToComponentG() { return operationToComponentG; } + @Override public void setOperationToComponentG(HashMap<String, String> operationToComponentG) { this.operationToComponentG = operationToComponentG; } + @Override public HashMap<String, HashMap<String, Integer>> getTraceModell() { return traceModell; } + @Override public void setTraceModell(HashMap<String, HashMap<String, Integer>> traceModell) { this.traceModell = traceModell; } + @Override public HashMap<String, String> getGoalToOriginal() { return goalToOriginal; } + @Override public void setGoalToOriginal(HashMap<String, String> goalToOriginal) { this.goalToOriginal = goalToOriginal; } + @Override public HashMap<String, String> getOriginallToGoal() { return originallToGoal; } + @Override public void setOriginallToGoal(HashMap<String, String> originallToGoal) { this.originallToGoal = originallToGoal; } + @Override public AssemblyModel getOrig() { return this.orig; } + @Override public AssemblyModel getGoal() { return this.goal; @@ -204,21 +214,21 @@ public class Matcher extends AbstractMapper { } private void populateOperationToComponentO() { - for(Entry<String, AssemblyComponent> e:this.orig.getComponents().entrySet()) { - Set<String>ops = e.getValue().getOperations().keySet(); - for(String s : ops) { + for (Entry<String, AssemblyComponent> e : this.orig.getComponents().entrySet()) { + Set<String> ops = e.getValue().getOperations().keySet(); + for (String s : ops) { this.operationToComponentO.put(s, e.getKey()); } } } - + private void populateOperationTocomponentG() { - for(Entry<String, AssemblyComponent> e:this.goal.getComponents().entrySet()) { - Set<String>ops = e.getValue().getOperations().keySet(); - for(String s : ops) { + for (Entry<String, AssemblyComponent> e : this.goal.getComponents().entrySet()) { + Set<String> ops = e.getValue().getOperations().keySet(); + for (String s : ops) { this.operationToComponentG.put(s, e.getKey()); } } } - + } diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/RandomMapper.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/RandomMapper.java index 09231781d3a5810187404bb84e4924104f48f69c..243b8bd704e139e59c248501732c995a0214041b 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/RandomMapper.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/RandomMapper.java @@ -1,171 +1,175 @@ package org.oceandsl.tools.restructuring.stages.exec.mapper; import java.util.ArrayList; -import java.util.Comparator; import java.util.HashMap; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.Map.Entry; import java.util.Random; +import java.util.Set; import kieker.model.analysismodel.assembly.AssemblyComponent; import kieker.model.analysismodel.assembly.AssemblyModel; public class RandomMapper extends AbstractMapper { - - - /** * Cosntructor is used to + * * @param orig * @param goal * @param compMapper */ - public RandomMapper(AssemblyModel orig, AssemblyModel goal) { + public RandomMapper(AssemblyModel orig, AssemblyModel goal, String originalModelName, String goalModelName) { + super(originalModelName, goalModelName); this.orig = orig; this.goal = goal; - System.out.println(this.orig!=null); - System.out.println(this.goal!=null); - //init mappings + System.out.println(this.orig != null); + System.out.println(this.goal != null); + // init mappings populateOperationTocomponentG(); populateOperationToComponentO(); populateTraceModel(); computeOriginalComponentNames(); - } - - - public HashMap <String, String> getOperationToComponentO() { + + @Override + public HashMap<String, String> getOperationToComponentO() { return operationToComponentO; } - public void setOperationToComponentO(HashMap <String, String> operationToComponentO) { + @Override + public void setOperationToComponentO(HashMap<String, String> operationToComponentO) { this.operationToComponentO = operationToComponentO; } - + @Override public HashMap<String, String> getOperationToComponentG() { return operationToComponentG; } + @Override public void setOperationToComponentG(HashMap<String, String> operationToComponentG) { this.operationToComponentG = operationToComponentG; } - public HashMap<String,HashMap<String, Integer>> getTraceModell() { + @Override + public HashMap<String, HashMap<String, Integer>> getTraceModell() { return traceModell; } - public void setTraceModell(HashMap<String,HashMap<String, Integer>> traceModell) { + @Override + public void setTraceModell(HashMap<String, HashMap<String, Integer>> traceModell) { this.traceModell = traceModell; } - public HashMap<String,String> getGoalToOriginal() { + @Override + public HashMap<String, String> getGoalToOriginal() { return goalToOriginal; } - public void setGoalToOriginal(HashMap<String,String> goalToOriginal) { + @Override + public void setGoalToOriginal(HashMap<String, String> goalToOriginal) { this.goalToOriginal = goalToOriginal; } - public HashMap<String,String> getOriginallToGoal() { + @Override + public HashMap<String, String> getOriginallToGoal() { return originallToGoal; } - public void setOriginallToGoal(HashMap<String,String> originallToGoal) { + @Override + public void setOriginallToGoal(HashMap<String, String> originallToGoal) { this.originallToGoal = originallToGoal; } - + + @Override public AssemblyModel getOrig() { return this.orig; - + } + @Override public AssemblyModel getGoal() { return this.goal; - + } - private void computeOriginalComponentNames() { - Set<String>comps = this.goal.getComponents().keySet(); + + private void computeOriginalComponentNames() { + Set<String> comps = this.goal.getComponents().keySet(); List<String> compList = new ArrayList(comps); List<String> randComps = getRandomComponents(compList); - - int currentRand = 0; - for(String origC: this.orig.getComponents().keySet()) { - this.goalToOriginal.put(randComps.get(currentRand), origC); - this.originallToGoal.put(origC,randComps.get(currentRand) ); - currentRand++; - } - + + int currentRand = 0; + for (String origC : this.orig.getComponents().keySet()) { + this.goalToOriginal.put(randComps.get(currentRand), origC); + this.originallToGoal.put(origC, randComps.get(currentRand)); + currentRand++; + } + } - - private List<String> getRandomComponents(List<String> componentNames){ + + private List<String> getRandomComponents(List<String> componentNames) { Random rand = new Random(); List<String> result = new ArrayList(); - for(int i=0; i<this.orig.getComponents().keySet().size(); i++) { + for (int i = 0; i < this.orig.getComponents().keySet().size(); i++) { int randomIndex = rand.nextInt(componentNames.size()); result.add(componentNames.get(randomIndex)); componentNames.remove(randomIndex); - + } return result; - + } - - private void populateTraceModel() { // For each component in the goal model... - for(Entry<String, AssemblyComponent> entry : this.goal.getComponents().entrySet()) { - - AssemblyComponent comp = entry.getValue(); - String name = entry.getKey(); - - // get operations of the current component - final Set<String> ops = comp.getOperations().keySet(); - //here we store the components where operations actually originate from and count how many operations of each - // original component are in the "goal component" - final HashMap<String, Integer> referencedComponents = new HashMap<String, Integer>(); - - // For each operation of current component.. - for(String op : ops) { - - - //String opName = op.getKey(); - //look up the name of the "original component" for that operation - String originalComponent = this.operationToComponentO.get(op); - - //Already found or not? - if(referencedComponents.containsKey(originalComponent)) { - referencedComponents.put(originalComponent, referencedComponents.get(originalComponent)+1); - - }else { - //first occurence - referencedComponents.put(originalComponent,1); - } - - } - this.traceModell.put(name, referencedComponents); - + for (Entry<String, AssemblyComponent> entry : this.goal.getComponents().entrySet()) { + + AssemblyComponent comp = entry.getValue(); + String name = entry.getKey(); + + // get operations of the current component + final Set<String> ops = comp.getOperations().keySet(); + // here we store the components where operations actually originate from and + // count how many operations of each + // original component are in the "goal component" + final HashMap<String, Integer> referencedComponents = new HashMap<String, Integer>(); + + // For each operation of current component.. + for (String op : ops) { + + // String opName = op.getKey(); + // look up the name of the "original component" for that operation + String originalComponent = this.operationToComponentO.get(op); + + // Already found or not? + if (referencedComponents.containsKey(originalComponent)) { + referencedComponents.put(originalComponent, referencedComponents.get(originalComponent) + 1); + + } else { + // first occurence + referencedComponents.put(originalComponent, 1); } + + } + this.traceModell.put(name, referencedComponents); + + } } - - + private void populateOperationToComponentO() { - for(Entry<String, AssemblyComponent> e:this.orig.getComponents().entrySet()) { - Set<String>ops = e.getValue().getOperations().keySet(); - for(String s : ops) { + for (Entry<String, AssemblyComponent> e : this.orig.getComponents().entrySet()) { + Set<String> ops = e.getValue().getOperations().keySet(); + for (String s : ops) { this.operationToComponentO.put(s, e.getKey()); } } } - + private void populateOperationTocomponentG() { - for(Entry<String, AssemblyComponent> e:this.goal.getComponents().entrySet()) { - Set<String>ops = e.getValue().getOperations().keySet(); - for(String s : ops) { + for (Entry<String, AssemblyComponent> e : this.goal.getComponents().entrySet()) { + Set<String> ops = e.getValue().getOperations().keySet(); + for (String s : ops) { this.operationToComponentG.put(s, e.getKey()); } } diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/matching/BipartiteGraph.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/matching/BipartiteGraph.java index 95863c5407940fc09a10413e6c7863e5b4191410..371903fdbef229c5727c9ff5e15ea4976ebaf957 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/matching/BipartiteGraph.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/matching/BipartiteGraph.java @@ -1,97 +1,106 @@ package org.oceandsl.tools.restructuring.stages.exec.mapper.matching; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.Set; import java.util.function.Supplier; import org.jgrapht.Graph; import org.jgrapht.GraphType; -public class BipartiteGraph implements Graph<Vertex,Edge> { - private int leftSize; // size of left partition - private int rightSize; // size of right partition - private Map<Vertex, List<Edge>> adjacencyList; // adjacency list representation of graph - - public BipartiteGraph(List<Vertex> leftVertices, List<Vertex> rightVertices) { - this.leftSize = leftVertices.size(); - this.rightSize = rightVertices.size(); - adjacencyList = new HashMap<>(); - for (Vertex vertex : leftVertices) { - adjacencyList.put(vertex, new ArrayList<>()); - } - for (Vertex vertex : rightVertices) { - adjacencyList.put(vertex, new ArrayList<>()); - } - } - - public int getLeftSize() { - return leftSize; - } - - public int getRightSize() { - return rightSize; - } - - public Map<Vertex, List<Edge>> getAdjacencyList(){ - return this.adjacencyList; - } - - public void addEdge(Vertex leftVertex, Vertex rightVertex, double weight) { - if (!adjacencyList.containsKey(leftVertex)) { - throw new IllegalArgumentException("Left vertex not in graph"); - } - if (!adjacencyList.containsKey(rightVertex)) { - throw new IllegalArgumentException("Right vertex not in graph"); - } - Edge edge = new Edge(rightVertex, weight); - adjacencyList.get(leftVertex).add(edge); - Edge reverseEdge = new Edge(leftVertex, weight); - adjacencyList.get(rightVertex).add(reverseEdge); - } - - public List<Edge> getNeighbors(Vertex vertex) { - if (!adjacencyList.containsKey(vertex)) { - throw new IllegalArgumentException("Vertex not in graph"); - } - return adjacencyList.get(vertex); - } - - public boolean isBipartite() { - int[] color = new int[leftSize + rightSize]; - Arrays.fill(color, -1); - for (Vertex vertex : adjacencyList.keySet()) { - if (color[getIndex(vertex)] == -1) { - color[getIndex(vertex)] = 0; - Queue<Vertex> queue = new LinkedList<>(); - queue.offer(vertex); - while (!queue.isEmpty()) { - Vertex curr = queue.poll(); - for (Edge edge : getNeighbors(curr)) { - Vertex neighbor = edge.getVertex(); - if (color[getIndex(neighbor)] == -1) { - color[getIndex(neighbor)] = 1 - color[getIndex(curr)]; - queue.offer(neighbor); - } else if (color[getIndex(neighbor)] == color[getIndex(curr)]) { - return false; - } - } - } - } - } - return true; - } - - private int getIndex(Vertex vertex) { - if (adjacencyList.containsKey(vertex)) { - int index = 0; - for (Vertex v : adjacencyList.keySet()) { - if (v.equals(vertex)) { - return index; - } - index++; - } - } - return -1; - } +@Deprecated +public class BipartiteGraph implements Graph<Vertex, Edge> { + private int leftSize; // size of left partition + private int rightSize; // size of right partition + private Map<Vertex, List<Edge>> adjacencyList; // adjacency list representation of graph + + public BipartiteGraph(List<Vertex> leftVertices, List<Vertex> rightVertices) { + this.leftSize = leftVertices.size(); + this.rightSize = rightVertices.size(); + adjacencyList = new HashMap<>(); + for (Vertex vertex : leftVertices) { + adjacencyList.put(vertex, new ArrayList<>()); + } + for (Vertex vertex : rightVertices) { + adjacencyList.put(vertex, new ArrayList<>()); + } + } + + public int getLeftSize() { + return leftSize; + } + + public int getRightSize() { + return rightSize; + } + + public Map<Vertex, List<Edge>> getAdjacencyList() { + return this.adjacencyList; + } + + public void addEdge(Vertex leftVertex, Vertex rightVertex, double weight) { + if (!adjacencyList.containsKey(leftVertex)) { + throw new IllegalArgumentException("Left vertex not in graph"); + } + if (!adjacencyList.containsKey(rightVertex)) { + throw new IllegalArgumentException("Right vertex not in graph"); + } + Edge edge = new Edge(rightVertex, weight); + adjacencyList.get(leftVertex).add(edge); + Edge reverseEdge = new Edge(leftVertex, weight); + adjacencyList.get(rightVertex).add(reverseEdge); + } + + public List<Edge> getNeighbors(Vertex vertex) { + if (!adjacencyList.containsKey(vertex)) { + throw new IllegalArgumentException("Vertex not in graph"); + } + return adjacencyList.get(vertex); + } + + public boolean isBipartite() { + int[] color = new int[leftSize + rightSize]; + Arrays.fill(color, -1); + for (Vertex vertex : adjacencyList.keySet()) { + if (color[getIndex(vertex)] == -1) { + color[getIndex(vertex)] = 0; + Queue<Vertex> queue = new LinkedList<>(); + queue.offer(vertex); + while (!queue.isEmpty()) { + Vertex curr = queue.poll(); + for (Edge edge : getNeighbors(curr)) { + Vertex neighbor = edge.getVertex(); + if (color[getIndex(neighbor)] == -1) { + color[getIndex(neighbor)] = 1 - color[getIndex(curr)]; + queue.offer(neighbor); + } else if (color[getIndex(neighbor)] == color[getIndex(curr)]) { + return false; + } + } + } + } + } + return true; + } + + private int getIndex(Vertex vertex) { + if (adjacencyList.containsKey(vertex)) { + int index = 0; + for (Vertex v : adjacencyList.keySet()) { + if (v.equals(vertex)) { + return index; + } + index++; + } + } + return -1; + } @Override public Set<Edge> getAllEdges(Vertex sourceVertex, Vertex targetVertex) { @@ -270,8 +279,7 @@ public class BipartiteGraph implements Graph<Vertex,Edge> { @Override public void setEdgeWeight(Edge e, double weight) { // TODO Auto-generated method stub - + } } - diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/matching/Edge.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/matching/Edge.java index 23999d5095bca7fe9b0bb9967094ed2872dd7774..a2bb9c7a8a444959dd8ac86934952847f08e6f25 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/matching/Edge.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/matching/Edge.java @@ -1,13 +1,14 @@ package org.oceandsl.tools.restructuring.stages.exec.mapper.matching; -public class Edge { - private Vertex vertex; - private double weight; +@Deprecated +public class Edge { + private Vertex vertex; + private double weight; - public Edge(Vertex vertex, double weight) { - this.vertex = vertex; - this.weight = weight; - } + public Edge(Vertex vertex, double weight) { + this.vertex = vertex; + this.weight = weight; + } public Vertex getVertex() { return vertex; diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/matching/HungarianAlgorithm.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/matching/HungarianAlgorithm.java index 6ce89dd9aed454169fc2c5163607b50299675ead..0e44a6c55b0d6ebf713effa15142b747e526fa82 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/matching/HungarianAlgorithm.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/matching/HungarianAlgorithm.java @@ -1,12 +1,13 @@ package org.oceandsl.tools.restructuring.stages.exec.mapper.matching; -import java.util.*; -import org.jgrapht.*; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; +import java.util.Queue; +@Deprecated public class HungarianAlgorithm { - - - + public static Map<Vertex, Vertex> getMaximumMatching(BipartiteGraph graph) { Map<Vertex, Vertex> matching = new HashMap<>(); Map<Vertex, Boolean> visited = new HashMap<>(); diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/matching/Vertex.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/matching/Vertex.java index 81b0581390b38262b6bd338e89cabf4b7b7c5c41..7ad35ea48027a057db525abfedd57eac9909abbf 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/matching/Vertex.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/stages/exec/mapper/matching/Vertex.java @@ -2,38 +2,39 @@ package org.oceandsl.tools.restructuring.stages.exec.mapper.matching; import java.util.Objects; - -public class Vertex { - private String name; - - public Vertex(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Vertex vertex = (Vertex) o; - return name.equals(vertex.name); - } - - @Override - public int hashCode() { - return Objects.hash(name); - } - - @Override - public String toString() { - return name; - } +@Deprecated +public class Vertex { + private String name; + + public Vertex(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Vertex vertex = (Vertex) o; + return name.equals(vertex.name); + } + + @Override + public int hashCode() { + return Objects.hash(name); + } + + @Override + public String toString() { + return name; + } } - diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/AbstractTransformationStep.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/AbstractTransformationStep.java index e07cf168bc0ff5ae13153e927012c4ff1b62490d..3e9cd45c2df4a67b3c58c92b5c44472f31fe34db 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/AbstractTransformationStep.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/AbstractTransformationStep.java @@ -4,13 +4,13 @@ import kieker.model.analysismodel.assembly.AssemblyModel; public abstract class AbstractTransformationStep { protected AssemblyModel model; - + public AbstractTransformationStep(AssemblyModel model) { this.model = model; } public AssemblyModel getModel() { return this.model; } - + public abstract void applyTransformation(AssemblyModel model); } diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/AtomicTransformation.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/AtomicTransformation.java index 1ffa95cca6f599d0f3b0c5469d91762b13db309f..683055b359d42598014f05e806960551f15b3e0f 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/AtomicTransformation.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/AtomicTransformation.java @@ -3,12 +3,12 @@ package org.oceandsl.tools.restructuring.transformations; import kieker.model.analysismodel.assembly.AssemblyModel; public abstract class AtomicTransformation extends AbstractTransformationStep { - + public AtomicTransformation(AssemblyModel model) { super(model); // TODO Auto-generated constructor stub } - + } diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/CompositeTransformation.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/CompositeTransformation.java index d7c292a3745cc4dac9630ee093cab61d0ea58faa..27a4dd51012ed780a4814630474e98c8bd19135d 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/CompositeTransformation.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/CompositeTransformation.java @@ -6,20 +6,20 @@ import java.util.List; import kieker.model.analysismodel.assembly.AssemblyModel; public abstract class CompositeTransformation extends AbstractTransformationStep { - + protected List<AbstractTransformationStep> steps; - + public CompositeTransformation(AssemblyModel model) { super(model); - this.steps = new ArrayList<AbstractTransformationStep>(); + this.steps = new ArrayList<>(); // TODO Auto-generated constructor stub } public List<AbstractTransformationStep> getSteps(){ return this.steps; } - - - - + + + + } diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/CreateTransformation.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/CreateTransformation.java index b894357a155e767024882617e5cf5181e412c09b..6c06efd5758c11c48b431a8dc76298148007019e 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/CreateTransformation.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/CreateTransformation.java @@ -1,23 +1,17 @@ package org.oceandsl.tools.restructuring.transformations; -import java.util.AbstractMap; -import java.util.Map; -import java.util.Map.Entry; - -import kieker.model.analysismodel.assembly.AssemblyComponent; import kieker.model.analysismodel.assembly.AssemblyModel; import kieker.model.analysismodel.assembly.impl.AssemblyFactoryImpl; -import kieker.model.system.model.ModelFactory; public class CreateTransformation extends AtomicTransformation { - + private String componentName; AssemblyFactoryImpl fac = new AssemblyFactoryImpl(); public CreateTransformation(AssemblyModel model) { super(model); // TODO Auto-generated constructor stub } - + public void setComponentName(String componentName) { this.componentName = componentName; } @@ -27,16 +21,16 @@ public class CreateTransformation extends AtomicTransformation { } @Override public void applyTransformation(AssemblyModel model) { - + // Entry<String, AssemblyComponent> entry = Map.entry(this.componentName, fac.createAssemblyComponent()); model.getComponents().put(componentName, fac.createAssemblyComponent()); this.model = model; //this.model.getComponents().add(entry); - + } - - - + + + } diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/CutTransformation.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/CutTransformation.java index a290f51b15b9d910da97efd5c5a3be5885b28c90..597d0859fa193d9c8a35e78e4fd3a8ea3407dd34 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/CutTransformation.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/CutTransformation.java @@ -1,50 +1,47 @@ package org.oceandsl.tools.restructuring.transformations; -import java.util.Map.Entry; - -import kieker.model.analysismodel.assembly.AssemblyComponent; import kieker.model.analysismodel.assembly.AssemblyModel; import kieker.model.analysismodel.assembly.AssemblyOperation; import kieker.model.analysismodel.assembly.impl.AssemblyFactoryImpl; public class CutTransformation extends AtomicTransformation { - + private String componentName; private String operationName; private AssemblyOperation operation; private AssemblyFactoryImpl fac = TransformationUtil.ASSEMBLY_MODEL_FACTORY; - + public CutTransformation(AssemblyModel model) { super(model); // TODO Auto-generated constructor stub } - + public void setComponentName(String componentName) { this.componentName = componentName; } - + public void setOperationName(String operationName) { this.operationName = operationName; } - + public AssemblyOperation getOperation() { return this.operation; } - + public String getComponentName() { return this.componentName; } - + public String getOperationName() { return this.operationName; } - + @Override public void applyTransformation(AssemblyModel model) { // System.out.println("cutting" +this.componentName); model.getComponents().get(this.componentName).getOperations().removeKey(this.operationName); this.model = model; - + } } diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/DeleteTransformation.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/DeleteTransformation.java index fb8bec943a30c2097a3e1cb61bfcc59176785c79..1c74bda5b2ab740bba8dfb7f3e71bf99a6ad1af5 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/DeleteTransformation.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/DeleteTransformation.java @@ -4,19 +4,19 @@ import kieker.model.analysismodel.assembly.AssemblyModel; import kieker.model.analysismodel.assembly.impl.AssemblyFactoryImpl; public class DeleteTransformation extends AtomicTransformation{ - + private String componentName; private AssemblyFactoryImpl fac = TransformationUtil.ASSEMBLY_MODEL_FACTORY; - + public DeleteTransformation(AssemblyModel model) { super(model); // TODO Auto-generated constructor stub } - + public void setComponentName(String componentName) { this.componentName = componentName; } - + public String getComponentName() { return this.componentName; } @@ -26,6 +26,6 @@ public class DeleteTransformation extends AtomicTransformation{ this.model = model; } - - + + } diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/FullTransformation.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/FullTransformation.java index 8397106df6da2a0798c4417c45219fc19f376290..19335eabcda31862e961d1e6489babaa72223d29 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/FullTransformation.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/FullTransformation.java @@ -15,7 +15,7 @@ public class FullTransformation extends CompositeTransformation { step.applyTransformation(model); } this.model = model; - + } } diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/MergeTransformation.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/MergeTransformation.java index a874113d26f4f8444fe8f135a1a5c621304640e9..a28c06dc81103e6dc7dd8c42dc3e420ea326409b 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/MergeTransformation.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/MergeTransformation.java @@ -23,19 +23,19 @@ public class MergeTransformation extends CompositeTransformation { } this.model = model; } - + public void add(AbstractTransformationStep step) { this.steps.add(step); } - + public DeleteTransformation getDeleteTransformation() { return (DeleteTransformation)this.steps.get(this.steps.size()-1); } - + public List<AbstractTransformationStep> getMoveTransformations() { - List<AbstractTransformationStep> result = new ArrayList<AbstractTransformationStep>(); + List<AbstractTransformationStep> result = new ArrayList<>(); result.addAll(this.steps); - result.remove(this.steps.size()-1); + result.remove(this.steps.size()-1); return result; } diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/MoveTransformation.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/MoveTransformation.java index 8d92c98f263464b634de6ad73ab4a3f94ee8dc17..cedb45ff1f61a5084ac4f6e0b10b675999e8d851 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/MoveTransformation.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/MoveTransformation.java @@ -21,15 +21,15 @@ public class MoveTransformation extends CompositeTransformation{ } this.model = model; } - + public void add(AbstractTransformationStep transformation) { this.steps.add(transformation); } - + public CutTransformation getCutTransformation() { return (CutTransformation)this.steps.get(0); } - + public PasteTransformation getPasteTransformation() { return (PasteTransformation)this.steps.get(1); } diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/PasteTransformation.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/PasteTransformation.java index 6eb05060a6df55f7a4e85cd1170dd422ba62155d..71a891707783356dbac75440b8c9ef352d88ac48 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/PasteTransformation.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/PasteTransformation.java @@ -10,20 +10,20 @@ public class PasteTransformation extends AtomicTransformation{ private String operationName; private AssemblyOperation operation; AssemblyFactoryImpl fac = new AssemblyFactoryImpl(); - + public PasteTransformation(AssemblyModel model) { super(model); // TODO Auto-generated constructor stub } - + public void setComponentName(String componentName) { this.componentName = componentName; } - + public void setOperationName(String operationName) { this.operationName = operationName; } - + public AssemblyOperation getOperation() { return this.operation; } @@ -31,13 +31,13 @@ public class PasteTransformation extends AtomicTransformation{ public String getComponentName() { return this.componentName; } - + public String getOperationName() { return this.operationName; } @Override public void applyTransformation(AssemblyModel model) { - model.getComponents().get(this.componentName).getOperations().put(this.operationName, fac.createAssemblyOperation()); + model.getComponents().get(this.componentName).getOperations().put(this.operationName, fac.createAssemblyOperation()); this.model = model; //System.out.println("x"); } diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/SplitTransformation.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/SplitTransformation.java index 639e21e38e13a40bbdbd93c2a7a01a514b3b2c71..ab9665a3d00ffc16c1be1135cf475a993d8d71e7 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/SplitTransformation.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/SplitTransformation.java @@ -8,15 +8,15 @@ import kieker.model.analysismodel.assembly.AssemblyModel; public class SplitTransformation extends CompositeTransformation { - - + + public SplitTransformation(AssemblyModel model) { super(model); // TODO Auto-generated constructor stub } - + @Override public void applyTransformation(AssemblyModel model) { //TODO CHEC IF THE LIST FORMAT IS APPROPRIETE @@ -26,21 +26,21 @@ public class SplitTransformation extends CompositeTransformation { } this.model= model; } - + public void add(AbstractTransformationStep step) { this.steps.add(step); } - + public CreateTransformation getCreateTransformation() { return (CreateTransformation)this.steps.get(0); } - + public List<AbstractTransformationStep> getMoveTransformation(){ - List<AbstractTransformationStep> result = new ArrayList<AbstractTransformationStep>(); + List<AbstractTransformationStep> result = new ArrayList<>(); result.addAll(this.steps); result.remove(0); return result; - + } } diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/TransformationUtil.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/TransformationUtil.java index ebcec3474392ade15d023a4301b8d07120a6e184..47a42ef6cc19c64263a373ed65f8d4291cadd486 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/TransformationUtil.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/transformations/TransformationUtil.java @@ -1,11 +1,5 @@ package org.oceandsl.tools.restructuring.transformations; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -import kieker.model.analysismodel.assembly.AssemblyComponent; -import kieker.model.analysismodel.assembly.AssemblyOperation; import kieker.model.analysismodel.assembly.impl.AssemblyFactoryImpl; public class TransformationUtil { diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/util/RestructurerTools.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/util/RestructurerTools.java index 00be6b29d5202e03b14adc11dcca027778d52ce4..03888f31787f1816ff86e3c61b368eb4bb1635d3 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/util/RestructurerTools.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/util/RestructurerTools.java @@ -2,7 +2,6 @@ package org.oceandsl.tools.restructuring.util; import java.util.Map.Entry; - import kieker.model.analysismodel.assembly.AssemblyComponent; import kieker.model.analysismodel.assembly.AssemblyFactory; import kieker.model.analysismodel.assembly.AssemblyModel; @@ -10,43 +9,40 @@ import kieker.model.analysismodel.assembly.AssemblyOperation; public class RestructurerTools { - public static AssemblyModel cloneModel(AssemblyModel model) { AssemblyFactory factory = AssemblyFactory.eINSTANCE; AssemblyModel result = factory.createAssemblyModel(); - - for(Entry<String, AssemblyComponent> e:model.getComponents().entrySet()) { + + for (Entry<String, AssemblyComponent> e : model.getComponents().entrySet()) { AssemblyComponent comp = factory.createAssemblyComponent(); result.getComponents().put(e.getKey(), comp); - for(Entry<String, AssemblyOperation>op: e.getValue().getOperations().entrySet()) { + for (Entry<String, AssemblyOperation> op : e.getValue().getOperations().entrySet()) { AssemblyOperation o = factory.createAssemblyOperation(); result.getComponents().get(e.getKey()).getOperations().put(op.getKey(), o); } } if (!TransformationFactory.areSameModels(model, result)) throw new Error("Models were not clonned succesfully!"); - - + return result; } - + public static AssemblyModel alterComponentNames(AssemblyModel model) { - String prefix = "_"; + String prefix = "_"; AssemblyFactory factory = AssemblyFactory.eINSTANCE; AssemblyModel result = factory.createAssemblyModel(); - - for(Entry<String, AssemblyComponent> e:model.getComponents().entrySet()) { + + for (Entry<String, AssemblyComponent> e : model.getComponents().entrySet()) { AssemblyComponent comp = factory.createAssemblyComponent(); - result.getComponents().put(prefix +e.getKey(), comp); - for(Entry<String, AssemblyOperation>op: e.getValue().getOperations().entrySet()) { + result.getComponents().put(prefix + e.getKey(), comp); + for (Entry<String, AssemblyOperation> op : e.getValue().getOperations().entrySet()) { AssemblyOperation o = factory.createAssemblyOperation(); result.getComponents().get(e.getKey()).getOperations().put(op.getKey(), o); } } if (!TransformationFactory.areSameModels(model, result)) throw new Error("Models were not clonned succesfully!"); - - + return result; } } diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/util/TransformationFactory.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/util/TransformationFactory.java index 4154258b5168ee887d8296673ac7050463a27fb7..a9ed19851c2c646b3d993236f45ef88ddbc72dfa 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/util/TransformationFactory.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/util/TransformationFactory.java @@ -1,8 +1,8 @@ package org.oceandsl.tools.restructuring.util; import java.util.HashSet; -import java.util.List; import java.util.Map.Entry; +import java.util.Set; import org.oceandsl.tools.restructuring.transformations.CreateTransformation; import org.oceandsl.tools.restructuring.transformations.CutTransformation; @@ -12,8 +12,6 @@ import org.oceandsl.tools.restructuring.transformations.MoveTransformation; import org.oceandsl.tools.restructuring.transformations.PasteTransformation; import org.oceandsl.tools.restructuring.transformations.SplitTransformation; -import java.util.Set; - import kieker.model.analysismodel.assembly.AssemblyComponent; import kieker.model.analysismodel.assembly.AssemblyModel; @@ -63,64 +61,61 @@ public class TransformationFactory { result.add(to); return result; + } + + public static SplitTransformation createSplitTransformation(String componentOld, String componentNew, + String operationName, AssemblyModel model) { + CreateTransformation newComponent = createCreateTransformation(componentNew, model); + MoveTransformation to = createMoveTransformation(componentOld, componentNew, operationName, model); + + SplitTransformation result = new SplitTransformation(model); + result.add(newComponent); + result.add(to); + + return result; } - public static SplitTransformation createSplitTransformation(String componentOld, String componentNew, String operationName, AssemblyModel model) { - - CreateTransformation newComponent = createCreateTransformation(componentNew, model); - MoveTransformation to = createMoveTransformation(componentOld, componentNew, operationName, model); - - SplitTransformation result = new SplitTransformation(model); - result.add(newComponent); - result.add(to); - return result; - - - -} + public static MergeTransformation createMergeTransformation(String componentOld, String componentNew, + String operationName, AssemblyModel model) { + + DeleteTransformation newComponent = createDeleteTransformation(componentNew, model); + MoveTransformation to = createMoveTransformation(componentOld, componentNew, operationName, model); + + MergeTransformation result = new MergeTransformation(model); + result.add(newComponent); + result.add(to); + + return result; + } - public static MergeTransformation createMergeTransformation(String componentOld, String componentNew, String operationName, AssemblyModel model) { - - DeleteTransformation newComponent = createDeleteTransformation(componentNew, model); - MoveTransformation to = createMoveTransformation(componentOld, componentNew, operationName, model); - - MergeTransformation result = new MergeTransformation(model); - result.add(newComponent); - result.add(to); - return result; - - - -} public static boolean areSameComponents(AssemblyComponent a, AssemblyComponent b) { Set<String> opsA = a.getOperations().keySet(); Set<String> opsB = b.getOperations().keySet(); + return new HashSet<>(opsA).equals(new HashSet<>(opsB)); } - + public static boolean containsComponent(AssemblyModel model, AssemblyComponent b) { - - for(Entry<String, AssemblyComponent> e : model.getComponents().entrySet()) { - if(areSameComponents(e.getValue(),b)) { + for (Entry<String, AssemblyComponent> e : model.getComponents().entrySet()) { + if (areSameComponents(e.getValue(), b)) { return true; } } return false; } - - public static boolean areSameModels(AssemblyModel a , AssemblyModel b) { - if(a.getComponents().size()!=b.getComponents().size()) { + + public static boolean areSameModels(AssemblyModel a, AssemblyModel b) { + if (a.getComponents().size() != b.getComponents().size()) { return false; } - for(Entry<String, AssemblyComponent> e : b.getComponents().entrySet()) { - if(!containsComponent(a, e.getValue())) { + for (Entry<String, AssemblyComponent> e : b.getComponents().entrySet()) { + if (!containsComponent(a, e.getValue())) { return false; } } - - + return true; } } diff --git a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/util/WriteModelUtils.java b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/util/WriteModelUtils.java index be283f2958199ed4fff38dfbe3af43b6d36bf335..3d8fd622606bff4084233cf4856c71d7cdad1ab5 100644 --- a/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/util/WriteModelUtils.java +++ b/tools/restructuring/src/main/java/org/oceandsl/tools/restructuring/util/WriteModelUtils.java @@ -17,55 +17,50 @@ import org.oceandsl.analysis.architecture.ArchitectureModelManagementUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import restructuremodel.ComponentsTransformation; public class WriteModelUtils { private static final Logger LOGGER = LoggerFactory.getLogger(ArchitectureModelManagementUtils.class); - - - public static void writeModelRepository(final Path outputDirectory, ComponentsTransformation model) - throws IOException { + private static final String OUTPUT_MODEL_NAME = "outputmodel.xmi"; - final Resource.Factory.Registry registry = Resource.Factory.Registry.INSTANCE; - final Map<String, Object> extensionToFactoryMap = registry.getExtensionToFactoryMap(); - extensionToFactoryMap.put("xmi", new XMIResourceFactoryImpl()); + public static void writeModelRepository(final Path outputDirectory, ComponentsTransformation model) + throws IOException { - // store models - final ResourceSet resourceSet = new ResourceSetImpl(); - //resourceSet.setResourceFactoryRegistry(registry); - //resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi",new XMIResourceFactoryImpl()); - if (!Files.exists(outputDirectory)) { - Files.createDirectory(outputDirectory); - } + final Resource.Factory.Registry registry = Resource.Factory.Registry.INSTANCE; + final Map<String, Object> extensionToFactoryMap = registry.getExtensionToFactoryMap(); + extensionToFactoryMap.put("xmi", new XMIResourceFactoryImpl()); - writeModel(resourceSet, outputDirectory, - "outputmodel.xmi", model); + // store models + final ResourceSet resourceSet = new ResourceSetImpl(); + // resourceSet.setResourceFactoryRegistry(registry); + // resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi",new + // XMIResourceFactoryImpl()); + if (!Files.exists(outputDirectory)) { + Files.createDirectory(outputDirectory); + } - } + writeModel(resourceSet, outputDirectory, OUTPUT_MODEL_NAME, model); - private static <T extends EObject> void writeModel(final ResourceSet resourceSet, final Path outputDirectory, - final String filename, final T model) { - LOGGER.info("Saving model {}", filename); + } - final File modelFile = createWriteModelFileHandle(outputDirectory, filename); + private static <T extends EObject> void writeModel(final ResourceSet resourceSet, final Path outputDirectory, + final String filename, final T model) { + LOGGER.info("Saving model {}", filename); - final Resource resource = resourceSet.createResource(URI.createFileURI(modelFile.getAbsolutePath())); - resource.getContents().add(model); + final File modelFile = createWriteModelFileHandler(outputDirectory, filename); - try { - resource.save(Collections.EMPTY_MAP); - } catch (final IOException e) { - LOGGER.error("Cannot write {} model to storage. Cause: {}", - modelFile.getAbsoluteFile(), e.getLocalizedMessage()); - } - } + final Resource resource = resourceSet.createResource(URI.createFileURI(modelFile.getAbsolutePath())); + resource.getContents().add(model); - private static File createReadModelFileHandle(final Path path, final String filename) { - return new File(path.toString() + File.separator + filename); - } + try { + resource.save(Collections.EMPTY_MAP); + } catch (final IOException e) { + LOGGER.error("Cannot write {} model to storage. Cause: {}", modelFile.getAbsoluteFile(), + e.getLocalizedMessage()); + } + } - private static File createWriteModelFileHandle(final Path path, final String filename) { - return new File(path.toFile().getAbsolutePath() + File.separator + filename); - } + private static File createWriteModelFileHandler(final Path path, final String filename) { + return new File(path.toFile().getAbsolutePath() + File.separator + filename); + } }