question: private List < ColouredText > removeOverlaps ( List < ColouredText > segments ) { List < ColouredText > segments2 = new ArrayList < ColouredText > ( segments ) ; Iterator < ColouredText > iterator = segments . iterator ( ) ; ColouredText current = ( iterator . hasNext ( ) ) ? iterator . next ( ) : null ; while ( iterator . hasNext ( ) ) { ColouredText next = iterator . next ( ) ; if ( current . start == next . start ) { ColouredText toRemove = ( current . end < next . end ) ? current : next ; segments2 . remove ( toRemove ) ; } else if ( next . start < current . end ) { current . end = next . start ; if ( next . end < current . end ) { segments2 . add ( new ColouredText ( next . end , current . end , current . colour ) ) ; } } current = next ; } Collections . sort ( segments2 ) ; return segments2 ; }
target:  Removes all overlaps from the coloured segments, and returns the result.