import jalview.util.DBRefUtils;
import jalview.util.MapList;
import jalview.util.MappingUtils;
+import jalview.util.RangeComparator;
import jalview.util.StringUtils;
import java.io.UnsupportedEncodingException;
* ranges are assembled in order. Other cases should not use this method,
* but instead construct an explicit mapping for CDS (e.g. EMBL parsing).
*/
- Collections.sort(result, new Comparator<int[]>()
- {
- @Override
- public int compare(int[] o1, int[] o2)
- {
- return Integer.compare(o1[0], o2[0]);
- }
- });
+ Collections.sort(result, new RangeComparator(true));
return result;
}
import jalview.util.Comparison;
import jalview.util.DBRefUtils;
import jalview.util.MapList;
+import jalview.util.RangeComparator;
import java.io.IOException;
import java.net.MalformedURLException;
}
/**
- * A comparator to sort ranges into ascending start position order
- */
- private class RangeSorter implements Comparator<int[]>
- {
- boolean forwards;
-
- RangeSorter(boolean forward)
- {
- forwards = forward;
- }
-
- @Override
- public int compare(int[] o1, int[] o2)
- {
- return (forwards ? 1 : -1) * Integer.compare(o1[0], o2[0]);
- }
-
- }
-
- /**
* Default constructor (to use rest.ensembl.org)
*/
public EnsemblSeqProxy()
* a final sort is needed since Ensembl returns CDS sorted within source
* (havana / ensembl_havana)
*/
- Collections.sort(regions, new RangeSorter(direction == 1));
+ Collections.sort(regions, new RangeComparator(direction == 1));
List<int[]> to = Arrays.asList(new int[] { start,
start + mappedLength - 1 });
--- /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 RangeComparator implements Comparator<int[]>
+{
+ boolean forwards;
+
+ public RangeComparator(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