sortByIndex function
Used to sorts WordMarkers by their index, ascending.
If indexes are identical and marker types are different,
the start marker comes first and the end marker comes second,
making the resp. blocks intersect/overlap at that position.
Implementation
int sortByIndex(final WordMarker a, final WordMarker b) {
final int compareResult = a.index.compareTo(b.index);
if (compareResult == 0) {
if (a.type == b.type) {
return compareResult; // order does not matter
} else if (a.type == MarkerType.start) {
return -1; // start marker comes first
} else {
return 1; // end marker comes second
}
} else {
return compareResult;
}
}