From 98370d91a5ffe1024413502963f04e7fed936afb Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 12 May 2017 15:53:29 +0100 Subject: [PATCH] JAL-2480 java.util.RangeComparator renamed IntRangeComparator --- src/jalview/util/IntRangeComparator.java | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/jalview/util/IntRangeComparator.java diff --git a/src/jalview/util/IntRangeComparator.java b/src/jalview/util/IntRangeComparator.java new file mode 100644 index 0000000..cb32a0e --- /dev/null +++ b/src/jalview/util/IntRangeComparator.java @@ -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 +{ + public static final Comparator ASCENDING = new IntRangeComparator( + true); + + public static final Comparator 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 -- 1.7.10.2