JAL-2480 java.util.RangeComparator renamed IntRangeComparator
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 12 May 2017 14:53:29 +0000 (15:53 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 12 May 2017 14:53:29 +0000 (15:53 +0100)
src/jalview/util/IntRangeComparator.java [new file with mode: 0644]

diff --git a/src/jalview/util/IntRangeComparator.java b/src/jalview/util/IntRangeComparator.java
new file mode 100644 (file)
index 0000000..cb32a0e
--- /dev/null
@@ -0,0 +1,31 @@
+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