Skip to content

Commit 2ddf8b0

Browse files
author
Sreejith Nair
committed
Refactoring Decompose conditional : Changes to refactor getContactOverlapScore method to eliminate complex conditional smell
1 parent bf40264 commit 2ddf8b0

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

biojava-structure/src/main/java/org/biojava/nbio/structure/contact/StructureInterface.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -616,10 +616,7 @@ public double getContactOverlapScore(StructureInterface other, boolean invert) {
616616
Pair<EntityInfo> thisCompounds = new Pair<EntityInfo>(thisChains.getFirst().getEntityInfo(), thisChains.getSecond().getEntityInfo());
617617
Pair<EntityInfo> otherCompounds = new Pair<EntityInfo>(otherChains.getFirst().getEntityInfo(), otherChains.getSecond().getEntityInfo());
618618

619-
if ( ( (thisCompounds.getFirst().getMolId() == otherCompounds.getFirst().getMolId()) &&
620-
(thisCompounds.getSecond().getMolId() == otherCompounds.getSecond().getMolId()) ) ||
621-
( (thisCompounds.getFirst().getMolId() == otherCompounds.getSecond().getMolId()) &&
622-
(thisCompounds.getSecond().getMolId() == otherCompounds.getFirst().getMolId()) ) ) {
619+
if (checkMolIdMatch(thisCompounds,otherCompounds)) {
623620

624621
int common = 0;
625622
GroupContactSet thisContacts = getGroupContacts();
@@ -653,6 +650,17 @@ public double getContactOverlapScore(StructureInterface other, boolean invert) {
653650
}
654651
}
655652

653+
/**
654+
* This method check if two compounds have same MolIds or not.
655+
* @param thisCompounds
656+
* @param otherCompounds
657+
* @return
658+
*/
659+
private boolean checkMolIdMatch(Pair<EntityInfo> thisCompounds, Pair<EntityInfo> otherCompounds){
660+
boolean firstMatch = thisCompounds.getFirst().getMolId() == otherCompounds.getFirst().getMolId() && thisCompounds.getSecond().getMolId() == otherCompounds.getSecond().getMolId();
661+
boolean secondMatch = thisCompounds.getFirst().getMolId() == otherCompounds.getSecond().getMolId() && thisCompounds.getSecond().getMolId() == otherCompounds.getFirst().getMolId();
662+
return firstMatch || secondMatch;
663+
}
656664
public GroupContactSet getGroupContacts() {
657665
if (groupContacts==null) {
658666
this.groupContacts = new GroupContactSet(contacts);

0 commit comments

Comments
 (0)