Change header template for a new version
[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         @Override\r
50         public int hashCode() {\r
51                 final int prime = 31;\r
52                 int result = 1;\r
53                 result = prime * result + from;\r
54                 result = prime * result + to;\r
55                 return result;\r
56         }\r
57         @Override\r
58         public boolean equals(Object obj) {\r
59                 if (this == obj)\r
60                         return true;\r
61                 if (obj == null)\r
62                         return false;\r
63                 if (getClass() != obj.getClass())\r
64                         return false;\r
65                 Range other = (Range) obj;\r
66                 if (from != other.from)\r
67                         return false;\r
68                 if (to != other.to)\r
69                         return false;\r
70                 return true;\r
71         }\r
72 \r
73         @Override\r
74         public int compareTo(Range o) {\r
75                 if (o == null)\r
76                         return 1;\r
77                 return new Integer(this.from).compareTo(new Integer(o.from));\r
78         }\r
79 \r
80 }\r