1 /* Copyright (c) 2011 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0
\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
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
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
15 * Any republication or derived work distributed in source code form
\r
16 * must include this copyright and license notice.
\r
18 package compbio.data.sequence;
\r
20 public class Range implements Comparable<Range> {
\r
22 public final int from;
\r
23 public final int to;
\r
26 // JAXB default constructor should not be used
\r
31 public Range(int from, int to) {
\r
36 public Range(String[] twoElementAr) {
\r
37 if (twoElementAr == null || twoElementAr.length != 2) {
\r
38 throw new IllegalArgumentException();
\r
40 this.from = Integer.parseInt(twoElementAr[0].trim());
\r
41 this.to = Integer.parseInt(twoElementAr[1].trim());
\r
45 public String toString() {
\r
46 return from + "-" + to;
\r
51 public int hashCode() {
\r
52 final int prime = 31;
\r
54 result = prime * result + from;
\r
55 result = prime * result + to;
\r
59 public boolean equals(Object obj) {
\r
64 if (getClass() != obj.getClass())
\r
66 Range other = (Range) obj;
\r
67 if (from != other.from)
\r
75 * Daniel messed with this method.
\r
76 * It now compares Ranges based on
\r
80 // public int compareTo(Range o) {
\r
83 // return new Integer(this.from).compareTo(new Integer(o.from));
\r
87 public int compareTo(Range o) {
\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
94 return new Integer(this.to).compareTo(new Integer(o.to));
\r