diff --git a/src/fdtmc/FDTMC.java b/src/fdtmc/FDTMC.java index ef21282..78e9c2d 100644 --- a/src/fdtmc/FDTMC.java +++ b/src/fdtmc/FDTMC.java @@ -156,14 +156,20 @@ public Interface createInterface(String id, State initial, State success, State errorTransition); List interfaceOccurrences = null; - if (interfaces.containsKey(id)) { + interfaceOccurrences = checkExistenceOfInterface(id); + interfaceOccurrences.add(newInterface); + return newInterface; + } + + private List checkExistenceOfInterface(String id) { + List interfaceOccurrences; + if (interfaces.containsKey(id)) { interfaceOccurrences = interfaces.get(id); } else { interfaceOccurrences = new LinkedList(); interfaces.put(id, interfaceOccurrences); } - interfaceOccurrences.add(newInterface); - return newInterface; + return interfaceOccurrences; } public State getStateByLabel(String label) { @@ -227,19 +233,29 @@ public String toString() { */ @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 compareState(other, thisInterfaces, otherInterfaces); } + return false; } + + private boolean compareState(FDTMC other, LinkedList> thisInterfaces, LinkedList> otherInterfaces) { + + boolean state = states.equals(other.states) + && getInitialState().equals(other.getInitialState()) + && getSuccessState().equals(other.getSuccessState()) + && getErrorState().equals(other.getErrorState()) + && transitionSystem.equals(other.transitionSystem) + && thisInterfaces.equals(otherInterfaces); + + return state; + } @Override public int hashCode() { diff --git a/src/fdtmc/Interface.java b/src/fdtmc/Interface.java index f6cd969..b077388 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 compareAllAtributtes(other); } return false; } + private boolean compareAllAtributtes(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() diff --git a/src/tool/RDGNode.java b/src/tool/RDGNode.java index 180097c..bcf333f 100644 --- a/src/tool/RDGNode.java +++ b/src/tool/RDGNode.java @@ -90,7 +90,9 @@ public static RDGNode getById(String id) { } public static String getNextId() { - return "n" + lastNodeIndex++; + String nextId; + nextId = "n" + lastNodeIndex++; + return nextId; } /** @@ -102,21 +104,29 @@ public static String getNextId() { public boolean equals(Object obj) { if (obj != null && obj instanceof RDGNode) { RDGNode other = (RDGNode) obj; - return this.getPresenceCondition().equals(other.getPresenceCondition()) - && this.getFDTMC().equals(other.getFDTMC()) - && this.getDependencies().equals(other.getDependencies()); + return compareAttributesOfRDGNodeObject(other); } return false; } + private boolean compareAttributesOfRDGNodeObject(RDGNode other) { + return this.getPresenceCondition().equals(other.getPresenceCondition()) + && this.getFDTMC().equals(other.getFDTMC()) + && this.getDependencies().equals(other.getDependencies()); + } + @Override public int hashCode() { - return id.hashCode() + presenceCondition.hashCode() + fdtmc.hashCode() + dependencies.hashCode(); + int hashCode; + hashCode = id.hashCode() + presenceCondition.hashCode() + fdtmc.hashCode() + dependencies.hashCode(); + return hashCode; } @Override public String toString() { - return getId() + " (" + getPresenceCondition() + ")"; + String newString; + newString = getId() + " (" + getPresenceCondition() + ")"; + return newString; } /**