ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/trunk/proteinstructure/GenericContact.java
Revision: 185
Committed: Thu Jun 7 09:14:46 2007 UTC (17 years, 3 months ago) by duarte
File size: 1016 byte(s)
Log Message:
Implemented hashCode method in Contact and GenericContact. Was necessary to use these classes as keys in Maps
Fixed bug in equals method in GenericContact
Changed middle character from "\t" to " " in toString
Line User Rev File contents
1 duarte 184 package proteinstructure;
2     import java.lang.Comparable;
3    
4     public class GenericContact implements Comparable {
5    
6     public String i_res;
7     public String j_res;
8    
9     public GenericContact(String i_res,String j_res){
10     this.i_res=i_res;
11     this.j_res=j_res;
12     }
13    
14     public int compareTo(Object o) {
15     int diff=0;
16     GenericContact other = (GenericContact) o;
17     if (this.i_res.compareTo(other.i_res)>0){
18     diff=1;
19     }
20     else if (this.i_res.compareTo(other.i_res)<0){
21     diff=-1;
22     }
23     else if (this.i_res.equals(other.i_res)){
24     if (this.j_res.compareTo(other.j_res)>0){
25     diff=1;
26     }
27     else if (this.j_res.compareTo(other.j_res)<0){
28     diff=-1;
29     }
30     }
31     return diff;
32     }
33    
34     public boolean equals(Object o){
35     boolean eq = false;
36     GenericContact other = (GenericContact) o;
37 duarte 185 if (this.i_res.equals(other.i_res) && this.j_res.equals(other.j_res)){
38 duarte 184 eq=true;
39     }
40     return eq;
41     }
42    
43     public String toString() {
44 duarte 185 return this.i_res+" "+this.j_res;
45 duarte 184 }
46 duarte 185
47     public int hashCode() {
48     return this.toString().hashCode();
49     }
50    
51 duarte 184 }