*/
public class NCListBuilder<T extends IntervalI>
{
+ /**
+ * Compares two intervals in a way that will sort a list by start position
+ * ascending, then by length descending
+ */
class NCListComparator<V extends IntervalI> implements Comparator<V>
{
- /**
- * Compares two intervals in a way that will sort a list by start position
- * ascending, then by length descending. Answers
- * <ul>
- * <li>a negative value if o1.begin < o2.begin</li>
- * <li>else a positive value if o1.begin > o2.begin</li>
- * <li>else a negative value if o1.end > o2.end</li>
- * <li>else a positive value of o1.end < o2.end</li>
- * <li>else zero</li
- * </ul>
- */
@Override
public int compare(V o1, V o2)
{
int order = Integer.compare(o1.getBegin(), o2.getBegin());
if (order == 0)
{
- /*
- * if tied on start position, longer length sorts to left
- * i.e. the negation of normal ordering by length
- */
order = Integer.compare(o2.getEnd(), o1.getEnd());
}
return order;
}
}
-
- private Comparator<T> comparator = new NCListComparator<>();
/**
* Default constructor
}
/**
- * Answers a comparator which sorts items of type T by start position
- * ascending, and within that by end position (length) descending)
- *
- * @return
- */
- Comparator<T> getComparator()
- {
- return comparator;
- }
-
- /**
* Sorts and traverses the ranges to identify sublists, whose start intervals
* are overlapping or disjoint but not mutually contained. Answers a list of
* start-end indices of the sorted list of ranges.
* sort by start ascending, length descending, so that
* contained intervals follow their containing interval
*/
- Collections.sort(ranges, comparator);
+ Collections.sort(ranges, IntervalI.COMPARE_BEGIN_ASC_END_DESC);
int listStartIndex = 0;