1 package jalview.datamodel.features;
3 import java.util.Comparator;
6 * A comparator that orders ranges by either start position or end position
7 * ascending. If the position matches,
12 public class RangeComparator implements Comparator<ContiguousI>
17 public int compare(ContiguousI o1, ContiguousI o2)
19 int len1 = o1.getEnd() - o1.getBegin();
20 int len2 = o2.getEnd() - o2.getBegin();
24 return compare(o1.getBegin(), o2.getBegin(), len1, len2);
28 return compare(o1.getEnd(), o2.getEnd(), len1, len2);
33 * Compares two ranges for ordering
36 * first range positional ordering criterion
38 * second range positional ordering criterion
40 * first range length ordering criterion
42 * second range length ordering criterion
45 public int compare(long pos1, long pos2, int len1, int len2)
47 int order = Long.compare(pos1, pos2);
51 * if tied on position order, longer length sorts to left
52 * i.e. the negation of normal ordering by length
54 order = -Integer.compare(len1, len2);
62 * @param byStartPosition
63 * if true, order based on start position, if false by end position
65 public RangeComparator(boolean byStartPosition)
67 byStart = byStartPosition;