SectionComparator implements Comparator<Section> { @Override public int compare(final Section object, final Section compareWithObject) { if (object != null && compareWithObject == null) { return 1; } if (object == null && compareWithObject != null) { return -1; } if (object == compareWithObject) { return 0; } final int objStart = object.getStart(); final int objEnd = object.getEnd(); final int otherStart = compareWithObject.getStart(); final int otherEnd = compareWithObject.getEnd(); final int objectSum = objStart + objEnd; final int otherSum = otherStart + otherEnd; if (objStart < otherStart) { return 1; } if (objStart == otherStart) { if (otherSum < objectSum) { return 1; } if (otherSum > objectSum) { return -1; } return 0; } return -1; }  @Override int compare(final Section object, final Section compareWithObject);  }
@Override @Test public void testCompare() { super.testCompare(); }