From e29ecec356824559333aaab1a9cc5142bc44179d Mon Sep 17 00:00:00 2001 From: rafaelrabetti Date: Fri, 29 Sep 2017 20:05:32 -0300 Subject: [PATCH 01/18] =?UTF-8?q?RDGNode:=20M=C3=A9todo=20Longo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Operação: Extrair método. Condicional longa e complexa. Resultados: Criação de novos métodos substituindo as condicionais. Signed-off-by: rafaelrabetti --- src/tool/RDGNode.java | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/tool/RDGNode.java b/src/tool/RDGNode.java index 180097c..444c348 100644 --- a/src/tool/RDGNode.java +++ b/src/tool/RDGNode.java @@ -100,15 +100,31 @@ public static String getNextId() { */ @Override public boolean equals(Object obj) { - if (obj != null && obj instanceof RDGNode) { + if (notNullAndSameInstance(obj)) { RDGNode other = (RDGNode) obj; - return this.getPresenceCondition().equals(other.getPresenceCondition()) - && this.getFDTMC().equals(other.getFDTMC()) - && this.getDependencies().equals(other.getDependencies()); + return hasSamePresenceCondition(other) + && hasSameFDTMC(other) + && hasSameDependencies(other); } return false; } + private boolean notNullAndSameInstance(Object obj) { + return obj != null && obj instanceof RDGNode; + } + + private boolean hasSameDependencies(RDGNode other) { + return this.getDependencies().equals(other.getDependencies()); + } + + private boolean hasSameFDTMC(RDGNode other) { + return this.getFDTMC().equals(other.getFDTMC()); + } + + private boolean hasSamePresenceCondition(RDGNode other) { + return this.getPresenceCondition().equals(other.getPresenceCondition()); + } + @Override public int hashCode() { return id.hashCode() + presenceCondition.hashCode() + fdtmc.hashCode() + dependencies.hashCode(); From ee92ba2d2a24ab5a6d5a99a0b5727566ad97f084 Mon Sep 17 00:00:00 2001 From: eduqg Date: Fri, 29 Sep 2017 20:22:36 -0300 Subject: [PATCH 02/18] =?UTF-8?q?Extra=C3=A7=C3=A3o=20de=20m=C3=A9todos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/paramwrapper/ParamModel.java | 38 +++++++++++++++++++------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/paramwrapper/ParamModel.java b/src/paramwrapper/ParamModel.java index ddd77e4..670e9bd 100644 --- a/src/paramwrapper/ParamModel.java +++ b/src/paramwrapper/ParamModel.java @@ -103,14 +103,7 @@ public String toString() { for (String parameter : parameters) { params += "param double "+parameter+";\n"; } - String module = - "dtmc\n" + - "\n" + - params + - "\n" + - "module " + moduleName + "\n" + - " "+stateVariable+ " : ["+stateRangeStart+".."+stateRangeEnd+"] init "+initialState+";" + - "\n"; + String module = moduleString(params); for (Command command : commands.values()) { module += " "+command.makeString(stateVariable) + "\n"; } @@ -121,17 +114,32 @@ public String toString() { Set states = entry.getValue(); int count = 1; - for (Integer state : states) { - module += stateVariable+"="+state; - if (count < states.size()) { - module += " | "; - } - count++; - } + module = changeModuleState(module, states, count); module += ";\n"; } return module; } + + private String changeModuleState(String module, Set states, int count) { + for (Integer state : states) { + module += stateVariable+"="+state; + if (count < states.size()) { + module += " | "; + } + count++; + } + return module; + } + + private String moduleString(String params) { + return "dtmc\n" + + "\n" + + params + + "\n" + + "module " + moduleName + "\n" + + " "+stateVariable+ " : ["+stateRangeStart+".."+stateRangeEnd+"] init "+initialState+";" + + "\n"; + } } class Command { From 485e9c10417779c0d3527d40d4575ca815df14d2 Mon Sep 17 00:00:00 2001 From: rafaelrabetti Date: Fri, 29 Sep 2017 20:23:20 -0300 Subject: [PATCH 03/18] =?UTF-8?q?RDGNode:=20M=C3=A9todo=20longo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Operação: Extrair métodos de loops. Resultados: Criação de novos métodos deixando o método menor. Signed-off-by: rafaelrabetti --- src/tool/RDGNode.java | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/tool/RDGNode.java b/src/tool/RDGNode.java index 444c348..cbed6ac 100644 --- a/src/tool/RDGNode.java +++ b/src/tool/RDGNode.java @@ -165,15 +165,20 @@ private void topoSortVisit(RDGNode node, Map marks, List marks, List sorted) + throws CyclicRdgException { + for (RDGNode child: node.getDependencies()) { + topoSortVisit(child, marks, sorted); + } + } + /** * Computes the number of paths from source nodes to every known node. * @return A map associating an RDGNode to the corresponding number @@ -205,10 +210,7 @@ private static Map numPathsVisit(RDGNode node, Map tmpNumberOfPaths = numPathsVisit(child, marks, cache); - numberOfPaths = sumPaths(numberOfPaths, tmpNumberOfPaths); - } + numberOfPaths = getDependenciesForEachChild(node, marks, cache, numberOfPaths); // Mark node permanently (finished sorting branch) marks.put(node, true); cache.put(node, numberOfPaths); @@ -218,6 +220,15 @@ private static Map numPathsVisit(RDGNode node, Map getDependenciesForEachChild(RDGNode node, Map marks, + Map> cache, Map numberOfPaths) throws CyclicRdgException { + for (RDGNode child: node.getDependencies()) { + Map tmpNumberOfPaths = numPathsVisit(child, marks, cache); + numberOfPaths = sumPaths(numberOfPaths, tmpNumberOfPaths); + } + return numberOfPaths; + } + /** * Sums two paths-counting maps * @param pathsCountA @@ -226,7 +237,13 @@ private static Map numPathsVisit(RDGNode node, Map sumPaths(Map pathsCountA, Map pathsCountB) { Map numberOfPaths = new HashMap(pathsCountA); - for (Map.Entry entry: pathsCountB.entrySet()) { + pathsCountBEntrySetForEachEntry(pathsCountB, numberOfPaths); + return numberOfPaths; + } + + private static void pathsCountBEntrySetForEachEntry(Map pathsCountB, + Map numberOfPaths) { + for (Map.Entry entry: pathsCountB.entrySet()) { RDGNode node = entry.getKey(); Integer count = entry.getValue(); if (numberOfPaths.containsKey(node)) { @@ -234,8 +251,7 @@ private static Map sumPaths(Map pathsCountA, } numberOfPaths.put(node, count); } - return numberOfPaths; - } + } /** * Returns the first RDG node (in crescent order of creation time) which is similar From 0edec0099d1b19566142e864396dc4b8b567e889 Mon Sep 17 00:00:00 2001 From: rafaelrabetti Date: Fri, 29 Sep 2017 20:30:21 -0300 Subject: [PATCH 04/18] =?UTF-8?q?RDGNode:=20M=C3=A9todo=20Longo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Operação: Extrair método. Condicional longa e complexa. Resultados: Criação de novos métodos substituindo as condicionais. Signed-off-by: rafaelrabetti --- src/tool/RDGNode.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/tool/RDGNode.java b/src/tool/RDGNode.java index cbed6ac..72738e1 100644 --- a/src/tool/RDGNode.java +++ b/src/tool/RDGNode.java @@ -159,10 +159,10 @@ public List getDependenciesTransitiveClosure() throws CyclicRdgExceptio * @throws CyclicRdgException */ private void topoSortVisit(RDGNode node, Map marks, List sorted) throws CyclicRdgException { - if (marks.containsKey(node) && marks.get(node) == false) { + if (containsKeyAndNotHaveNode(node, marks)) { // Visiting temporarily marked node -- this means a cyclic dependency! throw new CyclicRdgException(); - } else if (!marks.containsKey(node)) { + } else if (doesNotContainKey(node, marks)) { // Mark node temporarily (cycle detection) marks.put(node, false); getDependenciesForEachChild(node, marks, sorted); @@ -172,6 +172,10 @@ private void topoSortVisit(RDGNode node, Map marks, List marks) { + return !marks.containsKey(node); + } + private void getDependenciesForEachChild(RDGNode node, Map marks, List sorted) throws CyclicRdgException { for (RDGNode child: node.getDependencies()) { @@ -198,10 +202,10 @@ public Map getNumberOfPaths() throws CyclicRdgException { // TODO Parameterize topological sort of RDG. private static Map numPathsVisit(RDGNode node, Map marks, Map> cache) throws CyclicRdgException { - if (marks.containsKey(node) && marks.get(node) == false) { + if (containsKeyAndNotHaveNode(node, marks)) { // Visiting temporarily marked node -- this means a cyclic dependency! throw new CyclicRdgException(); - } else if (!marks.containsKey(node)) { + } else if (doesNotContainKey(node, marks)) { // Mark node temporarily (cycle detection) marks.put(node, false); @@ -220,6 +224,10 @@ private static Map numPathsVisit(RDGNode node, Map marks) { + return marks.containsKey(node) && marks.get(node) == false; + } + private static Map getDependenciesForEachChild(RDGNode node, Map marks, Map> cache, Map numberOfPaths) throws CyclicRdgException { for (RDGNode child: node.getDependencies()) { From be46f2daf4f41769a18c2576f95af9c167215818 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 29 Sep 2017 20:35:30 -0300 Subject: [PATCH 05/18] extract method --- src/fdtmc/Interface.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/fdtmc/Interface.java b/src/fdtmc/Interface.java index f6cd969..0582b49 100644 --- a/src/fdtmc/Interface.java +++ b/src/fdtmc/Interface.java @@ -53,15 +53,19 @@ public String getAbstractedId() { public boolean equals(Object obj) { if (obj != null && obj instanceof Interface) { Interface other = (Interface) obj; - return initial.equals(other.initial) - && success.equals(other.success) - && error.equals(other.error) - && successTransition.equals(other.successTransition) - && errorTransition.equals(other.errorTransition); + return compareInterfaceAtributtes(other); } return false; } + private boolean compareInterfaceAtributtes(Interface other) { + return initial.equals(other.initial) + && success.equals(other.success) + && error.equals(other.error) + && successTransition.equals(other.successTransition) + && errorTransition.equals(other.errorTransition); + } + @Override public int hashCode() { return initial.hashCode() From b624f735420bd0bd6563c47c4b83ace15d887b66 Mon Sep 17 00:00:00 2001 From: eduqg Date: Fri, 29 Sep 2017 20:44:13 -0300 Subject: [PATCH 06/18] Extraindo metodo de escrita de arquivo e condicional de tipo de modelo --- src/paramwrapper/ParamWrapper.java | 46 ++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/src/paramwrapper/ParamWrapper.java b/src/paramwrapper/ParamWrapper.java index 1b34cb8..f975497 100644 --- a/src/paramwrapper/ParamWrapper.java +++ b/src/paramwrapper/ParamWrapper.java @@ -49,28 +49,16 @@ private String evaluate(String model, String property) { try { File modelFile = File.createTempFile("model", "param"); FileWriter modelWriter = new FileWriter(modelFile); - modelWriter.write(model); - modelWriter.flush(); - modelWriter.close(); + writeAndFlushFile(modelFile, modelWriter, model); File propertyFile = File.createTempFile("property", "prop"); FileWriter propertyWriter = new FileWriter(propertyFile); - propertyWriter.write(property); - propertyWriter.flush(); - propertyWriter.close(); + writeAndFlushFile(propertyFile, propertyWriter, property); File resultsFile = File.createTempFile("result", null); String formula; - if (usePrism && !model.contains("param")) { - formula = invokeModelChecker(modelFile.getAbsolutePath(), - propertyFile.getAbsolutePath(), - resultsFile.getAbsolutePath()); - } else { - formula = invokeParametricModelChecker(modelFile.getAbsolutePath(), - propertyFile.getAbsolutePath(), - resultsFile.getAbsolutePath()); - } + formula = invokeTypeModelChecker(model, modelFile, propertyFile, resultsFile); return formula.trim().replaceAll("\\s+", ""); } catch (IOException e) { LOGGER.log(Level.SEVERE, e.toString(), e); @@ -78,6 +66,34 @@ private String evaluate(String model, String property) { return ""; } + private String invokeTypeModelChecker(String model, + File modelFile, + File propertyFile, + File resultsFile) throws IOException { + String formula; + if (usePrism && !model.contains("param")) { + formula = invokeModelChecker(modelFile.getAbsolutePath(), + propertyFile.getAbsolutePath(), + resultsFile.getAbsolutePath()); + } else { + formula = invokeParametricModelChecker(modelFile.getAbsolutePath(), + propertyFile.getAbsolutePath(), + resultsFile.getAbsolutePath()); + } + return formula; + } + + private void writeAndFlushFile(File file, FileWriter writer, String model) { + try { + writer.write(model); + writer.flush(); + writer.close(); + } catch (IOException e) { + LOGGER.log(Level.SEVERE, e.toString(), e); + } + + } + private String invokeParametricModelChecker(String modelPath, String propertyPath, String resultsPath) throws IOException { From b42527a6ab83351ca5670b591c27fb05f02673cc Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 29 Sep 2017 20:47:08 -0300 Subject: [PATCH 07/18] Implementing extract method techinique --- src/fdtmc/FDTMC.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/fdtmc/FDTMC.java b/src/fdtmc/FDTMC.java index ef21282..b2fd176 100644 --- a/src/fdtmc/FDTMC.java +++ b/src/fdtmc/FDTMC.java @@ -206,17 +206,22 @@ public String toString() { List transitionList = this.transitionSystem.get(temp); if (transitionList != null) { Iterator itTransitions = transitionList.iterator(); - while (itTransitions.hasNext()) { - Transition t = itTransitions.next(); - msg += temp.getVariableName() + "=" + temp.getIndex() + ((temp.getLabel() != null) ? "(" + temp.getLabel() + ")" : "") + - " --- " + t.getActionName() + " / " + t.getProbability() + - " ---> " + t.getTarget().getVariableName() + "=" + t.getTarget().getIndex() + ((t.getTarget().getLabel() != null) ? "(" + t.getTarget().getLabel() + ")" : "") + "\n"; - } + msg = creteStateMessage(msg, temp, itTransitions); } } return msg; } + private String creteStateMessage(String msg, State temp, Iterator itTransitions) { + while (itTransitions.hasNext()) { + Transition t = itTransitions.next(); + msg += temp.getVariableName() + "=" + temp.getIndex() + ((temp.getLabel() != null) ? "(" + temp.getLabel() + ")" : "") + + " --- " + t.getActionName() + " / " + t.getProbability() + + " ---> " + t.getTarget().getVariableName() + "=" + t.getTarget().getIndex() + ((t.getTarget().getLabel() != null) ? "(" + t.getTarget().getLabel() + ")" : "") + "\n"; + } + return msg; + } + /** * Two FDTMCs are deemed equal whenever: * - their states are equal; From 3d0717ca1932eaf4ad998c6cc3e6efa4ac497e64 Mon Sep 17 00:00:00 2001 From: eduqg Date: Fri, 29 Sep 2017 20:50:19 -0300 Subject: [PATCH 08/18] =?UTF-8?q?Extraindo=20m=C3=A9todos=20para=20simplic?= =?UTF-8?q?ar=20declaracoes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/paramwrapper/FDTMCToParamTest.java | 47 +++++++++++++++---------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/test/paramwrapper/FDTMCToParamTest.java b/test/paramwrapper/FDTMCToParamTest.java index f3ddcaa..c2e4fc7 100644 --- a/test/paramwrapper/FDTMCToParamTest.java +++ b/test/paramwrapper/FDTMCToParamTest.java @@ -26,15 +26,18 @@ public void testSingletonFDTMC() { State s = singletonFDTMC.createState(); singletonFDTMC.createTransition(s, s, null, "1"); - String expectedModule = - "dtmc\n" + String expectedModule = stringExpectedModule(); + + assertEquals(expectedModule, paramWrapper.fdtmcToParam(singletonFDTMC)); + } + + private String stringExpectedModule() { + return "dtmc\n" + "\n\n" + "module dummyModule\n" + " s : [0..1] init 0;\n" + " [] s=0 -> (1) : (s'=0);\n" + "endmodule\n\n"; - - assertEquals(expectedModule, paramWrapper.fdtmcToParam(singletonFDTMC)); } @Test @@ -44,8 +47,13 @@ public void testSingletonFDTMCWithLabel() { State s = singletonFDTMC.createState("success"); singletonFDTMC.createTransition(s, s, null, "1"); - String expectedModule = - "dtmc\n" + String expectedModule = stringExpectedModuleWithLabel(); + + assertEquals(expectedModule, paramWrapper.fdtmcToParam(singletonFDTMC)); + } + + private String stringExpectedModuleWithLabel() { + return "dtmc\n" + "\n\n" + "module dummyModule\n" + " s : [0..1] init 0;\n" @@ -53,8 +61,6 @@ public void testSingletonFDTMCWithLabel() { + "endmodule\n" + "\n" + "label \"success\" = s=0;\n"; - - assertEquals(expectedModule, paramWrapper.fdtmcToParam(singletonFDTMC)); } @Test @@ -67,8 +73,13 @@ public void testSimpleFDTMCWithParameters() { fdtmc.createTransition(s0, s1, null, "1-rLoop"); fdtmc.createTransition(s1, s1, null, "1"); - String expectedModule = - "dtmc\n" + String expectedModule = stringExpectedModuleWithParams(); + + assertEquals(expectedModule, paramWrapper.fdtmcToParam(fdtmc)); + } + + private String stringExpectedModuleWithParams() { + return "dtmc\n" + "\n" + "param double rLoop;\n" + "\n" @@ -77,11 +88,8 @@ public void testSimpleFDTMCWithParameters() { + " [] s=0 -> (rLoop) : (s'=0) + (1-rLoop) : (s'=1);\n" + " [] s=1 -> (1) : (s'=1);\n" + "endmodule\n\n"; - - assertEquals(expectedModule, paramWrapper.fdtmcToParam(fdtmc)); } - @Test public void testSimpleFDTMCWithParametersAndLabels() { FDTMC fdtmc = new FDTMC(); @@ -97,8 +105,13 @@ public void testSimpleFDTMCWithParametersAndLabels() { fdtmc.createTransition(s2, s2, null, "1"); fdtmc.createTransition(s3, s3, null, "1"); - String expectedModule = - "dtmc\n" + String expectedModule = stringExpectedModuleWithParamsAndLabels(); + + assertEquals(expectedModule, paramWrapper.fdtmcToParam(fdtmc)); + } + + private String stringExpectedModuleWithParamsAndLabels() { + return "dtmc\n" + "\n" + "param double rFail;\n" + "param double rLoop;\n" @@ -113,9 +126,5 @@ public void testSimpleFDTMCWithParametersAndLabels() { + "\n" + "label \"error\" = s=3;\n" + "label \"success\" = s=1 | s=2;\n"; - - assertEquals(expectedModule, paramWrapper.fdtmcToParam(fdtmc)); } - - // Many states with one label } From b4bbfef3328a472258bce857b9e8127164a3cc07 Mon Sep 17 00:00:00 2001 From: rafaelrabetti Date: Fri, 29 Sep 2017 20:56:41 -0300 Subject: [PATCH 09/18] RDGNode: Classe de dados e Classe inchada MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Operação: Extrair classe. Resultados: Foi criada uma classe que contém os dados e os getters e setters e assim o tamanho da classe original diminuiu. Signed-off-by: rafaelrabetti --- src/tool/RDGNode.java | 73 +++++++++------------------------------ src/tool/RDGNodeData.java | 63 +++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 56 deletions(-) create mode 100644 src/tool/RDGNodeData.java diff --git a/src/tool/RDGNode.java b/src/tool/RDGNode.java index 72738e1..c6a927e 100644 --- a/src/tool/RDGNode.java +++ b/src/tool/RDGNode.java @@ -17,21 +17,7 @@ public class RDGNode { private static int lastNodeIndex = 0; - // Node identifier - private String id; - //This attribute is used to store the FDTMC for the RDG node. - private FDTMC fdtmc; - /** - * The node must have an associated presence condition, which is - * a boolean expression over features. - */ - private String presenceCondition; - // Nodes on which this one depends - private Collection dependencies; - /** - * Height of the RDGNode. - */ - private int height; + private RDGNodeData data = new RDGNodeData(); /** @@ -45,45 +31,20 @@ public class RDGNode { * this node. */ public RDGNode(String id, String presenceCondition, FDTMC fdtmc) { - this.id = id; - this.presenceCondition = presenceCondition; - this.fdtmc = fdtmc; - this.dependencies = new HashSet(); - this.height = 0; + this.data.setId(id); + this.data.setPresenceCondition(presenceCondition); + this.data.setFdtmc(fdtmc); + this.data.setDependencies(new HashSet()); + this.data.setHeight(0); rdgNodes.put(id, this); nodesInCreationOrder.add(this); } - public FDTMC getFDTMC() { - return this.fdtmc; - } - - public void addDependency(RDGNode child) { - this.dependencies.add(child); - height = Math.max(height, child.height + 1); - } - - public Collection getDependencies() { - return dependencies; - } - - public String getPresenceCondition() { - return presenceCondition; - } - - public String getId() { - return id; - } - - /** - * Height of the RDGNode. This metric is defined in the same way as - * the height of a tree node, i.e., the maximum number of nodes in a path - * from this one to a leaf (node with no dependencies). - */ - public int getHeight() { - return height; - } + public void addDependency(RDGNode child) { + this.data.dependencies.add(child); + data.height = Math.max(data.height, child.data.height + 1); + } public static RDGNode getById(String id) { return rdgNodes.get(id); @@ -114,25 +75,25 @@ private boolean notNullAndSameInstance(Object obj) { } private boolean hasSameDependencies(RDGNode other) { - return this.getDependencies().equals(other.getDependencies()); + return this.data.getDependencies().equals(other.data.getDependencies()); } private boolean hasSameFDTMC(RDGNode other) { - return this.getFDTMC().equals(other.getFDTMC()); + return this.data.getFdtmc().equals(other.data.getFdtmc()); } private boolean hasSamePresenceCondition(RDGNode other) { - return this.getPresenceCondition().equals(other.getPresenceCondition()); + return this.data.getPresenceCondition().equals(other.data.getPresenceCondition()); } @Override public int hashCode() { - return id.hashCode() + presenceCondition.hashCode() + fdtmc.hashCode() + dependencies.hashCode(); + return data.id.hashCode() + data.presenceCondition.hashCode() + data.fdtmc.hashCode() + data.dependencies.hashCode(); } @Override public String toString() { - return getId() + " (" + getPresenceCondition() + ")"; + return data.getId() + " (" + data.getPresenceCondition() + ")"; } /** @@ -178,7 +139,7 @@ private static boolean doesNotContainKey(RDGNode node, Map mar private void getDependenciesForEachChild(RDGNode node, Map marks, List sorted) throws CyclicRdgException { - for (RDGNode child: node.getDependencies()) { + for (RDGNode child: node.data.getDependencies()) { topoSortVisit(child, marks, sorted); } } @@ -230,7 +191,7 @@ private static boolean containsKeyAndNotHaveNode(RDGNode node, Map getDependenciesForEachChild(RDGNode node, Map marks, Map> cache, Map numberOfPaths) throws CyclicRdgException { - for (RDGNode child: node.getDependencies()) { + for (RDGNode child: node.data.getDependencies()) { Map tmpNumberOfPaths = numPathsVisit(child, marks, cache); numberOfPaths = sumPaths(numberOfPaths, tmpNumberOfPaths); } diff --git a/src/tool/RDGNodeData.java b/src/tool/RDGNodeData.java new file mode 100644 index 0000000..7673665 --- /dev/null +++ b/src/tool/RDGNodeData.java @@ -0,0 +1,63 @@ +package tool; + +import java.util.Collection; + +import fdtmc.FDTMC; + +public class RDGNodeData { + public String id; + public FDTMC fdtmc; + /** + * The node must have an associated presence condition, which is + * a boolean expression over features. + */ + public String presenceCondition; + public Collection dependencies; + /** + * Height of the RDGNode. + */ + public int height; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public FDTMC getFdtmc() { + return fdtmc; + } + + public void setFdtmc(FDTMC fdtmc) { + this.fdtmc = fdtmc; + } + + public String getPresenceCondition() { + return presenceCondition; + } + + public void setPresenceCondition(String presenceCondition) { + this.presenceCondition = presenceCondition; + } + + public Collection getDependencies() { + return dependencies; + } + + public void setDependencies(Collection dependencies) { + this.dependencies = dependencies; + } + + public int getHeight() { + return height; + } + + public void setHeight(int height) { + this.height = height; + } + + public RDGNodeData() { + } +} \ No newline at end of file From 0b7768f34664698d1765844211bb7314422c0aaf Mon Sep 17 00:00:00 2001 From: MatheusMello Date: Fri, 29 Sep 2017 21:03:45 -0300 Subject: [PATCH 10/18] Adding interface to create initial inline --- src/fdtmc/FDTMC.java | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/src/fdtmc/FDTMC.java b/src/fdtmc/FDTMC.java index ef21282..db640f7 100644 --- a/src/fdtmc/FDTMC.java +++ b/src/fdtmc/FDTMC.java @@ -366,25 +366,20 @@ private void inlineTransitions(FDTMC fdtmc, Map statesOldToNew) { private void inlineInterface(Interface iface, FDTMC fragment, Map statesMapping) { Map fragmentStatesMapping = this.inlineStates(fragment); this.inlineTransitions(fragment, fragmentStatesMapping); + + InterfaceInline InitialInline = new InterfaceInline(iface, fragment); - State initialInlined = iface.getInitial(); - State initialFragment = fragment.getInitialState(); - State successInlined = iface.getSuccess(); - State successFragment = fragment.getSuccessState(); - State errorInlined = iface.getError(); - State errorFragment = fragment.getErrorState(); - - this.createTransition(statesMapping.get(initialInlined), - fragmentStatesMapping.get(initialFragment), + this.createTransition(statesMapping.get(InitialInline.getinitialInlined()), + fragmentStatesMapping.get(InitialInline.getinitialFragment()), "", "1"); - this.createTransition(fragmentStatesMapping.get(successFragment), - statesMapping.get(successInlined), + this.createTransition(fragmentStatesMapping.get(InitialInline.getsuccessFragment()), + statesMapping.get(InitialInline.getsuccessInlined()), "", "1"); if (errorFragment != null) { - this.createTransition(fragmentStatesMapping.get(errorFragment), - statesMapping.get(errorInlined), + this.createTransition(fragmentStatesMapping.get(InitialInline.geterrorFragment()), + statesMapping.get(InitialInline.geterrorInlined()), "", "1"); } @@ -394,28 +389,23 @@ private void inlineInterfaceWithVariability(Interface iface, FDTMC fragment, Map Map fragmentStatesMapping = this.inlineStates(fragment); this.inlineTransitions(fragment, fragmentStatesMapping); - State initialInlined = iface.getInitial(); - State initialFragment = fragment.getInitialState(); - State successInlined = iface.getSuccess(); - State successFragment = fragment.getSuccessState(); - State errorInlined = iface.getError(); - State errorFragment = fragment.getErrorState(); + InterfaceInline InitialInline = new InterfaceInline(iface, fragment); - this.createTransition(statesMapping.get(initialInlined), - fragmentStatesMapping.get(initialFragment), + this.createTransition(statesMapping.get(InitialInline.getinitialInlined()), + fragmentStatesMapping.get(InitialInline.getinitialFragment()), "", iface.getAbstractedId()); - this.createTransition(statesMapping.get(initialInlined), - statesMapping.get(successInlined), + this.createTransition(statesMapping.get(InitialInline.getinitialInlined()), + statesMapping.get(InitialInline.getsuccessInlined()), "", "1 - " + iface.getAbstractedId()); - this.createTransition(fragmentStatesMapping.get(successFragment), - statesMapping.get(successInlined), + this.createTransition(fragmentStatesMapping.get(InitialInline.getsuccessFragment()), + statesMapping.get(InitialInline.getsuccessInlined()), "", "1"); if (errorFragment != null) { - this.createTransition(fragmentStatesMapping.get(errorFragment), - statesMapping.get(errorInlined), + this.createTransition(fragmentStatesMapping.get(InitialInline.geterrorFragment()), + statesMapping.get(InitialInline.geterrorInlined()), "", "1"); } From 7a0ccde1d24a1beb53b233f65eedb4ad6d6aeeb6 Mon Sep 17 00:00:00 2001 From: MatheusMello Date: Fri, 29 Sep 2017 21:11:45 -0300 Subject: [PATCH 11/18] Adding class to avoid code duplication --- src/fdtmc/FDTMC.java | 32 +++++++++++++------------- src/fdtmc/Inline.java | 52 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 16 deletions(-) create mode 100644 src/fdtmc/Inline.java diff --git a/src/fdtmc/FDTMC.java b/src/fdtmc/FDTMC.java index db640f7..0d940b7 100644 --- a/src/fdtmc/FDTMC.java +++ b/src/fdtmc/FDTMC.java @@ -367,19 +367,19 @@ private void inlineInterface(Interface iface, FDTMC fragment, Map Map fragmentStatesMapping = this.inlineStates(fragment); this.inlineTransitions(fragment, fragmentStatesMapping); - InterfaceInline InitialInline = new InterfaceInline(iface, fragment); + Inline InitialInline = new InterfaceInline(iface, fragment); - this.createTransition(statesMapping.get(InitialInline.getinitialInlined()), - fragmentStatesMapping.get(InitialInline.getinitialFragment()), + this.createTransition(statesMapping.get(InitialInline.getInitialInlined()), + fragmentStatesMapping.get(InitialInline.getInitialFragment()), "", "1"); - this.createTransition(fragmentStatesMapping.get(InitialInline.getsuccessFragment()), - statesMapping.get(InitialInline.getsuccessInlined()), + this.createTransition(fragmentStatesMapping.get(InitialInline.getSuccessFragment()), + statesMapping.get(InitialInline.getSuccessInlined()), "", "1"); if (errorFragment != null) { - this.createTransition(fragmentStatesMapping.get(InitialInline.geterrorFragment()), - statesMapping.get(InitialInline.geterrorInlined()), + this.createTransition(fragmentStatesMapping.get(InitialInline.getErrorFragment()), + statesMapping.get(InitialInline.getErrorInlined()), "", "1"); } @@ -389,23 +389,23 @@ private void inlineInterfaceWithVariability(Interface iface, FDTMC fragment, Map Map fragmentStatesMapping = this.inlineStates(fragment); this.inlineTransitions(fragment, fragmentStatesMapping); - InterfaceInline InitialInline = new InterfaceInline(iface, fragment); + Inline InitialInline = new InterfaceInline(iface, fragment); - this.createTransition(statesMapping.get(InitialInline.getinitialInlined()), - fragmentStatesMapping.get(InitialInline.getinitialFragment()), + this.createTransition(statesMapping.get(InitialInline.getInitialInlined()), + fragmentStatesMapping.get(InitialInline.getInitialFragment()), "", iface.getAbstractedId()); - this.createTransition(statesMapping.get(InitialInline.getinitialInlined()), - statesMapping.get(InitialInline.getsuccessInlined()), + this.createTransition(statesMapping.get(InitialInline.getInitialInlined()), + statesMapping.get(InitialInline.getSuccessInlined()), "", "1 - " + iface.getAbstractedId()); - this.createTransition(fragmentStatesMapping.get(InitialInline.getsuccessFragment()), - statesMapping.get(InitialInline.getsuccessInlined()), + this.createTransition(fragmentStatesMapping.get(InitialInline.getSuccessFragment()), + statesMapping.get(InitialInline.getSuccessInlined()), "", "1"); if (errorFragment != null) { - this.createTransition(fragmentStatesMapping.get(InitialInline.geterrorFragment()), - statesMapping.get(InitialInline.geterrorInlined()), + this.createTransition(fragmentStatesMapping.get(InitialInline.getErrorFragment()), + statesMapping.get(InitialInline.getErrorInlined()), "", "1"); } diff --git a/src/fdtmc/Inline.java b/src/fdtmc/Inline.java new file mode 100644 index 0000000..20f2e6e --- /dev/null +++ b/src/fdtmc/Inline.java @@ -0,0 +1,52 @@ +package fdtmc; + +public class Inline { + + private Interface iface; + private FDTMC fragment; + + private State initialInlined; + private State initialFragment; + private State successInlined; + private State successFragment; + private State errorInlined; + private State errorFragment; + + public Inline(Interface iface, FDTMC fragment) { + + this.iface = iface; + this.fragment = fragment; + + this.initialInlined = iface.getInitial(); + this.initialFragment = fragment.getInitialState(); + this.successInlined = iface.getSuccess(); + this.successFragment = fragment.getSuccessState(); + this.errorInlined = iface.getError(); + this.errorFragment = fragment.getErrorState(); + + } + + public State getInitialInlined() { + return initialInlined; + } + + public State getInitialFragment() { + return initialFragment; + } + + public State getSuccessInlined() { + return successInlined; + } + + public State getSuccessFragment() { + return successFragment; + } + + public State getErrorInlined() { + return errorInlined; + } + + public State getErrorFragment() { + return errorFragment; + } +} From f89cf28aaabdb26184bb9339447fe7ccd3730684 Mon Sep 17 00:00:00 2001 From: eduqg Date: Fri, 29 Sep 2017 21:12:01 -0300 Subject: [PATCH 12/18] Introduzir variavel explicativa --- src/paramwrapper/ParamModel.java | 24 ++++++++++++------------ src/paramwrapper/ParamWrapper.java | 8 +++++--- test/paramwrapper/FDTMCToParamTest.java | 8 ++++---- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/paramwrapper/ParamModel.java b/src/paramwrapper/ParamModel.java index 670e9bd..0ef357e 100644 --- a/src/paramwrapper/ParamModel.java +++ b/src/paramwrapper/ParamModel.java @@ -22,16 +22,16 @@ class ParamModel { private String stateVariable = "s"; // TODO Deixar nome do módulo PARAM configurável. - private String moduleName = "dummyModule"; + private final String moduleName = "dummyModule"; // TODO Inferir estado inicial a partir da topologia da FDTMC. private int initialState = 0; - private Set parameters; - private Map> labels; - private Map commands; + private final Set parameters; + private final Map> labels; + private final Map commands; - private int stateRangeStart; - private int stateRangeEnd; + private final int stateRangeStart; + private final int stateRangeEnd; public ParamModel(FDTMC fdtmc) { if (fdtmc.getVariableName() != null) { @@ -50,13 +50,13 @@ public ParamModel(FDTMC fdtmc) { private Map> getLabels(FDTMC fdtmc) { Map> labeledStates = new TreeMap>(); Collection states = fdtmc.getStates(); - for (State s : states) { - String label = s.getLabel(); + for (State actualState : states) { + String label = actualState.getLabel(); if (label != null) { if (!labeledStates.containsKey(label)) { labeledStates.put(label, new TreeSet()); } - labeledStates.get(label).add(s.getIndex()); + labeledStates.get(label).add(actualState.getIndex()); } } return labeledStates; @@ -88,9 +88,9 @@ private Set getParameters(Collection commands) { Pattern validIdentifier = Pattern.compile("[A-Za-z_][A-Za-z0-9_]*"); for (Command command : commands) { for (String probability : command.getUpdatesProbabilities()) { - Matcher m = validIdentifier.matcher(probability); - while (m.find()) { - tmpParameters.add(m.group()); + Matcher matcherToFind = validIdentifier.matcher(probability); + while (matcherToFind.find()) { + tmpParameters.add(matcherToFind.group()); } } } diff --git a/src/paramwrapper/ParamWrapper.java b/src/paramwrapper/ParamWrapper.java index f975497..a51824d 100644 --- a/src/paramwrapper/ParamWrapper.java +++ b/src/paramwrapper/ParamWrapper.java @@ -46,6 +46,7 @@ public String getReliability(FDTMC fdtmc) { } private String evaluate(String model, String property) { + final String stringToBeReplaced = "\\s+"; try { File modelFile = File.createTempFile("model", "param"); FileWriter modelWriter = new FileWriter(modelFile); @@ -59,7 +60,7 @@ private String evaluate(String model, String property) { String formula; formula = invokeTypeModelChecker(model, modelFile, propertyFile, resultsFile); - return formula.trim().replaceAll("\\s+", ""); + return formula.trim().replaceAll(stringToBeReplaced, ""); } catch (IOException e) { LOGGER.log(Level.SEVERE, e.toString(), e); } @@ -69,9 +70,10 @@ private String evaluate(String model, String property) { private String invokeTypeModelChecker(String model, File modelFile, File propertyFile, - File resultsFile) throws IOException { + File resultsFile) throws IOException { String formula; - if (usePrism && !model.contains("param")) { + final boolean modelContainParam = model.contains("param"); + if (usePrism && !modelContainParam) { formula = invokeModelChecker(modelFile.getAbsolutePath(), propertyFile.getAbsolutePath(), resultsFile.getAbsolutePath()); diff --git a/test/paramwrapper/FDTMCToParamTest.java b/test/paramwrapper/FDTMCToParamTest.java index c2e4fc7..5f2af55 100644 --- a/test/paramwrapper/FDTMCToParamTest.java +++ b/test/paramwrapper/FDTMCToParamTest.java @@ -23,8 +23,8 @@ public void setUp() throws Exception { public void testSingletonFDTMC() { FDTMC singletonFDTMC = new FDTMC(); singletonFDTMC.setVariableName("s"); - State s = singletonFDTMC.createState(); - singletonFDTMC.createTransition(s, s, null, "1"); + State stateSingleton = singletonFDTMC.createState(); + singletonFDTMC.createTransition(stateSingleton, stateSingleton, null, "1"); String expectedModule = stringExpectedModule(); @@ -44,8 +44,8 @@ private String stringExpectedModule() { public void testSingletonFDTMCWithLabel() { FDTMC singletonFDTMC = new FDTMC(); singletonFDTMC.setVariableName("s"); - State s = singletonFDTMC.createState("success"); - singletonFDTMC.createTransition(s, s, null, "1"); + State stateSingleton = singletonFDTMC.createState("success"); + singletonFDTMC.createTransition(stateSingleton, stateSingleton, null, "1"); String expectedModule = stringExpectedModuleWithLabel(); From dd7270325523f6e75b6ec3f627d51b8dfd7d8f7b Mon Sep 17 00:00:00 2001 From: rafaelrabetti Date: Fri, 29 Sep 2017 21:24:26 -0300 Subject: [PATCH 13/18] =?UTF-8?q?RDGNode:=20C=C3=B3digo=20duplicado?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Operação: Extrair método Resultados: Foi criado um método para evitar as chamadas de código duplicado. Signed-off-by: rafaelrabetti --- src/tool/RDGNode.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/tool/RDGNode.java b/src/tool/RDGNode.java index c6a927e..81beca9 100644 --- a/src/tool/RDGNode.java +++ b/src/tool/RDGNode.java @@ -1,5 +1,4 @@ package tool; -import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; @@ -125,10 +124,10 @@ private void topoSortVisit(RDGNode node, Map marks, List numPathsVisit(RDGNode node, Map numberOfPaths = new HashMap(); // A node always has a path to itself. @@ -177,7 +176,7 @@ private static Map numPathsVisit(RDGNode node, Map numPathsVisit(RDGNode node, Map marks, boolean bool) { + marks.put(node, bool); + } + private static boolean containsKeyAndNotHaveNode(RDGNode node, Map marks) { return marks.containsKey(node) && marks.get(node) == false; } From 92d3422909ddafafec0ec546fbb20baee39a2837 Mon Sep 17 00:00:00 2001 From: MatheusMello Date: Fri, 29 Sep 2017 21:27:33 -0300 Subject: [PATCH 14/18] fixing name misspelling --- src/fdtmc/FDTMC.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fdtmc/FDTMC.java b/src/fdtmc/FDTMC.java index 591d4b9..eef4a1a 100644 --- a/src/fdtmc/FDTMC.java +++ b/src/fdtmc/FDTMC.java @@ -372,7 +372,7 @@ private void inlineInterface(Interface iface, FDTMC fragment, Map Map fragmentStatesMapping = this.inlineStates(fragment); this.inlineTransitions(fragment, fragmentStatesMapping); - Inline InitialInline = new InterfaceInline(iface, fragment); + Inline InitialInline = new Inline(iface, fragment); this.createTransition(statesMapping.get(InitialInline.getInitialInlined()), fragmentStatesMapping.get(InitialInline.getInitialFragment()), @@ -382,7 +382,7 @@ private void inlineInterface(Interface iface, FDTMC fragment, Map statesMapping.get(InitialInline.getSuccessInlined()), "", "1"); - if (errorFragment != null) { + if (InitialInline.getErrorFragment() != null) { this.createTransition(fragmentStatesMapping.get(InitialInline.getErrorFragment()), statesMapping.get(InitialInline.getErrorInlined()), "", @@ -394,7 +394,7 @@ private void inlineInterfaceWithVariability(Interface iface, FDTMC fragment, Map Map fragmentStatesMapping = this.inlineStates(fragment); this.inlineTransitions(fragment, fragmentStatesMapping); - Inline InitialInline = new InterfaceInline(iface, fragment); + Inline InitialInline = new Inline(iface, fragment); this.createTransition(statesMapping.get(InitialInline.getInitialInlined()), fragmentStatesMapping.get(InitialInline.getInitialFragment()), @@ -408,7 +408,7 @@ private void inlineInterfaceWithVariability(Interface iface, FDTMC fragment, Map statesMapping.get(InitialInline.getSuccessInlined()), "", "1"); - if (errorFragment != null) { + if (InitialInline.getErrorFragment() != null) { this.createTransition(fragmentStatesMapping.get(InitialInline.getErrorFragment()), statesMapping.get(InitialInline.getErrorInlined()), "", From 4070537bc4a481c7ff4bb481a8adc862a58425a9 Mon Sep 17 00:00:00 2001 From: MatheusMello Date: Fri, 29 Sep 2017 21:34:42 -0300 Subject: [PATCH 15/18] Single return --- src/fdtmc/State.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/fdtmc/State.java b/src/fdtmc/State.java index 3d0b1f9..b72d708 100644 --- a/src/fdtmc/State.java +++ b/src/fdtmc/State.java @@ -34,13 +34,14 @@ public String getLabel() { * A state is equal to another one if they have equal indices. * Labels are only considered when comparing FDTMCs as a whole. */ - @Override + @Override public boolean equals(Object obj) { + boolean isEqual = false; if (obj != null && obj instanceof State) { State other = (State) obj; - return this.index == other.index; + isEqual = this.index == other.index; } - return false; + return isEqual; } @Override From 910b6c6d2264258032fdaea274d379a6e671481b Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 29 Sep 2017 21:35:21 -0300 Subject: [PATCH 16/18] Big Method --- src/fdtmc/FDTMC.java | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/fdtmc/FDTMC.java b/src/fdtmc/FDTMC.java index eef4a1a..292ac9e 100644 --- a/src/fdtmc/FDTMC.java +++ b/src/fdtmc/FDTMC.java @@ -215,9 +215,12 @@ public String toString() { private String creteStateMessage(String msg, State temp, Iterator itTransitions) { while (itTransitions.hasNext()) { Transition t = itTransitions.next(); - msg += temp.getVariableName() + "=" + temp.getIndex() + ((temp.getLabel() != null) ? "(" + temp.getLabel() + ")" : "") + - " --- " + t.getActionName() + " / " + t.getProbability() + - " ---> " + t.getTarget().getVariableName() + "=" + t.getTarget().getIndex() + ((t.getTarget().getLabel() != null) ? "(" + t.getTarget().getLabel() + ")" : "") + "\n"; + msg += temp.getVariableName() + "=" + temp.getIndex() + + ((temp.getLabel() != null) ? "(" + temp.getLabel() + ")" : "") + + " --- " + t.getActionName() + " / " + t.getProbability() + + " ---> " + t.getTarget().getVariableName() + + "=" + t.getTarget().getIndex() + ((t.getTarget().getLabel() != null) ? "(" + + t.getTarget().getLabel() + ")" : "") + "\n"; } return msg; } @@ -267,7 +270,13 @@ public FDTMC inline(Map indexedModels) { FDTMC inlined = new FDTMC(); Map statesMapping = copyForInlining(inlined); - for (Map.Entry> entry: interfaces.entrySet()) { + getValueInlineIfTheyHaveKey(indexedModels, inlined, statesMapping); + return inlined; + } + + private void getValueInlineIfTheyHaveKey(Map indexedModels, FDTMC inlined, + Map statesMapping) { + for (Map.Entry> entry: interfaces.entrySet()) { String dependencyId = entry.getKey(); if (indexedModels.containsKey(dependencyId)) { FDTMC fragment = indexedModels.get(dependencyId); @@ -278,8 +287,7 @@ public FDTMC inline(Map indexedModels) { } } } - return inlined; - } + } /** * Inlines the given FDTMCs whenever there is an interface corresponding From d5f074b96df444452c1ce06a29c2984d3bb107cb Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 29 Sep 2017 21:55:17 -0300 Subject: [PATCH 17/18] Extracting method of big return --- src/fdtmc/FDTMC.java | 100 +++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 47 deletions(-) diff --git a/src/fdtmc/FDTMC.java b/src/fdtmc/FDTMC.java index 292ac9e..6ed7349 100644 --- a/src/fdtmc/FDTMC.java +++ b/src/fdtmc/FDTMC.java @@ -206,25 +206,21 @@ public String toString() { List transitionList = this.transitionSystem.get(temp); if (transitionList != null) { Iterator itTransitions = transitionList.iterator(); - msg = creteStateMessage(msg, temp, itTransitions); + while (itTransitions.hasNext()) { + Transition t = itTransitions.next(); + msg += temp.getVariableName() + "=" + temp.getIndex() + + ((temp.getLabel() != null) ? "(" + temp.getLabel() + ")" : "") + + " --- " + t.getActionName() + " / " + t.getProbability() + + " ---> " + t.getTarget().getVariableName() + "=" + + t.getTarget().getIndex() + + ((t.getTarget().getLabel() != null) ? "(" + + t.getTarget().getLabel() + ")" : "") + "\n"; + } } } return msg; } - private String creteStateMessage(String msg, State temp, Iterator itTransitions) { - while (itTransitions.hasNext()) { - Transition t = itTransitions.next(); - msg += temp.getVariableName() + "=" + temp.getIndex() - + ((temp.getLabel() != null) ? "(" + temp.getLabel() + ")" : "") + - " --- " + t.getActionName() + " / " + t.getProbability() + - " ---> " + t.getTarget().getVariableName() - + "=" + t.getTarget().getIndex() + ((t.getTarget().getLabel() != null) ? "(" - + t.getTarget().getLabel() + ")" : "") + "\n"; - } - return msg; - } - /** * Two FDTMCs are deemed equal whenever: * - their states are equal; @@ -239,16 +235,21 @@ public boolean equals(Object obj) { FDTMC other = (FDTMC) obj; LinkedList> thisInterfaces = new LinkedList>(interfaces.values()); LinkedList> otherInterfaces = new LinkedList>(other.interfaces.values()); - return states.equals(other.states) - && getInitialState().equals(other.getInitialState()) - && getSuccessState().equals(other.getSuccessState()) - && getErrorState().equals(other.getErrorState()) - && transitionSystem.equals(other.transitionSystem) - && thisInterfaces.equals(otherInterfaces); + return compareStateAttributes(other, thisInterfaces, otherInterfaces); } return false; } + private boolean compareStateAttributes(FDTMC other, LinkedList> thisInterfaces, + LinkedList> otherInterfaces) { + return states.equals(other.states) + && getInitialState().equals(other.getInitialState()) + && getSuccessState().equals(other.getSuccessState()) + && getErrorState().equals(other.getErrorState()) + && transitionSystem.equals(other.transitionSystem) + && thisInterfaces.equals(otherInterfaces); + } + @Override public int hashCode() { return states.hashCode() + transitionSystem.hashCode() + interfaces.hashCode(); @@ -270,13 +271,7 @@ public FDTMC inline(Map indexedModels) { FDTMC inlined = new FDTMC(); Map statesMapping = copyForInlining(inlined); - getValueInlineIfTheyHaveKey(indexedModels, inlined, statesMapping); - return inlined; - } - - private void getValueInlineIfTheyHaveKey(Map indexedModels, FDTMC inlined, - Map statesMapping) { - for (Map.Entry> entry: interfaces.entrySet()) { + for (Map.Entry> entry: interfaces.entrySet()) { String dependencyId = entry.getKey(); if (indexedModels.containsKey(dependencyId)) { FDTMC fragment = indexedModels.get(dependencyId); @@ -287,7 +282,8 @@ private void getValueInlineIfTheyHaveKey(Map indexedModels, FDTMC } } } - } + return inlined; + } /** * Inlines the given FDTMCs whenever there is an interface corresponding @@ -379,20 +375,25 @@ private void inlineTransitions(FDTMC fdtmc, Map statesOldToNew) { private void inlineInterface(Interface iface, FDTMC fragment, Map statesMapping) { Map fragmentStatesMapping = this.inlineStates(fragment); this.inlineTransitions(fragment, fragmentStatesMapping); - - Inline InitialInline = new Inline(iface, fragment); - this.createTransition(statesMapping.get(InitialInline.getInitialInlined()), - fragmentStatesMapping.get(InitialInline.getInitialFragment()), + State initialInlined = iface.getInitial(); + State initialFragment = fragment.getInitialState(); + State successInlined = iface.getSuccess(); + State successFragment = fragment.getSuccessState(); + State errorInlined = iface.getError(); + State errorFragment = fragment.getErrorState(); + + this.createTransition(statesMapping.get(initialInlined), + fragmentStatesMapping.get(initialFragment), "", "1"); - this.createTransition(fragmentStatesMapping.get(InitialInline.getSuccessFragment()), - statesMapping.get(InitialInline.getSuccessInlined()), + this.createTransition(fragmentStatesMapping.get(successFragment), + statesMapping.get(successInlined), "", "1"); - if (InitialInline.getErrorFragment() != null) { - this.createTransition(fragmentStatesMapping.get(InitialInline.getErrorFragment()), - statesMapping.get(InitialInline.getErrorInlined()), + if (errorFragment != null) { + this.createTransition(fragmentStatesMapping.get(errorFragment), + statesMapping.get(errorInlined), "", "1"); } @@ -402,23 +403,28 @@ private void inlineInterfaceWithVariability(Interface iface, FDTMC fragment, Map Map fragmentStatesMapping = this.inlineStates(fragment); this.inlineTransitions(fragment, fragmentStatesMapping); - Inline InitialInline = new Inline(iface, fragment); + State initialInlined = iface.getInitial(); + State initialFragment = fragment.getInitialState(); + State successInlined = iface.getSuccess(); + State successFragment = fragment.getSuccessState(); + State errorInlined = iface.getError(); + State errorFragment = fragment.getErrorState(); - this.createTransition(statesMapping.get(InitialInline.getInitialInlined()), - fragmentStatesMapping.get(InitialInline.getInitialFragment()), + this.createTransition(statesMapping.get(initialInlined), + fragmentStatesMapping.get(initialFragment), "", iface.getAbstractedId()); - this.createTransition(statesMapping.get(InitialInline.getInitialInlined()), - statesMapping.get(InitialInline.getSuccessInlined()), + this.createTransition(statesMapping.get(initialInlined), + statesMapping.get(successInlined), "", "1 - " + iface.getAbstractedId()); - this.createTransition(fragmentStatesMapping.get(InitialInline.getSuccessFragment()), - statesMapping.get(InitialInline.getSuccessInlined()), + this.createTransition(fragmentStatesMapping.get(successFragment), + statesMapping.get(successInlined), "", "1"); - if (InitialInline.getErrorFragment() != null) { - this.createTransition(fragmentStatesMapping.get(InitialInline.getErrorFragment()), - statesMapping.get(InitialInline.getErrorInlined()), + if (errorFragment != null) { + this.createTransition(fragmentStatesMapping.get(errorFragment), + statesMapping.get(errorInlined), "", "1"); } From 639e2ac27a34e9afdb0eabe2f83d8fea9a556421 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 29 Sep 2017 22:10:31 -0300 Subject: [PATCH 18/18] Long Method --- test/fdtmc/FDTMCTest.java | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/test/fdtmc/FDTMCTest.java b/test/fdtmc/FDTMCTest.java index 79da213..f649639 100644 --- a/test/fdtmc/FDTMCTest.java +++ b/test/fdtmc/FDTMCTest.java @@ -54,28 +54,40 @@ public void testCreateLotsOfStates() { s4 = fdtmc1.createState(); s5 = fdtmc1.createState(); - Assert.assertNotNull(s0); - Assert.assertNotNull(s1); - Assert.assertNotNull(s2); - Assert.assertNotNull(s3); - Assert.assertNotNull(s4); - Assert.assertNotNull(s5); + assertStatesNotNull(s0, s1, s2, s3, s4, s5); - Assert.assertTrue(fdtmc1.getStates().contains(s0)); - Assert.assertTrue(fdtmc1.getStates().contains(s1)); - Assert.assertTrue(fdtmc1.getStates().contains(s2)); - Assert.assertTrue(fdtmc1.getStates().contains(s3)); - Assert.assertTrue(fdtmc1.getStates().contains(s4)); - Assert.assertTrue(fdtmc1.getStates().contains(s5)); + assertTrueTheStates(s0, s1, s2, s3, s4, s5); + + assertEqualsTheStates(s0, s1, s2, s3, s4, s5); + + Assert.assertEquals(s0, fdtmc1.getInitialState()); + } + private void assertEqualsTheStates(State s0, State s1, State s2, State s3, State s4, State s5) { Assert.assertEquals(0, s0.getIndex()); Assert.assertEquals(1, s1.getIndex()); Assert.assertEquals(2, s2.getIndex()); Assert.assertEquals(3, s3.getIndex()); Assert.assertEquals(4, s4.getIndex()); Assert.assertEquals(5, s5.getIndex()); + } - Assert.assertEquals(s0, fdtmc1.getInitialState()); + private void assertTrueTheStates(State s0, State s1, State s2, State s3, State s4, State s5) { + Assert.assertTrue(fdtmc1.getStates().contains(s0)); + Assert.assertTrue(fdtmc1.getStates().contains(s1)); + Assert.assertTrue(fdtmc1.getStates().contains(s2)); + Assert.assertTrue(fdtmc1.getStates().contains(s3)); + Assert.assertTrue(fdtmc1.getStates().contains(s4)); + Assert.assertTrue(fdtmc1.getStates().contains(s5)); + } + + private void assertStatesNotNull(State s0, State s1, State s2, State s3, State s4, State s5) { + Assert.assertNotNull(s0); + Assert.assertNotNull(s1); + Assert.assertNotNull(s2); + Assert.assertNotNull(s3); + Assert.assertNotNull(s4); + Assert.assertNotNull(s5); }