2020 */
2121package org .biojava .nbio .structure .align .client ;
2222
23+ import java .util .Objects ;
24+
2325import org .biojava .nbio .structure .StructureException ;
2426
2527/**
26- * A pair for structure alignment
27- * <p>
28- * name1 is always < name2
28+ * A pair for structure alignment.
29+ * a pair is considered equal to another pair if their two respective tuple poles are equal either in their original or reversed order.
30+ * i.e. both <code>new PdbPair("1abc", "2abc").equals(new PdbPair("1abc", "2abc"))</code> and
31+ * <code>new PdbPair("1abc", "2abc").equals(new PdbPair("2abc", "1abc"))</code> are <code>true</code>.
2932 * @author Andreas Prlic
3033 *
3134 */
@@ -35,26 +38,26 @@ public class PdbPair implements Comparable<PdbPair> {
3538 private StructureName name2 ;
3639
3740 public PdbPair (String name1 , String name2 ) {
38- this (new StructureName (name1 ),new StructureName (name2 ));
41+ this (new StructureName (Objects .requireNonNull (name1 )),
42+ new StructureName (Objects .requireNonNull (name1 )));
3943 }
4044
4145 public PdbPair (StructureName name1 , StructureName name2 ) {
42- super ();
43- this .name1 = name1 ;
44- this .name2 = name2 ;
46+ this .name1 = Objects .requireNonNull (name1 );
47+ this .name2 = Objects .requireNonNull (name2 );
4548 }
4649
4750 public String getName1 () {
4851 return name1 .getIdentifier ();
4952 }
5053 public void setName1 (String name1 ) {
51- this .name1 = new StructureName (name1 );
54+ this .name1 = new StructureName (Objects . requireNonNull ( name1 ) );
5255 }
5356 public String getName2 () {
5457 return name2 .getIdentifier ();
5558 }
5659 public void setName2 (String name2 ) {
57- this .name2 = new StructureName (name2 );
60+ this .name2 = new StructureName (Objects . requireNonNull ( name2 ) );
5861 }
5962
6063 @ Override
@@ -64,11 +67,7 @@ public String toString() {
6467
6568 @ Override
6669 public int hashCode () {
67- final int prime = 31 ;
68- int result = 1 ;
69- result = prime * result + ((name1 == null ) ? 0 : name1 .hashCode ());
70- result = prime * result + ((name2 == null ) ? 0 : name2 .hashCode ());
71- return result ;
70+ return Objects .hashCode (name1 ) + Objects .hashCode (name2 );
7271 }
7372
7473 @ Override
@@ -80,23 +79,16 @@ public boolean equals(Object obj) {
8079 if (getClass () != obj .getClass ())
8180 return false ;
8281 PdbPair other = (PdbPair ) obj ;
83- if (name1 == null ) {
84- if (other .name1 != null )
85- return false ;
86- } else if (!name1 .equals (other .name1 ))
87- return false ;
88- if (name2 == null ) {
89- if (other .name2 != null )
90- return false ;
91- } else if (!name2 .equals (other .name2 ))
92- return false ;
93- return true ;
82+ return (this .name1 .equals (other .name1 ) && this .name2 .equals (other .name2 )) ||
83+ (this .name1 .equals (other .name2 ) && this .name2 .equals (other .name1 ));
9484 }
9585
9686 @ Override
9787 public int compareTo (PdbPair o ) {
88+ //make sure they are not just reverse.
9889 if ( this .equals (o ))
9990 return 0 ;
91+
10092 // Use StructureName's compareTo method
10193 int c = name1 .compareTo (o .name1 );
10294 if ( c != 0 )
@@ -119,7 +111,6 @@ public String getChainId2(){
119111 }
120112
121113 public PdbPair getReverse () {
122- PdbPair newPair = new PdbPair (name2 , name1 );
123- return newPair ;
114+ return new PdbPair (name2 , name1 );
124115 }
125116}
0 commit comments