1 |
duarte |
222 |
package proteinstructure; |
2 |
|
|
import java.lang.Comparable; |
3 |
|
|
/** |
4 |
|
|
* Class representing a residue interval with a beginning |
5 |
|
|
* and an end serial |
6 |
|
|
* The compareTo method is at the moment exactly the same as |
7 |
|
|
* in Contact class. It doesn't make much sense like this but we |
8 |
|
|
* keep it as it allows Interval objects to be keys in maps |
9 |
|
|
* |
10 |
|
|
* @author Jose Duarte |
11 |
|
|
* |
12 |
|
|
*/ |
13 |
|
|
public class Interval implements Comparable { |
14 |
|
|
|
15 |
|
|
public int beg; |
16 |
|
|
public int end; |
17 |
|
|
|
18 |
|
|
public Interval(int beg,int end){ |
19 |
|
|
this.beg=beg; |
20 |
|
|
this.end=end; |
21 |
|
|
} |
22 |
|
|
|
23 |
|
|
public int compareTo(Object o) { |
24 |
|
|
int diff=0; |
25 |
|
|
Interval other = (Interval) o; |
26 |
|
|
if (this.beg>other.beg){ |
27 |
|
|
diff=1; |
28 |
|
|
} |
29 |
|
|
else if (this.beg<other.beg){ |
30 |
|
|
diff=-1; |
31 |
|
|
} |
32 |
|
|
else if (this.beg==other.beg){ |
33 |
|
|
if (this.end>other.end){ |
34 |
|
|
diff=1; |
35 |
|
|
} |
36 |
|
|
else if (this.end<other.end){ |
37 |
|
|
diff=-1; |
38 |
|
|
} |
39 |
|
|
} |
40 |
|
|
return diff; |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
public int getLength(){ |
44 |
|
|
return (end - beg); |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
public boolean equals(Object o){ |
48 |
|
|
boolean eq = false; |
49 |
|
|
Interval other = (Interval) o; |
50 |
|
|
if (this.beg==other.beg && this.end==other.end){ |
51 |
|
|
eq=true; |
52 |
|
|
} |
53 |
|
|
return eq; |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
public String toString() { |
57 |
|
|
return this.beg+" "+this.end; |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
public int hashCode() { |
61 |
|
|
return this.toString().hashCode(); |
62 |
|
|
} |
63 |
|
|
|
64 |
|
|
} |