Clean-up, refactoring, commenting. Parameters file containts only options since Jalvi...
[jabaws.git] / datamodel / compbio / data / sequence / Range.java
1 /* Copyright (c) 2011 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0     \r
4  * \r
5  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
6  *  Apache License version 2 as published by the Apache Software Foundation\r
7  * \r
8  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
9  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
10  *  License for more details.\r
11  * \r
12  *  A copy of the license is in apache_license.txt. It is also available here:\r
13  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 package compbio.data.sequence;\r
19 \r
20 public class Range implements Comparable<Range> {\r
21 \r
22         public final int from;\r
23         public final int to;\r
24 \r
25         private Range() {\r
26                 // JAXB default constructor should not be used\r
27                 from = 0;\r
28                 to = from;\r
29         }\r
30 \r
31         public Range(int from, int to) {\r
32                 this.from = from;\r
33                 this.to = to;\r
34         }\r
35 \r
36         public Range(String[] twoElementAr) {\r
37                 if (twoElementAr == null || twoElementAr.length != 2) {\r
38                         throw new IllegalArgumentException();\r
39                 }\r
40                 this.from = Integer.parseInt(twoElementAr[0].trim());\r
41                 this.to = Integer.parseInt(twoElementAr[1].trim());\r
42         }\r
43         \r
44         @Override\r
45         public String toString() {\r
46                 return from + "-" + to;\r
47         }\r
48         \r
49 \r
50         @Override\r
51         public int hashCode() {\r
52                 final int prime = 31;\r
53                 int result = 1;\r
54                 result = prime * result + from;\r
55                 result = prime * result + to;\r
56                 return result;\r
57         }\r
58         @Override\r
59         public boolean equals(Object obj) {\r
60                 if (this == obj)\r
61                         return true;\r
62                 if (obj == null)\r
63                         return false;\r
64                 if (getClass() != obj.getClass())\r
65                         return false;\r
66                 Range other = (Range) obj;\r
67                 if (from != other.from)\r
68                         return false;\r
69                 if (to != other.to)\r
70                         return false;\r
71                 return true;\r
72         }\r
73 \r
74         /*\r
75          *  Daniel messed with this method.\r
76          *  It now compares Ranges based on \r
77          */\r
78         \r
79 //      @Override\r
80 //      public int compareTo(Range o) {\r
81 //              if (o == null)\r
82 //                      return 1;\r
83 //              return new Integer(this.from).compareTo(new Integer(o.from));\r
84 //      }\r
85         \r
86         @Override\r
87         public int compareTo(Range o) {\r
88                 if (o == null)\r
89                         return 1;\r
90                 if (new Integer(this.from).compareTo(new Integer(o.from)) != 0) {\r
91                         return new Integer(this.from).compareTo(new Integer(o.from));\r
92                 }\r
93                 else {\r
94                         return new Integer(this.to).compareTo(new Integer(o.to));\r
95                 }\r
96         }\r
97 \r
98 }\r