From: gmungoc Date: Fri, 12 May 2017 14:53:29 +0000 (+0100) Subject: JAL-2480 java.util.RangeComparator renamed IntRangeComparator X-Git-Tag: Release_2_10_3b1~286 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=98370d91a5ffe1024413502963f04e7fed936afb;p=jalview.git JAL-2480 java.util.RangeComparator renamed IntRangeComparator --- 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