1 |
package proteinstructure; |
2 |
import java.lang.Comparable; |
3 |
|
4 |
public class Edge implements Comparable { |
5 |
|
6 |
public int i; |
7 |
public int j; |
8 |
|
9 |
public Edge(int i,int j){ |
10 |
this.i=i; |
11 |
this.j=j; |
12 |
} |
13 |
|
14 |
public int compareTo(Object o) { |
15 |
Edge other = (Edge) o; |
16 |
if (this.i>other.i){ |
17 |
return 1; |
18 |
} |
19 |
else if (this.i<other.i){ |
20 |
return -1; |
21 |
} |
22 |
else { // only remains case this.i==other.i |
23 |
if (this.j>other.j){ |
24 |
return 1; |
25 |
} |
26 |
else if (this.j<other.j){ |
27 |
return -1; |
28 |
} |
29 |
} |
30 |
return 0; // if none of the conditions before returned, then both i and j are equal |
31 |
} |
32 |
|
33 |
public boolean equals(Object o){ |
34 |
Edge other = (Edge) o; |
35 |
if (this.i==other.i && this.j==other.j){ |
36 |
return true; |
37 |
} |
38 |
return false; |
39 |
} |
40 |
|
41 |
public String toString() { |
42 |
return this.i+" "+this.j; |
43 |
} |
44 |
|
45 |
public int hashCode() { |
46 |
return i*100000+j; // hash function found after a lot of experimenting!! do not touch! |
47 |
} |
48 |
|
49 |
/** |
50 |
* Gets range (i.e. sequence separation) of contact |
51 |
* @return |
52 |
*/ |
53 |
public int getRange(){ |
54 |
return Math.abs(this.i-this.j); |
55 |
} |
56 |
|
57 |
} |