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