diff --git a/src/main/java/tmltranslator/TMLActivityElement.java b/src/main/java/tmltranslator/TMLActivityElement.java index 9b06395c1081490e4b055361f7cbf5a1516f1d37..4a7cedbfb0ac1554fc6ee9d76e525a3ee5b97769 100755 --- a/src/main/java/tmltranslator/TMLActivityElement.java +++ b/src/main/java/tmltranslator/TMLActivityElement.java @@ -41,6 +41,8 @@ package tmltranslator; +import myutil.TraceManager; + import java.util.Objects; import java.util.Vector; @@ -158,12 +160,11 @@ public abstract class TMLActivityElement extends TMLElement { public boolean equalSpec(Object o) { if (o == null || getClass() != o.getClass()) return false; - if (this == o) return true; TMLActivityElement tmlActEtls = (TMLActivityElement) o; TMLComparingMethod comp = new TMLComparingMethod(); - return Objects.equals(value,tmlActEtls.getValue()) && - comp.isTMLActivityEltListEquals(nexts,tmlActEtls.getNexts()); + return Objects.equals(value, tmlActEtls.getValue()) && comp.isSecurityPatternEquals(securityPattern, tmlActEtls.getSecurityPattern()) && + comp.isTMLActivityEltListEquals(nexts, tmlActEtls.getNexts()); } public void setCheckableAccessibility(boolean b) { diff --git a/src/main/java/tmltranslator/TMLActivityElementChannel.java b/src/main/java/tmltranslator/TMLActivityElementChannel.java index 2bf1606e999f22eae15b9ff13197334d9fe036cc..05d11a4eb9d76724d311a7fdbc9aaa1c8ace718a 100755 --- a/src/main/java/tmltranslator/TMLActivityElementChannel.java +++ b/src/main/java/tmltranslator/TMLActivityElementChannel.java @@ -127,24 +127,13 @@ public abstract class TMLActivityElementChannel extends TMLActivityElement { @Override public boolean equalSpec(Object o) { - if (!(o instanceof TMLActivityElementChannel)) return false; if (!super.equalSpec(o)) return false; TMLActivityElementChannel tmlActEltChannel = (TMLActivityElementChannel) o; - + // TMLComparingMethod comp = new TMLComparingMethod(); // Check if the two TMLActivityElementChannel have the same channels list. - for (TMLChannel ch : channels) { - boolean isEqualChan = false; - for (TMLChannel ch2 : tmlActEltChannel.channels) { - if (ch.equalSpec(ch2)) { - isEqualChan = true; - break; - } - } - if (!isEqualChan) return false; - } + // if (!comp.isTMLChannelListEquals(channels, tmlActEltChannel.channels)) return false; return Objects.equals(nbOfSamples, tmlActEltChannel.getNbOfSamples()) && isAttacker == tmlActEltChannel.isAttacker(); - } public void fillValues(TMLActivityElementChannel newElt, TMLModeling tmlm) throws TMLCheckingError { diff --git a/src/main/java/tmltranslator/TMLActivityElementEvent.java b/src/main/java/tmltranslator/TMLActivityElementEvent.java index a2d0024aad13fa40f38b72355177718d13e9ae2b..b5062ce3521abd5d2213a502cb4425d45abcafbd 100755 --- a/src/main/java/tmltranslator/TMLActivityElementEvent.java +++ b/src/main/java/tmltranslator/TMLActivityElementEvent.java @@ -146,11 +146,10 @@ public abstract class TMLActivityElementEvent extends TMLActivityElement { @Override public boolean equalSpec(Object o) { - if (!(o instanceof TMLActivityElementEvent)) return false; if (!super.equalSpec(o)) return false; TMLActivityElementEvent tmlActivityElementEvent = (TMLActivityElementEvent) o; // Check if the two TMLActivityElementEvent have the same events list. - for (TMLEvent evt1 : events) { + /*for (TMLEvent evt1 : events) { boolean isEqualEvt = false; for (TMLEvent evt2 : tmlActivityElementEvent.getEvents()) { if (evt1.equalSpec(evt2)) { @@ -160,7 +159,7 @@ public abstract class TMLActivityElementEvent extends TMLActivityElement { } if (!isEqualEvt) return false; } - if (!event.equalSpec(tmlActivityElementEvent.getEvent())) return false; + if (!event.equalSpec(tmlActivityElementEvent.getEvent())) return false;*/ return (new HashSet<>(datas)).equals(new HashSet<>(tmlActivityElementEvent.getDatas())) && Objects.equals(variable, tmlActivityElementEvent.getVariable()); } diff --git a/src/main/java/tmltranslator/TMLActivityElementWithAction.java b/src/main/java/tmltranslator/TMLActivityElementWithAction.java index c2511b743134b8a69ac8720294e7ed73c4accb47..513529e9b3008fa3b562e35f3c773d8de169610e 100755 --- a/src/main/java/tmltranslator/TMLActivityElementWithAction.java +++ b/src/main/java/tmltranslator/TMLActivityElementWithAction.java @@ -80,7 +80,6 @@ public abstract class TMLActivityElementWithAction extends TMLActivityElement { @Override public boolean equalSpec(Object o) { - if (!(o instanceof TMLActivityElementWithAction)) return false; if (!super.equalSpec(o)) return false; TMLActivityElementWithAction tmlActivityElementWithAction = (TMLActivityElementWithAction) o; return Objects.equals(action, tmlActivityElementWithAction.getAction()); diff --git a/src/main/java/tmltranslator/TMLActivityElementWithIntervalAction.java b/src/main/java/tmltranslator/TMLActivityElementWithIntervalAction.java index 2fcae175312a7158f619f5784bb070fc9e402744..a1400ba132073039b682f201888698d147cf1057 100755 --- a/src/main/java/tmltranslator/TMLActivityElementWithIntervalAction.java +++ b/src/main/java/tmltranslator/TMLActivityElementWithIntervalAction.java @@ -85,7 +85,6 @@ public abstract class TMLActivityElementWithIntervalAction extends TMLActivityEl @Override public boolean equalSpec(Object o) { - if (!(o instanceof TMLActivityElementWithIntervalAction)) return false; if (!super.equalSpec(o)) return false; TMLActivityElementWithIntervalAction tmlAEIAction = (TMLActivityElementWithIntervalAction) o; diff --git a/src/main/java/tmltranslator/TMLAttribute.java b/src/main/java/tmltranslator/TMLAttribute.java index 1ff191a0792a4073481ada8e3d9e46ecd9600617..c73068f95ec31a3b44c5f704c5c0d3fa989fdc21 100755 --- a/src/main/java/tmltranslator/TMLAttribute.java +++ b/src/main/java/tmltranslator/TMLAttribute.java @@ -139,17 +139,24 @@ public class TMLAttribute extends DIPLOElement { return "unknown"; } - @Override public boolean equals( Object o ) { - if( !(o instanceof TMLAttribute ) ) { + @Override + public boolean equals(Object o) { + if (!(o instanceof TMLAttribute)) { return false; } - else { - TMLAttribute attr = (TMLAttribute)o; - return ( name.equals( attr.getName() ) && ( type.equals( attr.getType()) ) ); - } + TMLAttribute attr = (TMLAttribute) o; + return (name.equals(attr.getName()) && (type.equals(attr.getType()))); //return ( (name.equals( _other.getName() )) && ( initialValue.equals( _other.getInitialValue() )) && (type.equals( _other.getType() )) ); } + public boolean equalSpec(Object o) { + if (!(o instanceof TMLAttribute)) { + return false; + } + TMLAttribute attr = (TMLAttribute) o; + return (name.equals(attr.getName())) && (initialValue.equals(attr.getInitialValue())) && (type.equalSpec(attr.getType())); + } + @Override public int hashCode() { int result = 17; if( name == null ) { diff --git a/src/main/java/tmltranslator/TMLChoice.java b/src/main/java/tmltranslator/TMLChoice.java index 84147db3d165dc02407123c2358d8d9977434dd0..9d0797e11f4f67b31fe0df3fb443260949b6878d 100755 --- a/src/main/java/tmltranslator/TMLChoice.java +++ b/src/main/java/tmltranslator/TMLChoice.java @@ -353,7 +353,6 @@ public class TMLChoice extends TMLActivityElement{ @Override public boolean equalSpec(Object o) { - if (!(o instanceof TMLChoice)) return false; if (!super.equalSpec(o)) return false; TMLChoice tmlChoice = (TMLChoice) o; return (new HashSet<>(guards)).equals(new HashSet<>(tmlChoice.getGuards())); diff --git a/src/main/java/tmltranslator/TMLComparingMethod.java b/src/main/java/tmltranslator/TMLComparingMethod.java index 636f4d4d21950366fd71c24ff3b8ded661c41359..b27ceaaacc434c682515b4973ecfd90801bdeff1 100644 --- a/src/main/java/tmltranslator/TMLComparingMethod.java +++ b/src/main/java/tmltranslator/TMLComparingMethod.java @@ -44,10 +44,10 @@ public class TMLComparingMethod { return true; } //Only one of them is null - else if(list1 == null || list2 == null) { + else if (list1 == null || list2 == null) { return false; } - else if(list1.size() != list2.size()) { + else if (list1.size() != list2.size()) { return false; } @@ -193,14 +193,16 @@ public class TMLComparingMethod { boolean test; for (SecurityPattern spMap1 : map1.keySet()) { + boolean isEqual = false; for (SecurityPattern spMap2 : map2.keySet()) { if (spMap1.getName().equals(spMap2.getName())) { test = isHwMemoryListEquals(map1.get(spMap1), map2.get(spMap2)); if (!test) return false; + isEqual = true; break; } } - return false; + if (!isEqual) return false; } return true; @@ -240,18 +242,15 @@ public class TMLComparingMethod { return true; } //Only one of them is null - else if(list1 == null || list2 == null) { + else if (list1 == null || list2 == null) { return false; } - else if(list1.size() != list2.size()) { + else if (list1.size() != list2.size()) { return false; } - boolean test; - - for (int i = 0; i< list1.size(); i++) { - test = list1.get(i).equalSpec(list2.get(i)); - if (!test) return false; + for (int i = 0; i < list1.size(); i++) { + if (!list1.get(i).equalSpec(list2.get(i))) return false; } return true; } @@ -346,7 +345,7 @@ public class TMLComparingMethod { public boolean isTMLChannelSetEquals(Set<TMLChannel> channelSet1, Set<TMLChannel> channelSet2) { if (channelSet1 == null && channelSet2 == null) return true; - if (channelSet1 == null|| channelSet2 == null) return false; + if (channelSet1 == null || channelSet2 == null) return false; if(channelSet1.size() != channelSet2.size()) return false; @@ -384,8 +383,53 @@ public class TMLComparingMethod { test = events1.get(i).equalSpec(events2.get(i)); if (!test) return false; } + return true; + } + // Check equality of two security pattern specifications + public boolean isSecurityPatternEquals(SecurityPattern sp1, SecurityPattern sp2) { + if (sp1 == null && sp2 == null) return true; + else if (sp1 == null || sp2 == null) { + return false; + } + return (sp1.equalSpec(sp2)); + } + + // Check equality of two TMLAttribute Lists + public boolean isTMLAttributeListEquals(List<TMLAttribute> attributeList1, List<TMLAttribute> attributeList2) { + if (attributeList1 == null && attributeList2 == null) return true; + if (attributeList1 == null || attributeList2 == null) return false; + if(attributeList1.size() != attributeList2.size()) return false; + + for (TMLAttribute attrib : attributeList1) { + boolean isEqualAttrib = false; + for (TMLAttribute attrib2 : attributeList2) { + if (!attrib.equalSpec(attrib2)) { + isEqualAttrib = true; + break; + } + } + if (!isEqualAttrib) return false; + } return true; } + // Check if the two TMLActivityElementChannel have the same channels list. + public boolean isTMLChannelListEquals(List<TMLChannel> channelList1, List<TMLChannel> channelList2) { + if (channelList1 == null && channelList2 == null) return true; + if (channelList1 == null || channelList2 == null) return false; + if(channelList1.size() != channelList2.size()) return false; + + for (TMLChannel ch : channelList1) { + boolean isEqualChan = false; + for (TMLChannel ch2 : channelList2) { + if (!ch.equalSpec(ch2)) { + isEqualChan = true; + break; + } + } + if (!isEqualChan) return false; + } + return true; + } } diff --git a/src/main/java/tmltranslator/TMLDelay.java b/src/main/java/tmltranslator/TMLDelay.java index 7ae1a4103171c7f58a45e5eb85e9e244d6999fd3..3510ae48dc1b9b91953550c202c02f5767dd0606 100755 --- a/src/main/java/tmltranslator/TMLDelay.java +++ b/src/main/java/tmltranslator/TMLDelay.java @@ -95,7 +95,6 @@ public class TMLDelay extends TMLActivityElementWithIntervalAction { @Override public boolean equalSpec(Object o) { - if (! (o instanceof TMLDelay)) return false; if (!super.equalSpec(o)) return false; TMLDelay tmlDelay = (TMLDelay) o; diff --git a/src/main/java/tmltranslator/TMLExecC.java b/src/main/java/tmltranslator/TMLExecC.java index b736434d6defef019daf0ab6f2195bb125245844..dddc500dd436394246e690bf2c88569d54280113 100755 --- a/src/main/java/tmltranslator/TMLExecC.java +++ b/src/main/java/tmltranslator/TMLExecC.java @@ -74,7 +74,6 @@ public class TMLExecC extends TMLActivityElementWithAction { @Override public boolean equalSpec(Object o) { - if (!(o instanceof TMLExecC)) return false; if (!super.equalSpec(o)) return false; TMLExecC tmlExecC = (TMLExecC) o; return Objects.equals(isDecryptionProcess, tmlExecC.isDecryptionProcess()); diff --git a/src/main/java/tmltranslator/TMLForLoop.java b/src/main/java/tmltranslator/TMLForLoop.java index 8c0ea888b0fdfb88f30f8a800c1251e0de2b8c85..6a030b569eea8accfb9c23e3b3bf44eb11da0bcb 100755 --- a/src/main/java/tmltranslator/TMLForLoop.java +++ b/src/main/java/tmltranslator/TMLForLoop.java @@ -85,7 +85,6 @@ public class TMLForLoop extends TMLActivityElement { @Override public boolean equalSpec(Object o) { - if (!(o instanceof TMLForLoop)) return false; if(!super.equalSpec(o)) return false; TMLForLoop tmlForLoop = (TMLForLoop) o; return Objects.equals(init, tmlForLoop.getInit()) && diff --git a/src/main/java/tmltranslator/TMLRandom.java b/src/main/java/tmltranslator/TMLRandom.java index 0a5c1dc8641158c05518407ad568b4ef98e3014f..613db754ba26d3c7b6ec4878391a0b87f8e634ea 100755 --- a/src/main/java/tmltranslator/TMLRandom.java +++ b/src/main/java/tmltranslator/TMLRandom.java @@ -76,7 +76,6 @@ public class TMLRandom extends TMLActivityElement { @Override public boolean equalSpec(Object o) { - if (!(o instanceof TMLRandom)) return false; if (!super.equalSpec(o)) return false; TMLRandom tmlRandom = (TMLRandom) o; diff --git a/src/main/java/tmltranslator/TMLRandomSequence.java b/src/main/java/tmltranslator/TMLRandomSequence.java index 07741656c533fc54d6de4f576a774c888a69b20e..29af794568a96b5499c4a7c871429933e54ab4e1 100755 --- a/src/main/java/tmltranslator/TMLRandomSequence.java +++ b/src/main/java/tmltranslator/TMLRandomSequence.java @@ -108,7 +108,6 @@ public class TMLRandomSequence extends TMLActivityElement { @Override public boolean equalSpec(Object o) { - if (!(o instanceof TMLRandomSequence)) return false; if (!super.equalSpec(o)) return false; TMLRandomSequence tmlRS = (TMLRandomSequence) o; diff --git a/src/main/java/tmltranslator/TMLSendRequest.java b/src/main/java/tmltranslator/TMLSendRequest.java index 77de3b26ac0bc5a18c0519858767412f84c9ee04..4ec2e96281e87d8f73b3d8ce21f1b717f3028f19 100755 --- a/src/main/java/tmltranslator/TMLSendRequest.java +++ b/src/main/java/tmltranslator/TMLSendRequest.java @@ -125,11 +125,10 @@ public class TMLSendRequest extends TMLActivityElement { @Override public boolean equalSpec(Object o) { - if (!(o instanceof TMLSendRequest)) return false; if (!super.equalSpec(o)) return false; TMLSendRequest tmlSendRequest = (TMLSendRequest) o; - if (!request.equalSpec(tmlSendRequest.getRequest())) return false; + //if (!request.equalSpec(tmlSendRequest.getRequest())) return false; return (new HashSet<>(datas)).equals(new HashSet<>(tmlSendRequest.getDatas())); } diff --git a/src/main/java/tmltranslator/TMLSequence.java b/src/main/java/tmltranslator/TMLSequence.java index 8f50cdc68d575894c92414b3c1f9b8abbc934df4..90255352d4e8b9dbb962ed9c021e2221e93415a3 100755 --- a/src/main/java/tmltranslator/TMLSequence.java +++ b/src/main/java/tmltranslator/TMLSequence.java @@ -103,7 +103,6 @@ public class TMLSequence extends TMLActivityElement { @Override public boolean equalSpec(Object o) { - if (!(o instanceof TMLSequence)) return false; if (!super.equalSpec(o)) return false; TMLSequence tmlSequence = (TMLSequence) o; diff --git a/src/main/java/tmltranslator/TMLTask.java b/src/main/java/tmltranslator/TMLTask.java index 1fdc66ec15886b2942c08dc3739b127c54359e7d..8bf7e31152f8d28efc57fbe4b403c021af0206cd 100755 --- a/src/main/java/tmltranslator/TMLTask.java +++ b/src/main/java/tmltranslator/TMLTask.java @@ -583,9 +583,7 @@ public class TMLTask extends TMLElement { } //TraceManager.addDev("Going to compare attributes"); - - if (!(new HashSet<>(attributes).equals(new HashSet<>(tmlTask.attributes)))) - return false; + if (!comp.isTMLAttributeListEquals(attributes, tmlTask.getAttributes())) return false; //TraceManager.addDev("HashSet of attributes ok"); diff --git a/src/main/java/tmltranslator/TMLType.java b/src/main/java/tmltranslator/TMLType.java index 2b3bff733aa445a980c1b6a5448031658693516a..9f0d452183eeea3e96b3c84d076b5f2b067098da 100755 --- a/src/main/java/tmltranslator/TMLType.java +++ b/src/main/java/tmltranslator/TMLType.java @@ -162,14 +162,20 @@ public class TMLType { return getStringType(type); } - public boolean equals( Object o ) { - if( !( o instanceof TMLType ) ) { + public boolean equals(Object o) { + if (!(o instanceof TMLType)) { return false; } - else { - TMLType tt = (TMLType)o; - return ( getType() == tt.getType() ); + TMLType tt = (TMLType) o; + return (getType() == tt.getType()); + } + + public boolean equalSpec(Object o) { + if (!(o instanceof TMLType)) { + return false; } + TMLType tt = (TMLType) o; + return (getType() == tt.getType()) && typeOther.equals(tt.getTypeOther()); } @Override public int hashCode() {