From 1e9f87b8e9c560e061d6e8b28a9021c1356ee9cb Mon Sep 17 00:00:00 2001 From: Artur Bersan de Faria Date: Thu, 28 Sep 2017 21:16:40 -0300 Subject: [PATCH 01/16] Resolvendo aglomerados de dados em inLineInteface --- src/fdtmc/FDTMC.java | 44 +++++++++------------- src/fdtmc/InitialStateInlineInterface.java | 33 ++++++++++++++++ 2 files changed, 50 insertions(+), 27 deletions(-) create mode 100644 src/fdtmc/InitialStateInlineInterface.java diff --git a/src/fdtmc/FDTMC.java b/src/fdtmc/FDTMC.java index ef21282..83c0dc7 100644 --- a/src/fdtmc/FDTMC.java +++ b/src/fdtmc/FDTMC.java @@ -367,24 +367,19 @@ private void inlineInterface(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(); - - this.createTransition(statesMapping.get(initialInlined), - fragmentStatesMapping.get(initialFragment), + InitialStateInlineInterface intialState = new InitialStateInlineInterface(iface, fragment); + + this.createTransition(statesMapping.get(intialState.getInitialInlined()), + fragmentStatesMapping.get(intialState.getInitialFragment(), "", "1"); - this.createTransition(fragmentStatesMapping.get(successFragment), - statesMapping.get(successInlined), + this.createTransition(fragmentStatesMapping.get(intialState.getSuccessFragment(), + statesMapping.get(intialState.getSuccessInlined(), "", "1"); if (errorFragment != null) { - this.createTransition(fragmentStatesMapping.get(errorFragment), - statesMapping.get(errorInlined), + this.createTransition(fragmentStatesMapping.get(intialState.getErrorFragment(), + statesMapping.get(intialState.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(); + InitialStateInlineInterface intialState = new InitialStateInlineInterface(iface, fragment); - this.createTransition(statesMapping.get(initialInlined), - fragmentStatesMapping.get(initialFragment), + this.createTransition(statesMapping.get(intialState.getInitialInlined()), + fragmentStatesMapping.get(intialState.getInitialFragment()), "", iface.getAbstractedId()); - this.createTransition(statesMapping.get(initialInlined), - statesMapping.get(successInlined), + this.createTransition(statesMapping.get(intialState.getInitialInlined()), + statesMapping.get(intialState.getSuccessInlined()), "", "1 - " + iface.getAbstractedId()); - this.createTransition(fragmentStatesMapping.get(successFragment), - statesMapping.get(successInlined), + this.createTransition(fragmentStatesMapping.get(intialState.getSuccessFragment()), + statesMapping.get(intialState.getSuccessInlined()), "", "1"); if (errorFragment != null) { - this.createTransition(fragmentStatesMapping.get(errorFragment), - statesMapping.get(errorInlined), + this.createTransition(fragmentStatesMapping.get(intialState.getErrorFragment()), + statesMapping.get(intialState.getErrorInlined()), "", "1"); } diff --git a/src/fdtmc/InitialStateInlineInterface.java b/src/fdtmc/InitialStateInlineInterface.java new file mode 100644 index 0000000..bf21e35 --- /dev/null +++ b/src/fdtmc/InitialStateInlineInterface.java @@ -0,0 +1,33 @@ +package fdtmc; + +public class InitialStateInlineInterface { + + private Interface iface; + private FDTMC fragment; + + public State getInitialInlined() { + return this.iface.getInitial(); + } + + public State getInitialFragment() { + return this.fragment.getInitialState(); + } + public State getSuccessInlined() { + return this.iface.getSuccess(); + } + public State getSuccessFragment() { + return this.fragment.getSuccessState(); + } + public State getErrorInlined() { + return this.iface.getError(); + } + public State getErrorFragment() { + return this.fragment.getErrorState(); + } + + public InitialStateInlineInterface(Interface iface, FDTMC fragment) { + this.iface = iface; + this.fragment = fragment; + } + +} From 1fd1b952c2a156d7d88a759047104659444e3ca6 Mon Sep 17 00:00:00 2001 From: eduardonunes Date: Fri, 29 Sep 2017 00:17:14 +0000 Subject: [PATCH 02/16] Apply refactoring Extract Method in getTransitionByActionName(String action) --- src/fdtmc/FDTMC.java | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/fdtmc/FDTMC.java b/src/fdtmc/FDTMC.java index ef21282..81f5b47 100644 --- a/src/fdtmc/FDTMC.java +++ b/src/fdtmc/FDTMC.java @@ -177,23 +177,27 @@ public State getStateByLabel(String label) { } public Transition getTransitionByActionName(String action) { - //para cada Lista de adjacencias de cada nodo Collection> stateAdjacencies = transitionSystem.values(); Iterator> iteratorStateAdjacencies = stateAdjacencies.iterator(); - while (iteratorStateAdjacencies.hasNext()) { - List transitions = iteratorStateAdjacencies.next(); - - //Percorrer a lista de transicoes e comparar os labels das transicoes - Iterator iteratorTransitions = transitions.iterator(); - while (iteratorTransitions.hasNext()) { - Transition t = iteratorTransitions.next(); - if (t.getActionName().equals(action)) - return t; - } - } - return null; + while (iteratorStateAdjacencies.hasNext()) { + List transitions = iteratorStateAdjacencies.next(); + + Transition temporaryTransition = compareTransitionsLabels(transitions,action); + return temporaryTransition; + } + return null; + } + private Transition compareTransitionsLabels(List transitions, String action){ + Iterator iteratorTransitions = transitions.iterator(); + while (iteratorTransitions.hasNext()) { + Transition temporaryTransition = iteratorTransitions.next(); + if (temporaryTransition.getActionName().equals(action)) + return temporaryTransition; + } + return null; + } @Override public String toString() { From 9f524dd9f7555871d9175689898df93f692218b0 Mon Sep 17 00:00:00 2001 From: eduardonunes Date: Fri, 29 Sep 2017 00:33:49 +0000 Subject: [PATCH 03/16] Remove duplicate code, apply Extract Method in inline and inlineInterfaceWithVariability --- src/fdtmc/FDTMC.java | 596 ++++++++++++++++++++++--------------------- 1 file changed, 308 insertions(+), 288 deletions(-) diff --git a/src/fdtmc/FDTMC.java b/src/fdtmc/FDTMC.java index 81f5b47..44c2e76 100644 --- a/src/fdtmc/FDTMC.java +++ b/src/fdtmc/FDTMC.java @@ -13,20 +13,19 @@ public class FDTMC { - public static final String INITIAL_LABEL = "initial"; - public static final String SUCCESS_LABEL = "success"; - public static final String ERROR_LABEL = "error"; + public static final String INITIAL_LABEL = "initial"; + public static final String SUCCESS_LABEL = "success"; + public static final String ERROR_LABEL = "error"; private Set states; - private State initialState; - private State successState; - private State errorState; + private State initialState; + private State successState; + private State errorState; private String variableName; private int index; private Map> transitionSystem; private Map> interfaces; - public FDTMC() { states = new LinkedHashSet(); initialState = null; @@ -70,64 +69,66 @@ public State createState(String label) { return temp; } - public State createInitialState() { - State initial = createState(); - setInitialState(initial); - return initial; - } + public State createInitialState() { + State initial = createState(); + setInitialState(initial); + return initial; + } - private void setInitialState(State initialState) { - this.initialState = initialState; - initialState.setLabel(INITIAL_LABEL); - } + private void setInitialState(State initialState) { + this.initialState = initialState; + initialState.setLabel(INITIAL_LABEL); + } - public State getInitialState() { - return initialState; - } + public State getInitialState() { + return initialState; + } - public State createSuccessState() { - State success = createState(); - setSuccessState(success); - createTransition(success, success, "", "1.0"); - return success; - } + public State createSuccessState() { + State success = createState(); + setSuccessState(success); + createTransition(success, success, "", "1.0"); + return success; + } - private void setSuccessState(State successState) { - this.successState = successState; - successState.setLabel(SUCCESS_LABEL); - } + private void setSuccessState(State successState) { + this.successState = successState; + successState.setLabel(SUCCESS_LABEL); + } - public State getSuccessState() { - return successState; - } + public State getSuccessState() { + return successState; + } - public State createErrorState() { - State error = createState(); - setErrorState(error); - createTransition(error, error, "", "1.0"); - return error; - } + public State createErrorState() { + State error = createState(); + setErrorState(error); + createTransition(error, error, "", "1.0"); + return error; + } - private void setErrorState(State errorState) { - this.errorState = errorState; - errorState.setLabel(ERROR_LABEL); - } + private void setErrorState(State errorState) { + this.errorState = errorState; + errorState.setLabel(ERROR_LABEL); + } - public State getErrorState() { - return errorState; - } + public State getErrorState() { + return errorState; + } - public Transition createTransition(State source, State target, String action, String reliability) { - if (source == null) { - return null; - } + public Transition createTransition(State source, State target, + String action, String reliability) { + if (source == null) { + return null; + } - List l = transitionSystem.get(source); + List l = transitionSystem.get(source); if (l == null) { l = new LinkedList(); } - Transition newTransition = new Transition(source, target, action, reliability); + Transition newTransition = new Transition(source, target, action, + reliability); boolean success = l.add(newTransition); transitionSystem.put(source, l); return success ? newTransition : null; @@ -135,40 +136,43 @@ public Transition createTransition(State source, State target, String action, St /** * Creates an explicit interface to another FDTMC. - * - * An interface is an FDTMC fragment with 3 states (initial, success, and error) - * and 2 transitions (initial to success with probability {@code id} and initial - * to error with probability 1 - {@code id}). - * - * @param id Identifier of the FDTMC to be abstracted away. - * @param initial Initial state of the interface. - * @param success Success state of the interface. - * @param error Error state of the interface. + * + * An interface is an FDTMC fragment with 3 states (initial, success, and + * error) and 2 transitions (initial to success with probability {@code id} + * and initial to error with probability 1 - {@code id}). + * + * @param id + * Identifier of the FDTMC to be abstracted away. + * @param initial + * Initial state of the interface. + * @param success + * Success state of the interface. + * @param error + * Error state of the interface. */ - public Interface createInterface(String id, State initial, State success, State error) { - Transition successTransition = createTransition(initial, success, "", id); - Transition errorTransition = createTransition(initial, error, "", "1 - " + id); - Interface newInterface = new Interface(id, - initial, - success, - error, - successTransition, - errorTransition); - - List interfaceOccurrences = null; - if (interfaces.containsKey(id)) { - interfaceOccurrences = interfaces.get(id); - } else { - interfaceOccurrences = new LinkedList(); - interfaces.put(id, interfaceOccurrences); - } - interfaceOccurrences.add(newInterface); - return newInterface; + public Interface createInterface(String id, State initial, State success, + State error) { + Transition successTransition = createTransition(initial, success, "", + id); + Transition errorTransition = createTransition(initial, error, "", + "1 - " + id); + Interface newInterface = new Interface(id, initial, success, error, + successTransition, errorTransition); + + List interfaceOccurrences = null; + if (interfaces.containsKey(id)) { + interfaceOccurrences = interfaces.get(id); + } else { + interfaceOccurrences = new LinkedList(); + interfaces.put(id, interfaceOccurrences); + } + interfaceOccurrences.add(newInterface); + return newInterface; } public State getStateByLabel(String label) { - Iterator it = states.iterator(); - while (it.hasNext()){ + Iterator it = states.iterator(); + while (it.hasNext()) { State s = it.next(); if (s.getLabel().equals(label)) return s; @@ -177,26 +181,30 @@ public State getStateByLabel(String label) { } public Transition getTransitionByActionName(String action) { - Collection> stateAdjacencies = transitionSystem.values(); - Iterator> iteratorStateAdjacencies = stateAdjacencies.iterator(); - while (iteratorStateAdjacencies.hasNext()) { - List transitions = iteratorStateAdjacencies.next(); - - Transition temporaryTransition = compareTransitionsLabels(transitions,action); - return temporaryTransition; - } - return null; + Collection> stateAdjacencies = transitionSystem + .values(); + Iterator> iteratorStateAdjacencies = stateAdjacencies + .iterator(); + while (iteratorStateAdjacencies.hasNext()) { + List transitions = iteratorStateAdjacencies.next(); + + Transition temporaryTransition = compareTransitionsLabels( + transitions, action); + return temporaryTransition; + } + return null; } - private Transition compareTransitionsLabels(List transitions, String action){ - Iterator iteratorTransitions = transitions.iterator(); - while (iteratorTransitions.hasNext()) { - Transition temporaryTransition = iteratorTransitions.next(); - if (temporaryTransition.getActionName().equals(action)) - return temporaryTransition; - } - return null; + private Transition compareTransitionsLabels(List transitions, + String action) { + Iterator iteratorTransitions = transitions.iterator(); + while (iteratorTransitions.hasNext()) { + Transition temporaryTransition = iteratorTransitions.next(); + if (temporaryTransition.getActionName().equals(action)) + return temporaryTransition; + } + return null; } @Override @@ -204,17 +212,30 @@ public String toString() { String msg = new String(); Set tmpStates = this.transitionSystem.keySet(); - Iterator itStates = tmpStates.iterator(); + Iterator itStates = tmpStates.iterator(); while (itStates.hasNext()) { State temp = itStates.next(); List transitionList = this.transitionSystem.get(temp); if (transitionList != null) { - Iterator itTransitions = transitionList.iterator(); + 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 += 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"; } } } @@ -222,210 +243,210 @@ public String toString() { } /** - * Two FDTMCs are deemed equal whenever: - * - their states are equal; - * - their initial, success, and error states are equal; - * - the transitions with concrete values are equal; - * - the transitions with variable names have equal source and target states; and - * - the abstracted interfaces are equal. + * Two FDTMCs are deemed equal whenever: - their states are equal; - their + * initial, success, and error states are equal; - the transitions with + * concrete values are equal; - the transitions with variable names have + * equal source and target states; and - the abstracted interfaces are + * equal. */ @Override public boolean equals(Object obj) { - if (obj != null && obj instanceof FDTMC) { - 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 false; + if (obj != null && obj instanceof FDTMC) { + 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 false; } @Override - public int hashCode() { - return states.hashCode() + transitionSystem.hashCode() + interfaces.hashCode(); - } + public int hashCode() { + return states.hashCode() + transitionSystem.hashCode() + + interfaces.hashCode(); + } - public Map> getTransitions() { + public Map> getTransitions() { return transitionSystem; } /** - * Inlines the given FDTMCs whenever there is an interface corresponding - * to the string in the respective index. - * + * Inlines the given FDTMCs whenever there is an interface corresponding to + * the string in the respective index. + * * @param indexedModels - * @return a new FDTMC which represents this one with the ones specified - * in {@code indexedModels} inlined. + * @return a new FDTMC which represents this one with the ones specified in + * {@code indexedModels} inlined. */ - public FDTMC inline(Map indexedModels) { - FDTMC inlined = new FDTMC(); - Map statesMapping = copyForInlining(inlined); - - for (Map.Entry> entry: interfaces.entrySet()) { - String dependencyId = entry.getKey(); - if (indexedModels.containsKey(dependencyId)) { - FDTMC fragment = indexedModels.get(dependencyId); - for (Interface iface: entry.getValue()) { - inlined.inlineInterface(iface, - fragment, - statesMapping); - } - } - } - return inlined; - } + public FDTMC inline(Map indexedModels) { + FDTMC inlined = new FDTMC(); - /** - * Inlines the given FDTMCs whenever there is an interface corresponding - * to the string in the respective index. - * - * This method maintains the variability notion by using the same abstraction - * id of the interface as an encoding of presence (i.e., a "switch" on whether - * or not to take the transitions of the inlined model). - * - * @param indexedModels - * @return a new FDTMC which represents this one with the ones specified - * in {@code indexedModels} inlined. - */ - public FDTMC inlineWithVariability(Map indexedModels) { - FDTMC inlined = new FDTMC(); - Map statesMapping = copyForInlining(inlined); - - for (Map.Entry> entry: interfaces.entrySet()) { - String dependencyId = entry.getKey(); - if (indexedModels.containsKey(dependencyId)) { - FDTMC fragment = indexedModels.get(dependencyId); - for (Interface iface: entry.getValue()) { - inlined.inlineInterfaceWithVariability(iface, - fragment, - statesMapping); - } - } - } - return inlined; - } + inlined = scrollInterfaceList(inlined, indexedModels , false); - /** - * Prepares {@code destination} FDTMC to be an inlined version of this one. - * @param destination - * @return a mapping from states in this FDTMC to the corresponding states - * in the copied one ({@code destination}). - */ - private Map copyForInlining(FDTMC destination) { - destination.variableName = this.getVariableName(); - - Map statesMapping = destination.inlineStates(this); - destination.setInitialState(statesMapping.get(this.getInitialState())); - destination.setSuccessState(statesMapping.get(this.getSuccessState())); - destination.setErrorState(statesMapping.get(this.getErrorState())); - - destination.inlineTransitions(this, statesMapping); - return statesMapping; - } + return inlined; + } - /** - * Inlines all states from {@code fdtmc} stripped of their labels. - * @param fdtmc - * @return - */ - private Map inlineStates(FDTMC fdtmc) { - Map statesOldToNew = new HashMap(); - for (State state: fdtmc.getStates()) { - State newState = this.createState(); - statesOldToNew.put(state, newState); - } - return statesOldToNew; - } + private FDTMC scrollInterfaceList(FDTMC inlined, + Map indexedModels, + Boolean isInlineInterfaceWithVariability) { + + Map statesMapping = copyForInlining(inlined); + + for (Map.Entry> entry : interfaces.entrySet()) { + String dependencyId = entry.getKey(); + if (indexedModels.containsKey(dependencyId)) { + FDTMC fragment = indexedModels.get(dependencyId); + for (Interface iface : entry.getValue()) { + if (isInlineInterfaceWithVariability != true) { + inlined.inlineInterface(iface, fragment, statesMapping); + } else { + inlined.inlineInterfaceWithVariability(iface, fragment, + statesMapping); + } + } + } + } - /** - * Inlines all transitions from {@code fdtmc} that are not part of an interface. - * - * @param fdtmc - * @param statesOldToNew - */ - private void inlineTransitions(FDTMC fdtmc, Map statesOldToNew) { - Set interfaceTransitions = fdtmc.getInterfaceTransitions(); - for (Map.Entry> entry : fdtmc.getTransitions().entrySet()) { - State newSource = statesOldToNew.get(entry.getKey()); - List transitions = entry.getValue(); - if (transitions != null) { - for (Transition transition : transitions) { - if (!interfaceTransitions.contains(transition)) { - State newTarget = statesOldToNew.get(transition.getTarget()); - createTransition(newSource, - newTarget, - transition.getActionName(), - transition.getProbability()); - } - } - } - } - } + return inlined; + } - private void inlineInterface(Interface iface, FDTMC fragment, Map statesMapping) { - 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(); - - this.createTransition(statesMapping.get(initialInlined), - fragmentStatesMapping.get(initialFragment), - "", - "1"); - this.createTransition(fragmentStatesMapping.get(successFragment), - statesMapping.get(successInlined), - "", - "1"); - if (errorFragment != null) { - this.createTransition(fragmentStatesMapping.get(errorFragment), - statesMapping.get(errorInlined), - "", - "1"); - } - } + /** + * Inlines the given FDTMCs whenever there is an interface corresponding to + * the string in the respective index. + * + * This method maintains the variability notion by using the same + * abstraction id of the interface as an encoding of presence (i.e., a + * "switch" on whether or not to take the transitions of the inlined model). + * + * @param indexedModels + * @return a new FDTMC which represents this one with the ones specified in + * {@code indexedModels} inlined. + */ + public FDTMC inlineWithVariability(Map indexedModels) { + FDTMC inlined = new FDTMC(); - private void inlineInterfaceWithVariability(Interface iface, FDTMC fragment, Map statesMapping) { - 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(); - - this.createTransition(statesMapping.get(initialInlined), - fragmentStatesMapping.get(initialFragment), - "", - iface.getAbstractedId()); - this.createTransition(statesMapping.get(initialInlined), - statesMapping.get(successInlined), - "", - "1 - " + iface.getAbstractedId()); - this.createTransition(fragmentStatesMapping.get(successFragment), - statesMapping.get(successInlined), - "", - "1"); - if (errorFragment != null) { - this.createTransition(fragmentStatesMapping.get(errorFragment), - statesMapping.get(errorInlined), - "", - "1"); - } - } + inlined = scrollInterfaceList(inlined, indexedModels, true); + + return inlined; + } + + /** + * Prepares {@code destination} FDTMC to be an inlined version of this one. + * + * @param destination + * @return a mapping from states in this FDTMC to the corresponding states + * in the copied one ({@code destination}). + */ + private Map copyForInlining(FDTMC destination) { + destination.variableName = this.getVariableName(); + + Map statesMapping = destination.inlineStates(this); + destination.setInitialState(statesMapping.get(this.getInitialState())); + destination.setSuccessState(statesMapping.get(this.getSuccessState())); + destination.setErrorState(statesMapping.get(this.getErrorState())); - private Set getInterfaceTransitions() { + destination.inlineTransitions(this, statesMapping); + return statesMapping; + } + + /** + * Inlines all states from {@code fdtmc} stripped of their labels. + * + * @param fdtmc + * @return + */ + private Map inlineStates(FDTMC fdtmc) { + Map statesOldToNew = new HashMap(); + for (State state : fdtmc.getStates()) { + State newState = this.createState(); + statesOldToNew.put(state, newState); + } + return statesOldToNew; + } + + /** + * Inlines all transitions from {@code fdtmc} that are not part of an + * interface. + * + * @param fdtmc + * @param statesOldToNew + */ + private void inlineTransitions(FDTMC fdtmc, Map statesOldToNew) { + Set interfaceTransitions = fdtmc.getInterfaceTransitions(); + for (Map.Entry> entry : fdtmc.getTransitions() + .entrySet()) { + State newSource = statesOldToNew.get(entry.getKey()); + List transitions = entry.getValue(); + if (transitions != null) { + for (Transition transition : transitions) { + if (!interfaceTransitions.contains(transition)) { + State newTarget = statesOldToNew.get(transition + .getTarget()); + createTransition(newSource, newTarget, + transition.getActionName(), + transition.getProbability()); + } + } + } + } + } + + private void inlineInterface(Interface iface, FDTMC fragment, + Map statesMapping) { + 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(); + + this.createTransition(statesMapping.get(initialInlined), + fragmentStatesMapping.get(initialFragment), "", "1"); + this.createTransition(fragmentStatesMapping.get(successFragment), + statesMapping.get(successInlined), "", "1"); + if (errorFragment != null) { + this.createTransition(fragmentStatesMapping.get(errorFragment), + statesMapping.get(errorInlined), "", "1"); + } + } + + private void inlineInterfaceWithVariability(Interface iface, + FDTMC fragment, Map statesMapping) { + 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(); + + this.createTransition(statesMapping.get(initialInlined), + fragmentStatesMapping.get(initialFragment), "", + iface.getAbstractedId()); + this.createTransition(statesMapping.get(initialInlined), + statesMapping.get(successInlined), "", + "1 - " + iface.getAbstractedId()); + this.createTransition(fragmentStatesMapping.get(successFragment), + statesMapping.get(successInlined), "", "1"); + if (errorFragment != null) { + this.createTransition(fragmentStatesMapping.get(errorFragment), + statesMapping.get(errorInlined), "", "1"); + } + } + + private Set getInterfaceTransitions() { Set transitions = new HashSet(); interfaces.values().stream().flatMap(List::stream) .forEach(iface -> { @@ -434,5 +455,4 @@ private Set getInterfaceTransitions() { }); return transitions; } - } From 895c4f170bacb3f4d3f16f640a9a91da1bb0bd02 Mon Sep 17 00:00:00 2001 From: Thiago Lima Date: Fri, 29 Sep 2017 16:31:57 -0300 Subject: [PATCH 04/16] Applying extract variable techinique on equals method --- src/fdtmc/FDTMC.java | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/fdtmc/FDTMC.java b/src/fdtmc/FDTMC.java index e60233f..c65b079 100644 --- a/src/fdtmc/FDTMC.java +++ b/src/fdtmc/FDTMC.java @@ -257,12 +257,22 @@ public boolean equals(Object obj) { 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); + + // Variables to test Equality + final boolean isStateEqual = states.equals(other.states); + final boolean isInitialStateEqual = getInitialState().equals(other.getInitialState()); + final boolean isSuccessStateEqual = getSuccessState().equals(other.getSuccessState()); + final boolean isErrorStateEqual = getErrorState().equals(other.getErrorState()); + final boolean isTrasitionSystemEqual = transitionSystem.equals(other.transitionSystem); + final boolean isInterfaceEqual = thisInterfaces.equals(otherInterfaces); + + return isStateEqual + && isInitialStateEqual + && isSuccessStateEqual + && isErrorStateEqual + && isTrasitionSystemEqual + && isInterfaceEqual; + } return false; } @@ -280,7 +290,7 @@ public Map> getTransitions() { /** * Inlines the given FDTMCs whenever there is an interface corresponding to * the string in the respective index. - * + * * @param indexedModels * @return a new FDTMC which represents this one with the ones specified in * {@code indexedModels} inlined. @@ -320,11 +330,11 @@ private FDTMC scrollInterfaceList(FDTMC inlined, /** * Inlines the given FDTMCs whenever there is an interface corresponding to * the string in the respective index. - * + * * This method maintains the variability notion by using the same * abstraction id of the interface as an encoding of presence (i.e., a * "switch" on whether or not to take the transitions of the inlined model). - * + * * @param indexedModels * @return a new FDTMC which represents this one with the ones specified in * {@code indexedModels} inlined. @@ -339,7 +349,7 @@ public FDTMC inlineWithVariability(Map indexedModels) { /** * Prepares {@code destination} FDTMC to be an inlined version of this one. - * + * * @param destination * @return a mapping from states in this FDTMC to the corresponding states * in the copied one ({@code destination}). @@ -358,7 +368,7 @@ private Map copyForInlining(FDTMC destination) { /** * Inlines all states from {@code fdtmc} stripped of their labels. - * + * * @param fdtmc * @return */ @@ -374,7 +384,7 @@ private Map inlineStates(FDTMC fdtmc) { /** * Inlines all transitions from {@code fdtmc} that are not part of an * interface. - * + * * @param fdtmc * @param statesOldToNew */ From 9d7ebcab1f56a1a7b30a0edeb160ce592625aeec Mon Sep 17 00:00:00 2001 From: Thiago Lima Date: Fri, 29 Sep 2017 16:37:00 -0300 Subject: [PATCH 05/16] Applying extract method techinique --- src/fdtmc/FDTMC.java | 46 ++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/fdtmc/FDTMC.java b/src/fdtmc/FDTMC.java index c65b079..c1cda31 100644 --- a/src/fdtmc/FDTMC.java +++ b/src/fdtmc/FDTMC.java @@ -218,30 +218,34 @@ 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 = createMessage( itTransitions, temp, msg); return msg; } +private String createMessage(Iterator itTransitions, State temp, String msg) { + 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; - their * initial, success, and error states are equal; - the transitions with From 0c1317f4e7456f89f06ef8441a21dd3707d9730d Mon Sep 17 00:00:00 2001 From: Thiago Lima Date: Fri, 29 Sep 2017 16:42:43 -0300 Subject: [PATCH 06/16] Applying extract method techinique --- src/fdtmc/FDTMC.java | 56 ++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/src/fdtmc/FDTMC.java b/src/fdtmc/FDTMC.java index c1cda31..fe5bb81 100644 --- a/src/fdtmc/FDTMC.java +++ b/src/fdtmc/FDTMC.java @@ -213,37 +213,47 @@ public String toString() { Set tmpStates = this.transitionSystem.keySet(); Iterator itStates = tmpStates.iterator(); + + msg = createTrasitionList(itStates, msg); + + return msg; + } + + private String createTrasitionList(Iterator itStates, String msg) { while (itStates.hasNext()) { State temp = itStates.next(); List transitionList = this.transitionSystem.get(temp); if (transitionList != null) { - Iterator itTransitions = transitionList.iterator(); + Iterator itTransitions = transitionList.iterator(); msg = createMessage( itTransitions, temp, msg); + } + } + return msg; } -private String createMessage(Iterator itTransitions, State temp, String msg) { - 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 createMessage(Iterator itTransitions, State temp, String msg) { + 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; + } /** From e235046d298c304de0203761985296f7b21cf40d Mon Sep 17 00:00:00 2001 From: Marcelo Cristiano Date: Fri, 29 Sep 2017 17:53:29 -0300 Subject: [PATCH 07/16] Reducing complexity of scrollInterfaceList method --- src/fdtmc/FDTMC.java | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/fdtmc/FDTMC.java b/src/fdtmc/FDTMC.java index fe5bb81..61e519a 100644 --- a/src/fdtmc/FDTMC.java +++ b/src/fdtmc/FDTMC.java @@ -325,23 +325,36 @@ private FDTMC scrollInterfaceList(FDTMC inlined, for (Map.Entry> entry : interfaces.entrySet()) { String dependencyId = entry.getKey(); - if (indexedModels.containsKey(dependencyId)) { - FDTMC fragment = indexedModels.get(dependencyId); - for (Interface iface : entry.getValue()) { - if (isInlineInterfaceWithVariability != true) { - inlined.inlineInterface(iface, fragment, statesMapping); - } else { - inlined.inlineInterfaceWithVariability(iface, fragment, - statesMapping); - } - } - } - } + iterateModelsDependencies(inlined, indexedModels, isInlineInterfaceWithVariability, statesMapping, entry, dependencyId); + } return inlined; } - /** + private void iterateModelsDependencies(FDTMC inlined, Map indexedModels, + Boolean isInlineInterfaceWithVariability, Map statesMapping, + Map.Entry> entry, String dependencyId) { + if (indexedModels.containsKey(dependencyId)) { + FDTMC fragment = indexedModels.get(dependencyId); + for (Interface iface : entry.getValue()) { + checkForInlineInterfaceType(inlined, isInlineInterfaceWithVariability, + statesMapping, fragment, iface); + } + } + } + + private void checkForInlineInterfaceType(FDTMC inlined, Boolean isInlineInterfaceWithVariability, + Map statesMapping, + FDTMC fragment, Interface iface) { + if (!isInlineInterfaceWithVariability) { + inlined.inlineInterface(iface, fragment, statesMapping); + } else { + inlined.inlineInterfaceWithVariability(iface, fragment, + statesMapping); + } + } + + /** * Inlines the given FDTMCs whenever there is an interface corresponding to * the string in the respective index. * From 9b90a331614e8f1f537a6b424eb1de57d50b1673 Mon Sep 17 00:00:00 2001 From: Marcelo Cristiano Date: Fri, 29 Sep 2017 17:56:32 -0300 Subject: [PATCH 08/16] Changing method to have only one return --- reana.iml | 13 +++++++++++++ src/tool/RDGNode.java | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 reana.iml diff --git a/reana.iml b/reana.iml new file mode 100644 index 0000000..120f59d --- /dev/null +++ b/reana.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/tool/RDGNode.java b/src/tool/RDGNode.java index 180097c..45eeecb 100644 --- a/src/tool/RDGNode.java +++ b/src/tool/RDGNode.java @@ -100,13 +100,14 @@ public static String getNextId() { */ @Override public boolean equals(Object obj) { + boolean isEqual = false; if (obj != null && obj instanceof RDGNode) { RDGNode other = (RDGNode) obj; - return this.getPresenceCondition().equals(other.getPresenceCondition()) + isEqual = this.getPresenceCondition().equals(other.getPresenceCondition()) && this.getFDTMC().equals(other.getFDTMC()) && this.getDependencies().equals(other.getDependencies()); } - return false; + return isEqual; } @Override From 29bc1ab432b29daedca3a6333dfffa4f236aadac Mon Sep 17 00:00:00 2001 From: Marcelo Cristiano Date: Fri, 29 Sep 2017 18:02:52 -0300 Subject: [PATCH 09/16] Changing function to have only one return --- src/tool/RDGNode.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tool/RDGNode.java b/src/tool/RDGNode.java index 45eeecb..a06bb14 100644 --- a/src/tool/RDGNode.java +++ b/src/tool/RDGNode.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; +import com.sun.org.apache.bcel.internal.generic.NEW; import fdtmc.FDTMC; @@ -231,12 +232,13 @@ private static Map sumPaths(Map pathsCountA, * @return a similar RDG node or null in case there is none. */ public static RDGNode getSimilarNode(RDGNode target) { + RDGNode rdgNode = null; for (RDGNode candidate: nodesInCreationOrder) { if (candidate != target && candidate.equals(target)) { - return candidate; + rdgNode = candidate; } } - return null; + return rdgNode; } } From cfaf150ba99c2978872b2906834a5c3ee585018b Mon Sep 17 00:00:00 2001 From: Marcelo Cristiano Date: Fri, 29 Sep 2017 18:05:41 -0300 Subject: [PATCH 10/16] Reducing method complexity --- src/tool/RDGNode.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/tool/RDGNode.java b/src/tool/RDGNode.java index a06bb14..5604f69 100644 --- a/src/tool/RDGNode.java +++ b/src/tool/RDGNode.java @@ -213,16 +213,21 @@ private static Map numPathsVisit(RDGNode node, Map sumPaths(Map pathsCountA, Map pathsCountB) { Map numberOfPaths = new HashMap(pathsCountA); for (Map.Entry entry: pathsCountB.entrySet()) { - RDGNode node = entry.getKey(); - Integer count = entry.getValue(); - if (numberOfPaths.containsKey(node)) { - count += numberOfPaths.get(node); - } - numberOfPaths.put(node, count); + numberOfPathsForNode(numberOfPaths, entry); } return numberOfPaths; } + private static void numberOfPathsForNode(Map numberOfPaths, + Map.Entry entry) { + RDGNode node = entry.getKey(); + Integer count = entry.getValue(); + if (numberOfPaths.containsKey(node)) { + count += numberOfPaths.get(node); + } + numberOfPaths.put(node, count); + } + /** * Returns the first RDG node (in crescent order of creation time) which is similar * to the one provided. From 56db54bfea0ef9d57aac3a993e305a34b72dfb89 Mon Sep 17 00:00:00 2001 From: Marcelo Cristiano Date: Fri, 29 Sep 2017 18:07:59 -0300 Subject: [PATCH 11/16] Simplifying if checks --- src/tool/RDGNode.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tool/RDGNode.java b/src/tool/RDGNode.java index 5604f69..9d2077a 100644 --- a/src/tool/RDGNode.java +++ b/src/tool/RDGNode.java @@ -145,7 +145,7 @@ 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 (marks.containsKey(node) && !marks.get(node)) { // Visiting temporarily marked node -- this means a cyclic dependency! throw new CyclicRdgException(); } else if (!marks.containsKey(node)) { @@ -179,7 +179,7 @@ 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 (marks.containsKey(node) && !marks.get(node)) { // Visiting temporarily marked node -- this means a cyclic dependency! throw new CyclicRdgException(); } else if (!marks.containsKey(node)) { From 1eaaa6a77faa8dd843c369d0a81c482fc64f9b34 Mon Sep 17 00:00:00 2001 From: Marcelo Cristiano Date: Fri, 29 Sep 2017 18:09:45 -0300 Subject: [PATCH 12/16] Reducing method complexity --- src/tool/RDGNode.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/tool/RDGNode.java b/src/tool/RDGNode.java index 9d2077a..9749b67 100644 --- a/src/tool/RDGNode.java +++ b/src/tool/RDGNode.java @@ -239,9 +239,14 @@ private static void numberOfPathsForNode(Map numberOfPaths, public static RDGNode getSimilarNode(RDGNode target) { RDGNode rdgNode = null; for (RDGNode candidate: nodesInCreationOrder) { - if (candidate != target && candidate.equals(target)) { - rdgNode = candidate; - } + rdgNode = checkSimilarNode(target, rdgNode, candidate); + } + return rdgNode; + } + + private static RDGNode checkSimilarNode(RDGNode target, RDGNode rdgNode, RDGNode candidate) { + if (candidate != target && candidate.equals(target)) { + rdgNode = candidate; } return rdgNode; } From 672709284677a1b9812d1d43de69f7c4ea1ecfc5 Mon Sep 17 00:00:00 2001 From: Marcelo Cristiano Date: Fri, 29 Sep 2017 18:13:09 -0300 Subject: [PATCH 13/16] Reducing method complexity --- src/tool/RDGNode.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/tool/RDGNode.java b/src/tool/RDGNode.java index 9749b67..3287d9b 100644 --- a/src/tool/RDGNode.java +++ b/src/tool/RDGNode.java @@ -151,15 +151,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 From 6c771d0bf73bf0d22d2e8cc7b9a51c177f913b72 Mon Sep 17 00:00:00 2001 From: eduardonunes Date: Fri, 29 Sep 2017 23:12:45 +0000 Subject: [PATCH 14/16] Extract method of equals method --- src/fdtmc/FDTMC.java | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/fdtmc/FDTMC.java b/src/fdtmc/FDTMC.java index 61e519a..525f3ab 100644 --- a/src/fdtmc/FDTMC.java +++ b/src/fdtmc/FDTMC.java @@ -280,17 +280,29 @@ public boolean equals(Object obj) { final boolean isTrasitionSystemEqual = transitionSystem.equals(other.transitionSystem); final boolean isInterfaceEqual = thisInterfaces.equals(otherInterfaces); - return isStateEqual - && isInitialStateEqual - && isSuccessStateEqual - && isErrorStateEqual - && isTrasitionSystemEqual - && isInterfaceEqual; + return compareBooleanValuesOfVariables(isStateEqual, + isInitialStateEqual, isSuccessStateEqual, + isErrorStateEqual, isTrasitionSystemEqual, isInterfaceEqual); } return false; } + private Boolean compareBooleanValuesOfVariables(Boolean isStateEqual, + Boolean isInitialStateEqual, + Boolean isSuccessStateEqual, + Boolean isErrorStateEqual, + Boolean isTrasitionSystemEqual, + Boolean isInterfaceEqual){ + + return isStateEqual + && isInitialStateEqual + && isSuccessStateEqual + && isErrorStateEqual + && isTrasitionSystemEqual + && isInterfaceEqual; + } + @Override public int hashCode() { return states.hashCode() + transitionSystem.hashCode() From 46f55f4206a638ebdb605adb4910b1f1f3e9e645 Mon Sep 17 00:00:00 2001 From: eduardonunes Date: Fri, 29 Sep 2017 23:26:46 +0000 Subject: [PATCH 15/16] Remove duplicate code, appling Extract Method --- src/fdtmc/FDTMC.java | 182 +++++++++++++++++++++---------------------- 1 file changed, 90 insertions(+), 92 deletions(-) diff --git a/src/fdtmc/FDTMC.java b/src/fdtmc/FDTMC.java index 525f3ab..fc293bb 100644 --- a/src/fdtmc/FDTMC.java +++ b/src/fdtmc/FDTMC.java @@ -136,11 +136,11 @@ public Transition createTransition(State source, State target, /** * Creates an explicit interface to another FDTMC. - * + * * An interface is an FDTMC fragment with 3 states (initial, success, and * error) and 2 transitions (initial to success with probability {@code id} * and initial to error with probability 1 - {@code id}). - * + * * @param id * Identifier of the FDTMC to be abstracted away. * @param initial @@ -224,22 +224,23 @@ private String createTrasitionList(Iterator itStates, String msg) { State temp = itStates.next(); List transitionList = this.transitionSystem.get(temp); if (transitionList != null) { - Iterator itTransitions = transitionList.iterator(); - msg = createMessage( itTransitions, temp, msg); + Iterator itTransitions = transitionList.iterator(); + msg = createMessage(itTransitions, temp, msg); } } return msg; } - private String createMessage(Iterator itTransitions, State temp, String msg) { + private String createMessage(Iterator itTransitions, + State temp, String msg) { while (itTransitions.hasNext()) { Transition t = itTransitions.next(); msg += temp.getVariableName() + "=" + temp.getIndex() - + ((temp.getLabel() != null) ? "(" - + temp.getLabel() + ")" : "") + + ((temp.getLabel() != null) ? "(" + temp.getLabel() + ")" + : "") + " --- " + t.getActionName() + " / " @@ -249,13 +250,11 @@ private String createMessage(Iterator itTransitions, State temp, Str + "=" + t.getTarget().getIndex() + ((t.getTarget().getLabel() != null) ? "(" - + t.getTarget().getLabel() + ")" : "") - + "\n"; + + t.getTarget().getLabel() + ")" : "") + "\n"; } return msg; } - /** * Two FDTMCs are deemed equal whenever: - their states are equal; - their * initial, success, and error states are equal; - the transitions with @@ -274,35 +273,35 @@ public boolean equals(Object obj) { // Variables to test Equality final boolean isStateEqual = states.equals(other.states); - final boolean isInitialStateEqual = getInitialState().equals(other.getInitialState()); - final boolean isSuccessStateEqual = getSuccessState().equals(other.getSuccessState()); - final boolean isErrorStateEqual = getErrorState().equals(other.getErrorState()); - final boolean isTrasitionSystemEqual = transitionSystem.equals(other.transitionSystem); - final boolean isInterfaceEqual = thisInterfaces.equals(otherInterfaces); - - return compareBooleanValuesOfVariables(isStateEqual, - isInitialStateEqual, isSuccessStateEqual, + final boolean isInitialStateEqual = getInitialState().equals( + other.getInitialState()); + final boolean isSuccessStateEqual = getSuccessState().equals( + other.getSuccessState()); + final boolean isErrorStateEqual = getErrorState().equals( + other.getErrorState()); + final boolean isTrasitionSystemEqual = transitionSystem + .equals(other.transitionSystem); + final boolean isInterfaceEqual = thisInterfaces + .equals(otherInterfaces); + + return compareBooleanValuesOfVariables(isStateEqual, + isInitialStateEqual, isSuccessStateEqual, isErrorStateEqual, isTrasitionSystemEqual, isInterfaceEqual); } return false; } - private Boolean compareBooleanValuesOfVariables(Boolean isStateEqual, - Boolean isInitialStateEqual, - Boolean isSuccessStateEqual, - Boolean isErrorStateEqual, - Boolean isTrasitionSystemEqual, - Boolean isInterfaceEqual){ - - return isStateEqual - && isInitialStateEqual - && isSuccessStateEqual - && isErrorStateEqual - && isTrasitionSystemEqual - && isInterfaceEqual; - } - + private Boolean compareBooleanValuesOfVariables(Boolean isStateEqual, + Boolean isInitialStateEqual, Boolean isSuccessStateEqual, + Boolean isErrorStateEqual, Boolean isTrasitionSystemEqual, + Boolean isInterfaceEqual) { + + return isStateEqual && isInitialStateEqual && isSuccessStateEqual + && isErrorStateEqual && isTrasitionSystemEqual + && isInterfaceEqual; + } + @Override public int hashCode() { return states.hashCode() + transitionSystem.hashCode() @@ -316,17 +315,17 @@ public Map> getTransitions() { /** * Inlines the given FDTMCs whenever there is an interface corresponding to * the string in the respective index. - * + * * @param indexedModels * @return a new FDTMC which represents this one with the ones specified in * {@code indexedModels} inlined. */ public FDTMC inline(Map indexedModels) { - FDTMC inlined = new FDTMC(); + FDTMC inlined = new FDTMC(); - inlined = scrollInterfaceList(inlined, indexedModels , false); + inlined = scrollInterfaceList(inlined, indexedModels, false); - return inlined; + return inlined; } private FDTMC scrollInterfaceList(FDTMC inlined, @@ -337,58 +336,63 @@ private FDTMC scrollInterfaceList(FDTMC inlined, for (Map.Entry> entry : interfaces.entrySet()) { String dependencyId = entry.getKey(); - iterateModelsDependencies(inlined, indexedModels, isInlineInterfaceWithVariability, statesMapping, entry, dependencyId); - } + iterateModelsDependencies(inlined, indexedModels, + isInlineInterfaceWithVariability, statesMapping, entry, + dependencyId); + } return inlined; } - private void iterateModelsDependencies(FDTMC inlined, Map indexedModels, - Boolean isInlineInterfaceWithVariability, Map statesMapping, - Map.Entry> entry, String dependencyId) { - if (indexedModels.containsKey(dependencyId)) { - FDTMC fragment = indexedModels.get(dependencyId); - for (Interface iface : entry.getValue()) { - checkForInlineInterfaceType(inlined, isInlineInterfaceWithVariability, - statesMapping, fragment, iface); - } - } - } + private void iterateModelsDependencies(FDTMC inlined, + Map indexedModels, + Boolean isInlineInterfaceWithVariability, + Map statesMapping, + Map.Entry> entry, String dependencyId) { + if (indexedModels.containsKey(dependencyId)) { + FDTMC fragment = indexedModels.get(dependencyId); + for (Interface iface : entry.getValue()) { + checkForInlineInterfaceType(inlined, + isInlineInterfaceWithVariability, statesMapping, + fragment, iface); + } + } + } - private void checkForInlineInterfaceType(FDTMC inlined, Boolean isInlineInterfaceWithVariability, - Map statesMapping, - FDTMC fragment, Interface iface) { - if (!isInlineInterfaceWithVariability) { - inlined.inlineInterface(iface, fragment, statesMapping); - } else { - inlined.inlineInterfaceWithVariability(iface, fragment, - statesMapping); - } - } + private void checkForInlineInterfaceType(FDTMC inlined, + Boolean isInlineInterfaceWithVariability, + Map statesMapping, FDTMC fragment, Interface iface) { + if (!isInlineInterfaceWithVariability) { + inlined.inlineInterface(iface, fragment, statesMapping); + } else { + inlined.inlineInterfaceWithVariability(iface, fragment, + statesMapping); + } + } - /** + /** * Inlines the given FDTMCs whenever there is an interface corresponding to * the string in the respective index. - * + * * This method maintains the variability notion by using the same * abstraction id of the interface as an encoding of presence (i.e., a * "switch" on whether or not to take the transitions of the inlined model). - * + * * @param indexedModels * @return a new FDTMC which represents this one with the ones specified in * {@code indexedModels} inlined. */ public FDTMC inlineWithVariability(Map indexedModels) { - FDTMC inlined = new FDTMC(); + FDTMC inlined = new FDTMC(); - inlined = scrollInterfaceList(inlined, indexedModels, true); + inlined = scrollInterfaceList(inlined, indexedModels, true); - return inlined; + return inlined; } /** * Prepares {@code destination} FDTMC to be an inlined version of this one. - * + * * @param destination * @return a mapping from states in this FDTMC to the corresponding states * in the copied one ({@code destination}). @@ -407,7 +411,7 @@ private Map copyForInlining(FDTMC destination) { /** * Inlines all states from {@code fdtmc} stripped of their labels. - * + * * @param fdtmc * @return */ @@ -423,7 +427,7 @@ private Map inlineStates(FDTMC fdtmc) { /** * Inlines all transitions from {@code fdtmc} that are not part of an * interface. - * + * * @param fdtmc * @param statesOldToNew */ @@ -449,6 +453,12 @@ private void inlineTransitions(FDTMC fdtmc, Map statesOldToNew) { private void inlineInterface(Interface iface, FDTMC fragment, Map statesMapping) { + chooseInlineInterface(iface, fragment, statesMapping, false); + } + + private void chooseInlineInterface(Interface iface, FDTMC fragment, + Map statesMapping, Boolean isWithVariability) { + Map fragmentStatesMapping = this.inlineStates(fragment); this.inlineTransitions(fragment, fragmentStatesMapping); @@ -458,11 +468,20 @@ private void inlineInterface(Interface iface, FDTMC fragment, State successFragment = fragment.getSuccessState(); State errorInlined = iface.getError(); State errorFragment = fragment.getErrorState(); + String ifaceID = "1"; + + if (isWithVariability) { + ifaceID = iface.getAbstractedId(); + this.createTransition(statesMapping.get(initialInlined), + statesMapping.get(successInlined), "", + "1 - " + ifaceID); + } this.createTransition(statesMapping.get(initialInlined), - fragmentStatesMapping.get(initialFragment), "", "1"); + fragmentStatesMapping.get(initialFragment), "", ifaceID); this.createTransition(fragmentStatesMapping.get(successFragment), statesMapping.get(successInlined), "", "1"); + if (errorFragment != null) { this.createTransition(fragmentStatesMapping.get(errorFragment), statesMapping.get(errorInlined), "", "1"); @@ -471,28 +490,7 @@ private void inlineInterface(Interface iface, FDTMC fragment, private void inlineInterfaceWithVariability(Interface iface, FDTMC fragment, Map statesMapping) { - 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(); - - this.createTransition(statesMapping.get(initialInlined), - fragmentStatesMapping.get(initialFragment), "", - iface.getAbstractedId()); - this.createTransition(statesMapping.get(initialInlined), - statesMapping.get(successInlined), "", - "1 - " + iface.getAbstractedId()); - this.createTransition(fragmentStatesMapping.get(successFragment), - statesMapping.get(successInlined), "", "1"); - if (errorFragment != null) { - this.createTransition(fragmentStatesMapping.get(errorFragment), - statesMapping.get(errorInlined), "", "1"); - } + chooseInlineInterface(iface, fragment, statesMapping, true); } private Set getInterfaceTransitions() { From f46718af4b74b11e2188408b6ec3d0debc92cfd0 Mon Sep 17 00:00:00 2001 From: eduardonunes Date: Fri, 29 Sep 2017 23:35:58 +0000 Subject: [PATCH 16/16] Add explanatory variable --- src/fdtmc/FDTMC.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/fdtmc/FDTMC.java b/src/fdtmc/FDTMC.java index fc293bb..2f3919f 100644 --- a/src/fdtmc/FDTMC.java +++ b/src/fdtmc/FDTMC.java @@ -122,15 +122,15 @@ public Transition createTransition(State source, State target, return null; } - List l = transitionSystem.get(source); - if (l == null) { - l = new LinkedList(); + List transitionsList = transitionSystem.get(source); + if (transitionsList == null) { + transitionsList = new LinkedList(); } Transition newTransition = new Transition(source, target, action, reliability); - boolean success = l.add(newTransition); - transitionSystem.put(source, l); + boolean success = transitionsList.add(newTransition); + transitionSystem.put(source, transitionsList); return success ? newTransition : null; }