ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/trunk/proteinstructure/Contact.java
Revision: 224
Committed: Thu Jul 5 13:42:37 2007 UTC (17 years, 2 months ago) by duarte
File size: 982 byte(s)
Log Message:
Now calculate distance matrix uses HashMap instead of TreeMap
Needed to change the hashCode function in Contact to make it faster
Line User Rev File contents
1 duarte 123 package proteinstructure;
2     import java.lang.Comparable;
3    
4     public class Contact implements Comparable {
5    
6     public int i;
7     public int j;
8    
9     public Contact(int i,int j){
10     this.i=i;
11     this.j=j;
12     }
13    
14     public int compareTo(Object o) {
15     int diff=0;
16     Contact other = (Contact) o;
17     if (this.i>other.i){
18     diff=1;
19     }
20     else if (this.i<other.i){
21     diff=-1;
22     }
23     else if (this.i==other.i){
24     if (this.j>other.j){
25     diff=1;
26     }
27     else if (this.j<other.j){
28     diff=-1;
29     }
30     }
31     return diff;
32     }
33    
34     public boolean equals(Object o){
35     boolean eq = false;
36     Contact other = (Contact) o;
37     if (this.i==other.i && this.j==other.j){
38     eq=true;
39     }
40     return eq;
41     }
42 duarte 185
43     public String toString() {
44     return this.i+" "+this.j;
45     }
46 duarte 175
47 duarte 185 public int hashCode() {
48 duarte 224 return i*100000+j; // hash function found after a lot of experimenting!! do not touch!
49 duarte 185 }
50    
51     /**
52     * Gets range (i.e. sequence separation) of contact
53     * @return
54     */
55 duarte 175 public int getRange(){
56     return Math.abs(this.i-this.j);
57     }
58 duarte 178
59 duarte 123 }