ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/trunk/proteinstructure/Edge.java
Revision: 238
Committed: Fri Jul 20 10:02:03 2007 UTC (17 years, 7 months ago) by duarte
File size: 1032 byte(s)
Log Message:
Optimised slightly the compareTo method in Edge
Line File contents
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 }