--- /dev/null
+package jalview.util;
+
+import java.util.Comparator;
+
+/**
+ * A comparator to order [from, to] ranges into ascending or descending order of
+ * their start position
+ */
+public class IntRangeComparator implements Comparator<int[]>
+{
+ public static final Comparator<int[]> ASCENDING = new IntRangeComparator(
+ true);
+
+ public static final Comparator<int[]> DESCENDING = new IntRangeComparator(
+ false);
+
+ boolean forwards;
+
+ IntRangeComparator(boolean forward)
+ {
+ forwards = forward;
+ }
+
+ @Override
+ public int compare(int[] o1, int[] o2)
+ {
+ int compared = Integer.compare(o1[0], o2[0]);
+ return forwards ? compared : -compared;
+ }
+
+}
\ No newline at end of file